I am creating a custom TOC which needs to have both layer toggle and legend item (image data) for the web map. But the web map service does not have Legend Info. Does anybody know how to get legend info from the web map services. Any help would be very appreciated.
Ok gotcha, so there are urls that are used and populated that might not be visible by clicking around the webmap viewer. I tried digging through there to find what endpoints are available but couldn't find any that surfaced a "map server"
Yes, there are some key URL that everyone just kinda knows.
Try looking in YourServer\arcgis\rest\services <- that should be the base url to your services.
are also useful.
@jordan - Yes, you are correct, a webmap is a wrapper or collection of layers as JSON, however, a Portal/AGO webmap can also contain other types of layers not supported by (or originating) from ArcGIS Server (e.g. a WMTS layer). A hosted feature layer does not have a corresponding map service, so navigating the REST Services Directory won't show the map service for a hosted feature layer. See @Andrew's comment below.
I'm coming to this late (and in the context of getting a legend from Esri services for a Leaflet map), but I think the discrepancy noted between the questioners and the responders is that the "legend" service URL pattern is only available for services coming from ArcGIS Server (Enterprise) instances, but NOT from ArcGIS Online services. It looks like several questioners were referring specifically to AGOL resources...
Also, not every "FeatureServer" hosted in AGOL (at arcgis.com) will have a corresponding "MapServer" REST endpoint, unlike what you see with a standard ArcGIS Server/Enterprise setup.
I'm really hoping that someone else can confirm if this assessment is correct, and that the "legend" service URL pattern is only available for standard ArcGIS Server REST endpoints (for both Feature or Map service layers) and NOT for ArcGIS Online services (of any service type).
If so, and if I still need to support legends for AGOL feature and map resources (not just for ArcGIS Server/Enterprise resources), how do I generate the legend image for use in a web map interface (perhaps using Leaflet, or some other framework)? We're not planning on using any Dojo/JSAPI components...
I the AGOL REST service endpoints, there is a Drawing Info Renderer JSON object with all the necessary ingredients (symbol type, colors, sizes, etc), but it would be nice not to have to roll my own legend generator for AGOL services...
I _did_ eventually circle back to this and (with the hints from Rhys) got a working AGOL Feature Service legend image generator for use in a Leaflet map (which also leverages AngularJS). I can now generate legend images for using the drawingInfo.renderer object from the REST endpoint JSON response.
To do this, I had to first use the angular-esri-core library from here: https://github.com/Esri/angular-esri-map
I actually only needed the smaller angular-esri-core.js component to add just the bits of Dojo/JSAPI that I needed (specifically, the esriLoader object) to generate legend images using the JSAPI 4.x symbolPreview object's renderPreviewHTML method. Our version of AngularJS was just under the "supported" line, but the "core" loader library seems to work fine with our older version.
Using the esriLoader object, I loaded these pieces of Dojo/JSAPI:
Once I had an SVG legend image for the drawingInfo.renderer, I also needed to do some minor surgery on the SVG/XML string, to add an "xmlns" tag to make it valid SVG for rendering as a source URL for an img tag.