How can I get the renderer for a MapImageLayer sublayer?

495
2
Jump to solution
01-24-2023 12:56 PM
MattStayner
Occasional Contributor II

I am building a custom legend and I need to get the renderers for MapImageLayer sublayers. I see renderer under layer.allSublayers._items[1].renderer, but for some reason it is null. See the console for this codepen to see what I mean.

So how can I get the renderer for each sublayer show I can show the correct symbol in my legend?

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JoelBennett
MVP Regular Contributor

The documentation for the Sublayer.renderer property seems to suggest that the property only exists for the purpose of overriding symbology, and thus doesn't contain the default symbology.  This makes sense since the service information used to load your MapImageLayer doesn't contain sublayer renderer information.  For that, you have to look at the information from the individual layers (e.g. layer 0).

Therefore, I suppose you have two options for your legend.  You can retrieve the information for each sublayer manually, or you could retrieve the layer's legend information and use that instead.  It doesn't contain the renderer information, but does contain the swatches you could put in your legend.

View solution in original post

2 Replies
JoelBennett
MVP Regular Contributor

The documentation for the Sublayer.renderer property seems to suggest that the property only exists for the purpose of overriding symbology, and thus doesn't contain the default symbology.  This makes sense since the service information used to load your MapImageLayer doesn't contain sublayer renderer information.  For that, you have to look at the information from the individual layers (e.g. layer 0).

Therefore, I suppose you have two options for your legend.  You can retrieve the information for each sublayer manually, or you could retrieve the layer's legend information and use that instead.  It doesn't contain the renderer information, but does contain the swatches you could put in your legend.

MattStayner
Occasional Contributor II

@JoelBennett Ah, that makes sense now. The Sublayer.renderer doesn't contain the renderer information for the layer, but rather, the overriding renderer.

I'm going to use /legend endpoint. For me, that is even better than having the renderer. I just need the image to show in my legend. That will be perfect. Thanks a million!

 

Matt

0 Kudos