VinayBa

map.graphics.clear() and Feature Layer snapshot mode

Discussion created by VinayBa on Feb 10, 2014
Latest reply on Feb 12, 2014 by tligon
HI All,


  I am facing issue where my graphic object is getting removed from map .I am using world map and adding feature layer in snap shot mode.
I dont want to hit server again and again so hence i am keeping all featuer layer gaphics in dojo dictionary using below code

 dojo.forEach(featureLayer.graphics, function(graphic){
                hashMap.add(graphic.attributes.CNTRY_NAME, graphic);
            });


now when i want to highlight a country i do below .

if (hashMap.containsKey(country)) {
                                  var graphic = hashMap.item(country);
                                  graphic.setSymbol(alertOfficeSymbol);
                                  map.graphics.add(graphic);
                              }


I also have onClick functionality in my app.

SO lets say onload of page i have to highlight somecountries lets India,USA,UK etc.

now in some scenarios i have to clear these countries i.e i have to deHighlight them so i use below code

if (map.graphics != null) {
        map.graphics.clear();
    }


I have defined my onClick function as below

handle=dojo.connect(map, "onClick", function(e){
              selectCountries(e);
          });

function selectCountries(e){
  var graphic = evt.graphic;
        var countryName = graphic.attributes.CNTRY_NAME;
}


Now when user clicks on India,USA,UK i get below error
evt.graphic is undefined

so my graphic object is lost when i use map.graphics.clear();

how to overcome this.

Outcomes