Select to view content in your preferred language

How to get style, symbol or color from a feature?

351
1
11-03-2022 02:59 PM
AndrewMurdoch1
Occasional Contributor II

Good Day

I have a layer that which uses a valueExpression in the Unique Value Renderer to set it's style, giving me something like:

AndrewMurdoch1_0-1667512621210.png


I'm running into a problem where I need to know what colours / uniqueValueInfo from the Unique Value Renderer was set on to the map.  How can I get this information?  I tried running a query:

queryAllFeatures(layer: FeatureLayer): Promise<Graphic[] | Error> {
    return new Promise((r, j) => {
      const query = {
        where: '1=1',
        outFields: ['*'],
        returnGeometry: true
      }

      layer.queryFeatures(query).then((queryRes) => {
        r(queryRes.features);
      }).catch((error) => {
        console.log(error);
        j(null);
      })
    });
  }

But I can't seem to find the information in the output?  I  would imagine it's trivial to get the style information form the layer.  Ideally I'd like to get a list of all styles / colours that are active.

Is this possible?

Thanks

0 Kudos
1 Reply
JoelBennett
MVP Regular Contributor

If I'm understanding your question properly, it seems to me that UniqueValueRenderer.getUniqueValueInfo is the key to what you're trying to do.  For example:

layer.renderer.getUniqueValueInfo(someGraphic).then(function(uniqueValueInfo) {
	var symbol = uniqueValueInfo.symbol;
	//do whatever with the symbology for "someGraphic" here
});

 

0 Kudos