Thanks Robert, this is really helpful, but I still must have something wrong with my code. I've added an attribute to the graphics before they get added to the graphics layer, but when I try to remove the graphic from the graphic layer, I get the message: "Uncaught TypeError: Cannot read property 'attribute' of undefined."
Here is my revised code:
Creating the Graphics Layer near the beginning of my code:
var resultsLayer = new GraphicsLayer();
myMap = new Map({
basemap: basemap,
layers: [resultsLayer],
sliderPosition: "bottom-right"
});
The below functions, first, add the selected sport(s), and then remove the selected sport(s). Note that "text" is the name of the sport that is passed to each function.
function getResults(text, response){
console.log("in getResults");
console.log(response);
var parkFeatures = response.features.map(function(feature){
feature.symbol = parkSymbol;
feature.popupTemplate = resultsPopupTemplate;
feature.attribute = text;
return feature;
});
console.log(parkFeatures);
resultsLayer.graphics.addMany(parkFeatures);
};
function removeLayer(text){
for (gL = resultsLayer.graphics.length; gL>=0; gL--){
if (resultsLayer.graphics[gL].attribute == text){
resultsLayer.remove(resultsLayer.graphics[gL]);
}
}
}
Am I not adding the attribute to the graphic correctly (line 7)? The error is being thrown at line 20. Thanks.