Hi folks:
A very basic question: How to display map legend in the webmap widget?
I am really stuck despite I've been trying and using ArcGIS Python API for a little while.
Is it even possible?
Thanks.
Solved! Go to Solution.
Hi Simo Xu , thanks for the comments and suggestions. You are right that the audience could get confused by what the colors and symbols represent on the map widget without having a pictographic legend visible. While this functionality doesn't exist in our current 1.5 release, we will research the technical plausibility of adding in a legend for the widget, and will attempt to keep you updated. Thanks again for chiming in
If the charts from python matplotlib can have legend, I am sure maps should have legend too.
After all what's the benefit of using sophisticated ArcGIS map rendering technology when the audience can not understand what the symbols and colors represent?
I hope one of the group admins can shed some light on this
Hi Simo Xu , thanks for the comments and suggestions. You are right that the audience could get confused by what the colors and symbols represent on the map widget without having a pictographic legend visible. While this functionality doesn't exist in our current 1.5 release, we will research the technical plausibility of adding in a legend for the widget, and will attempt to keep you updated. Thanks again for chiming in
Hi David,
Thanks for the clarification.
Legend is so essential when mapping data in data science field. It's not like street map which people can understand without a key / legend, because of its ubiquity.
Since this function does not exist, I created a ArcGIS Idea, and hope this could become a priority in the future development.
Update:
This is fixed in the version 1.5.1 release, see the #1 in the New list:
What's new in version 1.5.1 | ArcGIS for Developers
But there is a catch: the legend is only available for the map widget (arcgis.widgets._mapview.MapView) , but not for the webmap (arcgis.mapping._types.WebMap), and only by coding which is a one-liner, not that too bad although a button on the UI will be easier for end users. Hope all these issues will be addressed in coming versions.
A nice step towards the right direction. Thank you ESRI for listening and acting on our request. David Vitale
Hi simo xu, glad to have helped out!! As to your points, yes the legend is only available for the MapView widget class. However, if you instantiate a MapView class directly, there is an item argument which allows you to pass in an Item instance of a WebMap or WebScene for visualization (See here).
Here's some sample code that might better explain this: Run these 2 blocks as 2 seperate code cells in a notebook:
from arcgis.gis import GIS
gis = GIS()
wm_item = gis.content.get('8a567ebac15748d39a747649a2e86cf4')
wm_item
from arcgis.mapping import WebMap
webmap = WebMap(wm_item)
webmap
You will notice no option to specify a legend. However, if you then run this code cell, you will see the same WebMap visualized with the legend property callable (notice the arguments passed in on MapView instantiation)
from arcgis.widgets import MapView
mapview = MapView(gis=gis, item=wm_item)
mapview.legend = True
mapview
As for making the legend visible via a UI button, we decided to do this programmatically to keep the user interface simple (There isn't much space in a jupyter notebook widget to add buttons without things looking cluttered). We'll reconsider adding a UI button for future releases.
Hopefully this fits your use case, let us know of any future concerns about the legend or anything else.
Thanks David, that works like a charm