function onRowClickHandler(evt){ var clickedRep = grid.getItem(evt.rowIndex).rep_no; var selectedRep; var selectedRepSymbol = new esri.symbol.SimpleMarkerSymbol(); selectedRepSymbol.style = esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE; selectedRepSymbol.setSize(10); selectedRepSymbol.setColor(new dojo.Color([0,255,0, 1])); dojo.forEach(map.graphics.graphics,function(graphic){ if((graphic.attributes) && graphic.attributes.rep_no === clickedRep){ selectedRep = graphic; var selectedRepGraphic = new esri.Graphic(selectedRep, selectedRepSymbol); selectedRepGraphic.setSymbol(selectedRepSymbol); var selInfoTemplate = new esri.InfoTemplate("Sales Rep: ${NAME}", ("${*}")); //"Rep # : ${rep_no}", "Address : ${ADDR1}"); map.infoWindow.setTitle(selectedRepGraphic.getContent("${NAME}")); map.infoWindow.setContent(selectedRepGraphic.getContent("Sales Rep: ${NAME}", "Rep #: ${rep_no}", "Address : ${ADDR1}")); selectedRepGraphic.setInfoTemplate(selInfoTemplate); map.infoWindow.show(selectedRepGraphic.geometry); if (selectedRepGraphic != undefined){ map.graphics.remove(map.graphics.graphics[map.graphics.graphics.length - 1]); }; map.graphics.add(selectedRepGraphic); return; }; }); return; };
Thats why I love these forums, lots of people working together to help each other. It is a pleasure to be part of this community.
function onClicker(evt){ identifyTaskReps = new esri.tasks.IdentifyTask("http://server/ArcGIS/rest/services/IndivTerritoriesOnly/SalesReps_simple/MapServer/"); identifyParamsReps = new esri.tasks.IdentifyParameters(); identifyParamsReps.tolerance = 5; identifyParamsReps.returnGeometry = true; identifyParamsReps.layerIds = [0]; identifyParamsReps.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE; identifyParamsReps.width = map.width; identifyParamsReps.height = map.height; identifyParamsReps.geometry = evt.mapPoint; identifyParamsReps.mapExtent = map.extent; var deferred = identifyTaskReps.execute(identifyParamsReps); deferred.addCallback(function(response){ if (response.length > 0) { return dojo.map(response, function(result){ var feature = result.feature; var featureSymbol = new esri.symbol.SimpleMarkerSymbol(); featureSymbol.style = esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE; featureSymbol.setSize(10); featureSymbol.setColor(new dojo.Color([0,255,0, 1])); feature.setSymbol(featureSymbol); feature.attributes.layerName = result.layerName; var infoTemplate = new esri.InfoTemplate(); feature.setInfoTemplate(infoTemplate); var name = feature.attributes.NAME; var rep_no = feature.attributes.rep_no; var address = feature.attributes.ADDR1; var city = feature.attributes.CITY; var state = feature.attributes.ST_ABBR; var zipcode = feature.attributes.ZIP_CODE; var leader = feature.attributes.Ldr_type; var prez = feature.attributes.PCText; var content = "<b>Rep # : </b>" + rep_no + "<br><b>Address : </b>" + address + "<br><b>City : </b>" + city + "<br><b>State : </b>" + state + "<br><b>Zip : </b>" + zipcode + "<br><b> Leader : </b>" + leader + "<br><b>Presidents Club :</b>" + prez; var title = "<b>Name : </b>" + name; map.infoWindow.setTitle(title); map.infoWindow.setContent(content); feature.setInfoTemplate(infoTemplate); map.graphics.add(feature); map.infoWindow.show(feature.geometry); this.highlightGraphic = new esri.Graphic(feature, featureSymbol); this.highlightGraphic.id = "highlight"; dojo.forEach(this.map.graphics.graphics, function(g) { if (g && g.id === "highlight") { //remove graphic with specific id this.map.graphics.remove(g); } }, this); this.map.graphics.add(this.highlightGraphic); return; }); }; }); };
help help? 🙂 please?
looking at your code (the last 3 blocks) you create the graphic, remove the graphic, then add the graphic. I dont think that is the logic you want
is you onclick supposed to add a graphic or remove one?
all the points should have a graphic.
if you click on a point, a new "highlight point" should appear. if you click on a second point, a new highlight point needs to appear, and the the first one needs to disappear.
thanks.
That makes more sense.
First, remove the old graphic before you create the new one. (the forEach loop)
Second, remove all the "this"'s. Looking at your code, you dont need them.
function onClicker(evt){ dojo.forEach(map.graphics.graphics, function(g) { console.log(g.id) if ( g && g.id === "highlight" ) { //remove graphic with specific id map.graphics.remove(g); // <-- this doesn't remove anything. } }); identifyTaskReps = new esri.tasks.IdentifyTask("http://172.26.197.91/ArcGIS/rest/services/IndivTerritoriesOnly/SalesReps_simple/MapServer/"); identifyParamsReps = new esri.tasks.IdentifyParameters(); identifyParamsReps.tolerance = 7; identifyParamsReps.returnGeometry = true; identifyParamsReps.layerIds = [0]; identifyParamsReps.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE; identifyParamsReps.width = map.width; identifyParamsReps.height = map.height; identifyParamsReps.geometry = evt.mapPoint; identifyParamsReps.mapExtent = map.extent; var deferred = identifyTaskReps.execute(identifyParamsReps); deferred.addCallback(function(response){ if (response.length > 0) { // console.log("response length ", response.length) // response is an array of identify result objects // Let's return an array of features. return dojo.map(response, function(result){ var selFeature = result.feature; var selFeatureSymbol = new esri.symbol.SimpleMarkerSymbol(); selFeatureSymbol.style = esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE; selFeatureSymbol.setSize(10); selFeatureSymbol.setColor(new dojo.Color([0,255,0, 1])); selFeature.setSymbol(selFeatureSymbol); selFeature.attributes.layerName = result.layerName; var infoTemplate = new esri.InfoTemplate(); selFeature.setInfoTemplate(infoTemplate); var name = selFeature.attributes.NAME; var rep_no = selFeature.attributes.rep_no; var address = selFeature.attributes.ADDR1; var city = selFeature.attributes.CITY; var state = selFeature.attributes.ST_ABBR; var zipcode = selFeature.attributes.ZIP_CODE; var leader = selFeature.attributes.Ldr_type; var prez = selFeature.attributes.PCText; var content = "<b>Rep # : </b>" + rep_no + "<br><b>Address : </b>" + address + "<br><b>City : </b>" + city + "<br><b>State : </b>" + state + "<br><b>Zip : </b>" + zipcode + "<br><b> Leader : </b>" + leader + "<br><b>Presidents Club :</b>" + prez; var title = "<b>Name : </b>" + name; map.infoWindow.setTitle(title); map.infoWindow.setContent(content); map.graphics.add(selFeature); map.infoWindow.show(selFeature.geometry); highlightGraphic = new esri.Graphic(selFeature, selFeatureSymbol); highlightGraphic.id = "highlight"; highlightGraphic.setSymbol; map.graphics.add(highlightGraphic); }); }; }); };
dojo.forEach(map.graphics.graphics, function(g) { console.log(g.id) if ( g && g.id === "highlight" ) { //remove graphic with specific id map.graphics.remove(g); // <-- this doesn't remove anything. } });
dojo.forEach(map.graphics.graphics, function(g) { console.log(g.id) if ( g && g.id === "highlight" ) { //remove graphic with specific id map.graphics.remove(g); // <-- this doesn't remove anything. } }, this);
dojo.forEach(map.graphics.graphics, dojo.hitch(this, function(g) { console.log(g.id) if ( g && g.id === "highlight" ) { //remove graphic with specific id map.graphics.remove(g); // <-- this doesn't remove anything. } }));
function onClicker(evt){ dojo.forEach(map.graphics.graphics, function(g) { if ( g && g.id === "highlight" ) { //remove graphic with specific id map.graphics.remove(g); console.log(map.spatialReference) } }, this); identifyTaskReps = new esri.tasks.IdentifyTask("http://172.26.197.91/ArcGIS/rest/services/IndivTerritoriesOnly/SalesReps_simple/MapServer/"); identifyParamsReps = new esri.tasks.IdentifyParameters(); identifyParamsReps.tolerance = 5; identifyParamsReps.returnGeometry = true; identifyParamsReps.layerIds = [0]; identifyParamsReps.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE; identifyParamsReps.width = map.width; identifyParamsReps.height = map.height; identifyParamsReps.geometry = evt.mapPoint; identifyParamsReps.mapExtent = map.extent; var deferred = identifyTaskReps.execute(identifyParamsReps); deferred.addCallback(function(response){ if (response.length > 0) { // console.log("response length ", response.length) // response is an array of identify result objects // Let's return an array of features. return dojo.map(response, function(result){ var selFeature = result.feature; var selFeatureSymbol = new esri.symbol.SimpleMarkerSymbol(); selFeatureSymbol.style = esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE; selFeatureSymbol.setSize(10); selFeatureSymbol.setColor(new dojo.Color([0,255,0, 1])); selFeature.setSymbol(selFeatureSymbol); selFeature.attributes.layerName = result.layerName; var infoTemplate = new esri.InfoTemplate(); selFeature.setInfoTemplate(infoTemplate); var name = selFeature.attributes.NAME; var rep_no = selFeature.attributes.rep_no; var address = selFeature.attributes.ADDR1; var city = selFeature.attributes.CITY; var state = selFeature.attributes.ST_ABBR; var zipcode = selFeature.attributes.ZIP_CODE; var leader = selFeature.attributes.Ldr_type; var prez = selFeature.attributes.PCText; var content = "<b>Rep # : </b>" + rep_no + "<br><b>Address : </b>" + address + "<br><b>City : </b>" + city + "<br><b>State : </b>" + state + "<br><b>Zip : </b>" + zipcode + "<br><b> Leader : </b>" + leader + "<br><b>Presidents Club :</b>" + prez; var title = "<b>Name : </b>" + name; map.infoWindow.setTitle(title); map.infoWindow.setContent(content); map.graphics.add(selFeature); map.infoWindow.show(selFeature.geometry); highlightGraphic = new esri.Graphic(selFeature, selFeatureSymbol); highlightGraphic.id = "highlight"; highlightGraphic.setSymbol(selFeatureSymbol); map.graphics.add(highlightGraphic); }); }; }); };