When users enter a new input (a zip code), it creates a graphic for it but when I enter the second input it doesn't remove the first graphic for the first input
I tried to use view.graphics.remove() to remove the oldest user's input whenever the user hits the generate button but it did not work it keeps adding graphics for each user's input (generate click )
This is my code so far:
NOTE: I'm getting the data from Open weather API
Solved! Go to Solution.
Hi @HossamAymanHassan ,
It looks like you are calling your removeGraphic function at the start of your script but not after adding a new graphic. Someplace in your script before adding the new graphic you would want to remove the old graphic(s). There are a few different ways to do this.
// Using your removeGraphic() function
removeGraphic(graphicToRemove)
// Using remove()
myMapView.graphics.remove(graphicToRemove);
// Using removeAll()
myMapView.graphics.removeAll()
// Then add the new graphic
myMapView.graphics.add(newGraphic);
Hi @HossamAymanHassan ,
It looks like you are calling your removeGraphic function at the start of your script but not after adding a new graphic. Someplace in your script before adding the new graphic you would want to remove the old graphic(s). There are a few different ways to do this.
// Using your removeGraphic() function
removeGraphic(graphicToRemove)
// Using remove()
myMapView.graphics.remove(graphicToRemove);
// Using removeAll()
myMapView.graphics.removeAll()
// Then add the new graphic
myMapView.graphics.add(newGraphic);
In this code sample, your require modules don't match up with your function arguments. Your Graphic argument thinks it's a BasemapGallery
require([
"esri/Map",
"esri/views/MapView",
"esri/widgets/BasemapGallery",
"esri/Graphic",
], (Map, MapView, Graphic) => {
Hi KenBuja
Thank you for mentioning it. I did use it in my original JS file, but I forgot to delete it from the sample code.