View Properties of Hosted FeatureLayer

710
4
Jump to solution
01-31-2020 02:10 PM
RyanCain
New Contributor II

Hello all!

I have a very simple question. Using the javascript API I have the simplest feature layer one could have:

var villages_to_domains = new FeatureLayer({
url:
outfields: ["*"],
});

 

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:

    {"renderer":{"visualVariables":[{"type":"sizeInfo","target":"outline","expression":"view.scale","valueExpression":"$view.scale","stops":[{"size":1.5,"value":31882},{"size":0.75,"value":99632},{"size":0.375,"value":398528},{"size":0,"value":797056}]}],"type":"uniqueValue","field1":"datafuku_3","defaultSymbol":{"color":[170,170,170,255],"outline":{"color":[153,153,153,64],"width":0.75,"type":"esriSLS","style":"esriSLSSolid"},"type":"esriSFS","style":"esriSFSSolid"},"defaultLabel":"Other","uniqueValueInfos":[{"value":"Fukui","label":"Fukui","symbol":{"color":[237,81,81,255],"outline":{"color":[153,153,153,64],"width":0.75,"type":"esriSLS","style":"esriSLSSolid"},"type":"esriSFS","style":"esriSFSSolid"}},{"value":"Bakuryou","label":"Bakuryou","symbol":{"color":[20,158,206,255] 
    ...
    ...

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.

console.log(villages_to_domains.renderer.uniqueValueInfos[0].color);

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!!!

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

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.

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus

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.

Noah-Sager
Esri Regular Contributor

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/

RyanCain
New Contributor II

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!

RyanCain
New Contributor II

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!