How do I Refresh Map/GrphicLayer after Remove element

3536
7
07-03-2016 01:07 AM
DrorElgabsi
New Contributor II

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!

Tags (1)
0 Kudos
7 Replies
SteveCole
Frequent Contributor

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.

0 Kudos
DrorElgabsi
New Contributor II

Didn't help... no reload/refresh there

0 Kudos
FC_Basson
MVP Regular Contributor

I would think it refreshes automatically after something like:

graphicsLayer.remove(graphicsLayer.graphics.items)
0 Kudos
DrorElgabsi
New Contributor II

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;

                }

0 Kudos
FC_Basson
MVP Regular Contributor

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.

0 Kudos
DrorElgabsi
New Contributor II

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;

            }

        });

0 Kudos
DrorElgabsi
New Contributor II

for future reference the problem was that I used the Graphic id with my own id.

so removing it did not work

0 Kudos