Select to view content in your preferred language

Refresh Graphics Layer

4676
2
07-23-2010 07:13 AM
by Anonymous User
Not applicable
Original User: ereed

I am using a dynamic map service that contains a point layer that changes frequently. I refresh the dynamic layer every 10 seconds, but the graphic that contains the map tip remains at the original location.If I remove the graphics from the graphicslayer, and recreate them, I see the graphics blink, but the show up at the original location. How do I get the graphics to refresh, and show up at the new location, just as is happening with the dynamic layer?

     public MainPage()
        {
            InitializeComponent();

            DispatcherTimer timer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(10) };
            timer.Tick += (s, e) => { RefreshMap(); };
            timer.Start();

        }
        private void RefreshMap()
        {
            DynamicLayer dLayer;
            dLayer= (DynamicLayer)Map1.Layers["myLayer"];
            dLayer.Refresh();
            CreatePtGraphics();
        }
        private void CreatePtGraphics()
        {
            GraphicsLayer gLayer;
            gLayer = (GraphicsLayer)Map1.Layers["PtGraphicsLayer"];
            //gLayer.ClearGraphics();

            ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query()
            {
                Geometry = new ESRI.ArcGIS.Client.Geometry.Envelope(-180, 0, 0, 90)
            };
            query.OutFields.Add("*");
            QueryTask queryTask = new QueryTask("http://XXX/ArcGIS/rest/services/XXX/MapServer/0");
            queryTask.ExecuteCompleted += PtGraphicsLayerQueryTask_ExecuteCompleted;
            queryTask.ExecuteAsync(query);
            //gLayer.Refresh();
        }


        void PtGraphicsLayerQueryTask_ExecuteCompleted(object sender, QueryEventArgs queryArgs)
        {
            if (queryArgs.FeatureSet == null)
                return;

            FeatureSet resultFeatureSet = queryArgs.FeatureSet;
            ESRI.ArcGIS.Client.GraphicsLayer graphicsLayer =
            Map1.Layers["PtGraphicsLayer"] as ESRI.ArcGIS.Client.GraphicsLayer;

            if (resultFeatureSet != null && resultFeatureSet.Features.Count > 0)
            {
                foreach (ESRI.ArcGIS.Client.Graphic graphicFeature in resultFeatureSet.Features)
                {
                    graphicFeature.Symbol = DefaultMarkerSymbol;
                    graphicsLayer.Graphics.Add(graphicFeature);
                }
            }
        }
0 Kudos
2 Replies
JenniferNery
Esri Regular Contributor
Looking at your code, you are trying to add graphics to a MapServer layer. This is read-only and any edits to it will not be applied, even if you refresh your dynamic layer.

Jennifer
0 Kudos
by Anonymous User
Not applicable
Original User: dbroux

Might be a cache issue.

Try disabling the client cache :
 
queryTask.DisableClientCaching = true;

This will add a time stamp to the URL.
0 Kudos