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;
};
Thank you for the help thus far.
Im going to be bald by the end of the day if I keep up all this hairpulling...
map.graphics.clear(); works, (and worked previously) but map.graphics.remove(g); does nothing.
as a test, within the IF i tried console.log(map.spatialReference), and it reported back to the console just fine.
what version of the API are you on? do you get any error in firebug?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); }); }; }); };
console.log(g)
dojo.forEach(map.graphics.graphics, function(g){
console.log(g)
if (g && g.id === "highlight") {
//remove graphic with specific id
console.log(g);
map.graphics.remove(g);
console.log(map.spatialReference)
}
}, this);
clue?
highlightGraphic = new esri.Graphic(selFeature, selFeatureSymbol); highlightGraphic.id = "highlight"; highlightGraphic.setSymbol(selFeatureSymbol); map.graphics.add(highlightGraphic);
function onClicker(evt){
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.attributes.id = "highlight";
highlightGraphic.setSymbol(selFeatureSymbol);
dojo.forEach(map.graphics.graphics, function(g){
if ( g.attributes && g.attributes.id === "highlight" ) {
//remove graphic with specific id
map.graphics.remove(g);
}
});
map.graphics.add(highlightGraphic);
});
};
});
};
doesnthighlightGraphic = new esri.Graphic(selFeature, selFeatureSymbol); highlightGraphic.id = "highlight"; highlightGraphic.setSymbol(selFeatureSymbol); map.graphics.add(highlightGraphic);
create a separate graphics layer?
<snip> ... I get a type error.
What does firebug report as the error?
TypeError: g is undefined
(undefined="(void 0)", undefined="7", undefined="[object Array]")findarep.html (line 417)
(undefined="[object Array]", undefined="(function (g) {if (g.at....graphics.remove(g);}})")?v=2.8 (line 14)
(undefined="[object Object]", undefined="0", undefined="[object Array]")findarep.html (line 416)
.setSymbol(undefined="selFeatureSymbol);dojo....h(map.graphics.graphics", undefined=" function (g) {if (g.at...dd(highlightGraphic);})")?v=2.8 (line 14)
(undefined="[object Array]")findarep.html (line 384)
_144()?v=2.8 (line 14)
_142(undefined="[object Array]")?v=2.8 (line 14)
(undefined="[object Array]")?v=2.8 (line 14)
(undefined="[object Object]", undefined="[object Array]")?v=2.8 (line 48)
(undefined="[object Array]", undefined=""onComplete"", undefined="(void 0)", undefined="[object Object]")?v=2.8 (line 48)
(undefined="[object Object]", undefined="[object Object]", undefined="(void 0)", undefined="(void 0)", undefined="[object Object]")?v=2.8 (line 48)
(undefined="[object Object]", undefined="[object Object]", undefined="(void 0)", undefined="(void 0)", undefined="[object Object]")?v=2.8 (line 14)
(undefined="[object Object]", undefined="[object Object]")?v=2.8 (line 48)
(undefined="[object Object]")?v=2.8 (line 48)
_144()?v=2.8 (line 14)
_142(undefined="[object Object]")?v=2.8 (line 14)
(undefined="[object Object]")?v=2.8 (line 14)
(undefined="[object Object]")?v=2.8 (line 48)
_144()?v=2.8 (line 14)
_142(undefined="[object Object]")?v=2.8 (line 14)
(undefined="[object Object]")?v=2.8 (line 14)
_144()?v=2.8 (line 14)
_142(undefined="[object Object]")?v=2.8 (line 14)
(undefined="[object Object]")?v=2.8 (line 14)
_144()?v=2.8 (line 14)
_142(undefined="[object Object]")?v=2.8 (line 14)
(undefined="[object Object]")?v=2.8 (line 14)
_144()?v=2.8 (line 14)
_142(undefined="[object Object]")?v=2.8 (line 14)
(undefined="[object Object]")?v=2.8 (line 14)
(undefined="[object Object]")?v=2.8 (line 48)
()?v=2.8 (line 14)
(undefined="12")?v=2.8 (line 14)
if ( g.attributes && g.attributes.id === "highlight" ) {
if ( g && g.attributes && g.attributes.id === "highlight" ) {