Hi,
I am using the 4.0 API,
trying to remove elements from the graphic layer some times leave the icon on the map...
how do I refresh it?
all the old examples that I sow saying do dataLayer.refresh(); or setExtent...
needless to say it didn't work!
I wonder if you have to use watch as explained in this thread. It's not exactly what you're trying to do but it is responding after a given event so it might still be applicable.
Didn't help... no reload/refresh there
I would think it refreshes automatically after something like:
graphicsLayer.remove(graphicsLayer.graphics.items)
it doesn't...
or maybe i'm doing something worng...
view.popup.on("trigger-action", function (evt) {
if (evt.action.id === "closeEvent") {
eventsLayer.remove(view.popup.selectedFeature);
view.popup.visible = false;
}
else if (evt.action.id === "closeAllEvents") {
eventsLayer.removeAll();
view.popup.visible = false;
}
If the graphic is not in the eventsLayer, then the remove function won't work.
You can try:
view.graphics.remove(view.popup.selectedFeature);
or
view.graphics.removeAll();
If you provide more code someone might be able to help.
tried using view.graphics.remove(view.popup.selectedFeature); -> didn't work
my code is pretty straight forward...
create the GraphicLayer and add it to the map:
var dataLayer = new GraphicsLayer({
id: "dataLayer"
});
map.add(eventsLayer);
I'm adding graphics to the eventsLayer like that (using SignalR messaging):
function AddEvent(message,position)
{
var x = JSON.parse(position);
var data = JSON.parse(message);
ElementAtt = {
Name: data.Description,
Source: data.Source,
Triggers: data.Trigger,
Time: new Date().toLocaleString(),
Description: data.IdDescription,
Latitude: x.X,
Longitude: x.Y
};
point = new Point({
longitude: x.Y,
latitude: x.X
});
pointGraphic = new Graphic({
geometry: point,
symbol: eventMarkerSymbol,
id: data.Id,
attributes: ElementAtt,
popupTemplate: eventTemplate
});
eventsLayer.add(pointGraphic);
view.goTo(Point);
}
the problematic part....
removing elements(Using popup action):
view.popup.on("trigger-action", function (evt) {
if (evt.action.id === "closeEvent") {
eventsLayer.remove(view.popup.selectedFeature);
view.popup.visible = false;
}
else if (evt.action.id === "closeAllEvents") {
eventsLayer.removeAll();
view.popup.visible = false;
}
});
for future reference the problem was that I used the Graphic id with my own id.
so removing it did not work