1

I have a feature layer being drawn from a map service. I have a graphics layer that is the result of a query (happens to be on the same feature layer). I wish to apply the same symbols from the Feature Layer to the new graphics layer produced by the query but have had no such luck. Relevant code bellow:

var featureLayer = new FeatureLayer(http://........);

function handleQuery(queryRslt) { 
    var queryGraphicsArray = queryRslt.features;
    var featureLayerSymbol = featureLayer.renderer.getSymbol(); 
    for (var i = 0 ; i < queryGraphicsArray.length ; i ++) { 
        queryGraphicsArray[i].symbol = featureLayerSymbol;
        map.graphics.add(queryGraphicsArray[i]);
}

I can confirm that the query is in fact functioning properly. I can also confirm that the symbol appears to being changed using console.log and debugging tool. However nothing is added to the map.

The symbol is a picture symbol added inside of arcMap before publishing to AGS. It is a ping image.

Any thoughts as to where i am going wrong?

1 Answer 1

3

You may not need to create a new graphic layer because you can also filter the existing feature layer with the following code:

featureLayer.setDefinitionExpression(<<your expression>>);
2
  • I had a feeling there would be a much simpler method. Sometimes I get lost navigating the api documentation. Question: The way I would like this to work is that the user clicks button one, it shows relevant data of the Feature Layer, button two would essentially do the same but with a different query. Would you refresh() the layer on the event. Or is there another method to ensure the new definition query gets applied to the map?
    – LCaraway
    Commented Jan 6, 2016 at 15:47
  • No need to do anything, setDefinition() expression automatically is reflected on the map.
    – LCaraway
    Commented Jan 6, 2016 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.