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?
Solved! Go to Solution.
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.
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.
@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