Select to view content in your preferred language

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

11-03-2022 02:59 PM
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:


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) => {
      }).catch((error) => {

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?


0 Kudos
1 Reply
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