Hello all!
I have a very simple question. Using the javascript API I have the simplest feature layer one could have:
Now, without manually declaring a renderer for this feature layer, the hosted layer naturally provides this, and I can see the default renderer attributes via the service URL found via my portal on ArcGIS Online. The details are found under the Drawing Info: section and look a bit as follows:
I would very much like to be able to access these color attributes from inside of my code. Any ideas on how to do this?
I have tried accessing them in a similar manner as below and printing them to the console to debug, but it always returns undefined.
It keeps saying that the feature layer has no property renderer. Any ideas on how to fix this?
Or, if anybody knows of any other way to access a featureLayer's default color scheme, I would greatly appreciate any guidance!
Thank you!!!
Solved! Go to Solution.
Ryan,
You just have to wait for the featurelayer to fully load then the renderer will be populated. In 3.x of the API you listen for the load event. In 4.x you watch the loaded property.
Ryan,
You just have to wait for the featurelayer to fully load then the renderer will be populated. In 3.x of the API you listen for the load event. In 4.x you watch the loaded property.
Here is a simple example of what Robert recommended in 4x:
https://codepen.io/noash/pen/oNXNQeK
And here is a helpful blog about visualizations and colors: https://www.esri.com/arcgis-blog/products/js-api-arcgis/mapping/better-colors-for-better-mapping/
Hey Noah!
Thank you for the codepen post. I initially got my implementation to work with Robert's post, but coming back and seeing your follow up, I was able to considerably clean up my solution. Thank you!
Thank you so much Robert! I got this working thanks to your help. I am not used to actually receiving help when posting on forums. The arcGis community is great!