SetViewpointGeometryAsync and then screenshot

434
3
06-05-2017 02:12 AM
Highlighted
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)
Reply
0 Kudos
3 Replies
Highlighted
Regular Contributor II

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. 

Reply
0 Kudos
Highlighted
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.

Reply
0 Kudos
Highlighted
Frequent 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);
            }
        }
Reply
0 Kudos