How can I remove a graphic using an attribute? I am able to add the graphic.
view.graphics.graphics.length is invalid. I am having a hard time finding what I need in the view object because of all the _proto_ levels.
//*************************************************//
//** show Graphic for selected feature **//
//*************************************************//
function showGraphic(myID) {
if (arrayIdFeatures.length) {
for (i = 0; i < arrayIdFeatures.length; i++) {
if (arrayIdFeatures.attributes['Legend ID'] == myID) {
var pointAtt = {
"LegendID": arrayIdFeatures.attributes['Legend ID']
};
var pointGeography = arrayIdFeatures.geometry;
var pointGraphic = new Graphic({
geometry: arrayIdFeatures.geometry,
symbol: pointSymbol,
attributes: pointAtt
});
view.graphics.add(pointGraphic);
} // end if stmt
} // end for stmt
} //end if stmt
} // end function showGraphic()
//*************************************************//
//** remove Graphic for selected feature **//
//*************************************************//
function removeGraphic(myID) {
if (view.graphics.graphics.length) {
for (i = 0; i < view.graphics.graphics.length; i++) {
if (view.graphics.graphics.attributes.LegendID == myID) {
view.graphics.remove(view.graphics.graphics);
} // end if stmt
} // end for stmt
} //end if stmt
} // end function removeGraphic()
Solved! Go to Solution.
Lori,
They way you are working with collections is incorrect. Collections are a bit different than arrays.
//*************************************************//
//** remove Graphic for selected feature **//
//*************************************************//
function removeGraphic(myID) {
if (view.graphics.graphics.length) {
for (i = 0; i < view.graphics.length; i++) {
if (view.graphics.getItemAt(i).attributes.LegendID == myID) {
view.graphics.remove(view.graphics.getItemAt(i));
} // end if stmt
} // end for stmt
} //end if stmt
} // end function removeGraphic()
Lori,
They way you are working with collections is incorrect. Collections are a bit different than arrays.
//*************************************************//
//** remove Graphic for selected feature **//
//*************************************************//
function removeGraphic(myID) {
if (view.graphics.graphics.length) {
for (i = 0; i < view.graphics.length; i++) {
if (view.graphics.getItemAt(i).attributes.LegendID == myID) {
view.graphics.remove(view.graphics.getItemAt(i));
} // end if stmt
} // end for stmt
} //end if stmt
} // end function removeGraphic()
Robert,
Thanks for the insight about Collections. I will learn more about it.
Using view.graphics.length worked. Also, using view.graphics.getItemAt(I).attributes.<custom attribute> worked. Brilliant. Thanks!!