AnsweredAssumed Answered

how to remove graphic from view using attribute in 4.6

Question asked by lorieme on Jan 16, 2018
Latest reply on Jan 16, 2018 by lorieme

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[i].attributes['Legend ID'] == myID) {

            var pointAtt = {

               "LegendID": arrayIdFeatures[i].attributes['Legend ID']

                     };

            var pointGeography = arrayIdFeatures[i].geometry;

            var pointGraphic = new Graphic({

                        geometry: arrayIdFeatures[i].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[i].attributes.LegendID == myID) {

                  view.graphics.remove(view.graphics.graphics[i]);

         } // end if stmt

      } // end for stmt

   } //end if stmt

} // end function removeGraphic()

 

 

Outcomes