Search code examples
dojoesriarcgis-js-api

How to revert the symbol of graphic in ESRI arcgis


i have a feature layer and added click event to select the graphic. on selection i have changed the symbol to show the graphic is selected.

as below code

var symbol;
switch (graphic.geometry.type) {
    case "point":
        //symbol for point geometry
        symbol = new SimpleMarkerSymbol(
        SimpleMarkerSymbol.STYLE_CIRCLE, 12,
        new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
        new Color([ 247, 0, 171, 0.9 ]), 2),
        new Color([ 0, 255, 255, 255.25 ]), 0.5);
        break;

    case "polyline":
    case "polygon":
        //symbol for Polygon geometry
        symbol = new SimpleFillSymbol(
        SimpleFillSymbol.STYLE_NULL, new SimpleLineSymbol(
        SimpleLineSymbol.STYLE_SOLID,
        new Color([ 0, 255, 0 ]), 3),
        new Color([ 0, 125, 0,0.35 ]));
        break;
    }
    graphic.setSymbol(symbol);

When the de-selection means again user select the graphic by clicking 2nd time i need to set the previous symbol.

do i need to maintain each feature and its symbol? or is their any best way to do this?


Solution

  • @chiranjeevibmse instead of you changing the symbol and maintain the previous symbol you can use the Featurelayer.selectFeatures method by sending objectid in the query.

    on first click, make query with objectid which you have to select

    var query = new Query();
    query.objectIds = [graphic.attributes.FID];
    layer.selectFeatures(query,FeatureLayer.SELECTION_ADD);
    

    dont forget to set the select symbol ;)

    on second time click on the graphic you can call

    var query = new Query();
    query.objectIds = [graphic.attributes.FID];
    layer.selectFeatures(query,FeatureLayer.SELECTION_SUBTRACT);
    

    which will take care of symbol.