Legend Architecture - fgpv-vpgf/geoApi GitHub Wiki

The application supports two legend modes. The first mode involves a custom legend that is supplied in full detail via a config object. geoApi is not required in this case. The second mode is when no custom legend is supplied, so any legend information on the layer needs to be scraped from the service and transformed into a compatible format. This functionality will be provided in the legend section.

Things this section should do:

  • A function to get the legend information from an ESRI Map Service
  • A function to determine which layer ids are captured by a service, and extract those sections from the legend information.
    • For Feature Layer endpoints, this is simply the index of the layer.
    • For Dynamic Map Service Layer endpoints, this involves figuring out which Feature Layer endpoints are within the Dynamic Map Service Layer. This information may be available in the LayerInfo property of the Dynamic Map Service Layer object; otherwise we would have to poll the service.
  • If required, a function to translate the legend info from the Map Service to the structure used by the viewer.

A note about legends in ArcGIS Rest Services.

An ESRI Map Service exposes a legend at the service level. This will contain any custom legend text and also provides legend symbols in base64 image data format, even if the source symbol is an ESRI symbol. The Feature Layer endpoint of a Map Service does not expose Legend information about itself, it only contains renderer information (which can be used to construct a legend, but it may not be the same as the legend defined by the publisher of the map service).

An ESRI Feature Service does not expose a legend at the service level. It does, however, expose the same renderer information at the Feature Layer level as you would see in a Map Service. This can be problematic, as users often see a Feature Layer endpoint as being the same for both Feature Services and Map Services, and then get furious when there is no legend.

When time permits, we may want to look into a way to generate a basic legend from the layer renderer to allow better support for endpoints coming from Feature Services. It may be possible to utilize ESRI Symbology JSON Utils to convert ESRI symbols to images/formats usable in the webpage.

Optional Functionality: Code to support WMS Layer Legends?