How to refresh esri Map in code

1909
1
Jump to solution
04-30-2014 12:59 AM
Labels (1)
NicolasVIOT
New Contributor II
Hi everyone,

I'm trying to do a screenshot of a part of MyMap and this is how I proceed :
(MyMap is esri Map)


  • hide all layers

  •             var screenShotLayer = MyMap.Layers["ScreenShotLayer"] as GraphicsLayer;             var regionsLayer = MyMap.Layers["RegionsLayer"] as GraphicsLayer;             var puitsLayer = MyMap.Layers["PuitsLayer"] as GraphicsLayer;             var linesLayer = MyMap.Layers["LinesLayer"] as GraphicsLayer;             var blocksLayer = MyMap.Layers["BlocksLayer"] as GraphicsLayer;             var bufferPuitsLayer = MyMap.Layers["BufferPuitsLayer"] as GraphicsLayer;             var topoMapLayer = MyMap.Layers["TopoMapLayer"] as ArcGISLocalTiledLayer;             var topoMapLayer2 = MyMap.Layers["TopoMapLayer2"] as ArcGISLocalTiledLayer;              regionsLayer.Visible = false;             puitsLayer.Visible = false;             linesLayer.Visible = false;             blocksLayer.Visible = false;             bufferPuitsLayer.Visible = false;             topoMapLayer.Visible = false;             topoMapLayer2.Visible = false;


  • Save Map Extent

  • var oldExtent = MyMap.Extent;


  • Add graphics that I want to screenshot in a specific layer

  • screenShotLayer.Graphics.AddRange(ListGraphicCopy);


  • Get the extent of my screenshotlayer

  • MyMap.Extent = screenShotLayer.FullExtent;


  • Do screenshot and revert all changes

  •             //On fait le screenshot             var image = Helper.BitmapHelper.CreateScreenShot(MyMap);             //On supprime les graphics ajouté au layer screenshot             foreach (var graphic in ListGraphicCopy) screenShotLayer.Graphics.Remove(graphic);             //On remet l'ancien cadrage qu'avait la map             MyMap.Extent = oldExtent;              //On rend tous les layers visible             regionsLayer.Visible = true;             puitsLayer.Visible = true;             linesLayer.Visible = true;             blocksLayer.Visible = true;             bufferPuitsLayer.Visible = true;             topoMapLayer.Visible = true;             topoMapLayer2.Visible = true;

The mather is that the map doesn't refresh without UserInterface asked her so the result is the basic view and not the one I create for screenshot.

Can anyone help me on this?

Thanks in advance.
0 Kudos
1 Solution

Accepted Solutions
NicolasVIOT
New Contributor II
By writing this thread I've foud a solution.

As I said, the mather was that the UI doesn't refresh.

So the solution is to force it :
        /// <summary>         /// Rafraîchit l'interface         /// </summary>         private static void refreshUI()         {             DispatcherFrame frame = new DispatcherFrame();             Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,                 new DispatcherOperationCallback(f =>                 {                     ((DispatcherFrame)f).Continue = false;                     return null;                 }), frame);             Dispatcher.PushFrame(frame);         }


And it works !

View solution in original post

0 Kudos
1 Reply
NicolasVIOT
New Contributor II
By writing this thread I've foud a solution.

As I said, the mather was that the UI doesn't refresh.

So the solution is to force it :
        /// <summary>         /// Rafraîchit l'interface         /// </summary>         private static void refreshUI()         {             DispatcherFrame frame = new DispatcherFrame();             Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,                 new DispatcherOperationCallback(f =>                 {                     ((DispatcherFrame)f).Continue = false;                     return null;                 }), frame);             Dispatcher.PushFrame(frame);         }


And it works !
0 Kudos