Select to view content in your preferred language

Using Maps SDK or JIMU - how to access layer visualization settings and render a legend swatch?

525
5
Jump to solution
06-14-2024 11:08 AM
NFlourish
Frequent Contributor

We have "rolled our own" legend in Experience Builder because the out-of-box legend lacks functionality we needed it. It works fine for most things. Of course it has a key defecit ... it depends on the renderer settings of the ReST endpoint of the feature layer to determine what symbology to should be for the layers, and to draw a little symbol. This is SUPER tedious to deal with because there are so many types of layers and symbologies, that you need a giant chunk of switch or if-then logic to figure out what each layer type is and how to draw a symbol.

We keep thinking, there must be some standard Esri way of doing this? It is bonkers that Esri is expecting us to recreate all the logic for legend rendering, right?

But we just can't find any examples that really cover all the potential cases for layer types and generate a cute little symbol swatch like we see in the AGO map viewers. I thought I found the source code for it in Esri's GitHub once ... specifically the source for the Experience Builder Dev Edition Legend Widget... but when I went back later to use it, I couldn't find it again.

Additionally, not only can we not find a complete example of the logic to handle the layer types for legend rendering, but we also do not see how to access the symbolization settings that are stored in the "visualization" tab for an AGO item. In other words, a feature layer might have some renderer defined for it, but it appears that the settings in the visualization tab for an AGO item can override the ReST endpoint. An example is a layer I created that has a Drawing Info value of:

    {"labelingInfo":null,"renderer":{"label":"Survey Point","symbol":{"angle":0,"color":[255,0,0,255],"outline":{"color":[255,255,0,255],"width":1},"size":8,"style":"esriSMSCircle","type":"esriSMS","xoffset":0,"yoffset":0},"type":"simple"},"transparency":0}

However, five minutes ago I changed the fill color to purple, not red (so it should be something like [255,0,128,255] instead of [255,0,0,255]). So the ReST endpoint either gets overridden by the visualization setting, or takes a while to update from it. However, we would really like to just be able to directly access the updated visualization setting. Which I cannot seem to figure out how to find in the ArcGIS Online API ... I can't even find it in the ArcGIS Online Assistant.

So what is the standard method by which someone would render their own legend symbolx? Do we really need to re-invent a wheel that Esri has conquered a million times over?

0 Kudos
1 Solution

Accepted Solutions
JeffreyThompson2
MVP Regular Contributor

If you would like to customize the OOTB Experience Builder Legend Widget, it can be found in the /client/dist/widgets/arcgis/legend folder. Instructions for converting a OOTB widget to a custom widget can be found here.

Looking at the code it appears to mostly just call in the Legend Widget from the API. You could also build a custom widget just designed to pull in the API version of the widget.

I'm not really sure why you would need to modify the Legend Widget though. The legend should respect the symbology at the REST endpoint, unless there is something different in the renderer. And the legend should update if the renderer changes. This is the standard behavior of the Legend Widget.

GIS Developer
City of Arlington, Texas

View solution in original post

5 Replies
JeffreyThompson2
MVP Regular Contributor

If you would like to customize the OOTB Experience Builder Legend Widget, it can be found in the /client/dist/widgets/arcgis/legend folder. Instructions for converting a OOTB widget to a custom widget can be found here.

Looking at the code it appears to mostly just call in the Legend Widget from the API. You could also build a custom widget just designed to pull in the API version of the widget.

I'm not really sure why you would need to modify the Legend Widget though. The legend should respect the symbology at the REST endpoint, unless there is something different in the renderer. And the legend should update if the renderer changes. This is the standard behavior of the Legend Widget.

GIS Developer
City of Arlington, Texas
NFlourish
Frequent Contributor

This looks promising. I'll explore. Thank you.

The issue with where we pull the renderer info from is that there seems to be a disconnect between the ReST endpoint and the ArcGIS Online "Visualization" tab settings.

Consider this in the Visualization tab:

Screenshot 2024-06-14 at 3.44.59 PM.png

And this is what the ReST endpoint says for the drawing info (renderer):

Screenshot 2024-06-14 at 3.45.20 PM.png

They are not the same and I know (since i changed it a few hours ago) the "Visualization" tab is the most recently changed.

So, needing to pull symbology settings from the Visualization tab is because we need to avoid this disconnect.

But I can't find any documentation in the ArcGIS Rest API stuff that talks about how to query the Visualization settings, nor any examples.

0 Kudos
NFlourish
Frequent Contributor

Not sure if it is helpful, but our custom Legend is used in this Experience.

https://www.stone-env.net/opdgig-view-data/

As described, we're having an issue where the symbology swatches are showing old symbols after the client has updated the layer's symbology in the AGO Visualization tab... because we are fetching the drawing info (renderer info) from the ReST endpoint.

0 Kudos
JeffreyThompson2
MVP Regular Contributor

That's a lot more than just a legend.

My guess is that your problem is that you are not the data owner, so you do not have permission to alter the data from the Visualization tab.

If you own the item, you can save changes you make to the layer. Changes to the layer properties are saved to the existing layer item.

Both the item owner and those who have privileges to create content can also save a copy of the layer as a new item. The new item references the original source layer but appears on the My content page of the member who creates the copy. You can save copies of layers as items in Map Viewer or on the Visualization tab of the layer item's details page.

https://doc.arcgis.com/en/arcgis-online/get-started/item-details.htm#ESRI_SECTION2_93D932F9D6744934B...

GIS Developer
City of Arlington, Texas
0 Kudos
NFlourish
Frequent Contributor

We have taken route of making our own "items" of some data sources we do not own so that we could improve the symbology or, more importantly, metadata. But we've found that even for datasets we completely own, the difference between the visualization settings and ReST endpoint drawing info remains an issue.

0 Kudos