SetViewpointGeometryAsync and then screenshot

1051
3
06-05-2017 02:12 AM
xiaoguangyan
New Contributor III

I SetViewpointGeometryAsync and then screenshot code follow, but the image of screenshot is uncomleleted, some of image is backgound ,I think this is due to the mapview can't change immediately, but how to solve this ? code and image show bellow

Tags (1)
0 Kudos
3 Replies
AnttiKajanus1
Occasional Contributor III

Is the MapView (actually the layers) still requesting the data at that point? You might need to use arcgis-runtime-samples-dotnet/src/WPF/ArcGISRuntime.WPF.Samples/Samples/MapView/DisplayDrawingStatus...  to make sure that the drawing is finished before taking the screenshot. 

0 Kudos
xiaoguangyan
New Contributor III

Hi, Antti

            I wonder if that data is requested (and draw) as I navigate the map to other extents, then which compeleted comes first, the navigate compeleted or the draw compeleted? thanks.

0 Kudos
JenniferNery
Esri Regular Contributor

You can subscribe to DrawStatusChanged to be able to grab the image when all layers are rendered.

        EventHandler<DrawStatusChangedEventArgs> onDrawStatusChanged = null;
        private async void OnSetView(object sender, RoutedEventArgs e)
        {
            try
            {
                MyMapView.DrawStatusChanged -= onDrawStatusChanged;
                var geometry = await MyMapView.SketchEditor.StartAsync(SketchCreationMode.Rectangle, false);
                await MyMapView.SetViewpointGeometryAsync(geometry);
                onDrawStatusChanged = async (s, a) =>
                  {
                      if (a.Status == DrawStatus.Completed)
                      {
                          MyMapView.DrawStatusChanged -= onDrawStatusChanged;
                          var image = await MyMapView.ExportImageAsync();
                          new Window() { Content = new Image() { Source = await image.ToImageSourceAsync() } }.ShowDialog();
                      }
                  };
                MyMapView.DrawStatusChanged += onDrawStatusChanged;
            }
            catch(TaskCanceledException)
            {
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
0 Kudos