예제 #1
0
        private async void OnEditButtonClick()
        {
            if (_selection == null)
            {
                return;                     // Selection missing
            }
            // Cancel previous edit
            if (SceneEditHelper.IsActive)
            {
                SceneEditHelper.Cancel();
            }

            Esri.ArcGISRuntime.Geometry.Geometry editedGeometry = null;

            try
            {
                // Edit selected geometry and set it back to the selected graphic
                switch (_selection.GeometryType)
                {
                case GeometryType.Point:
                    editedGeometry = await SceneEditHelper.CreatePointAsync(
                        View);

                    break;

                case GeometryType.Polyline:
                    _selection.SetHidden();     // Hide selected graphic from the UI
                    editedGeometry = await SceneEditHelper.EditPolylineAsync(
                        View,
                        _selection.SelectedGraphic.Geometry as Polyline);

                    break;

                case GeometryType.Polygon:
                    _selection.SetHidden();     // Hide selected graphic from the UI
                    editedGeometry = await SceneEditHelper.EditPolygonAsync(
                        View,
                        _selection.SelectedGraphic.Geometry as Polygon);

                    break;

                default:
                    break;
                }

                _selection.SelectedGraphic.Geometry = editedGeometry; // Set edited geometry to selected graphic
            }
            catch (TaskCanceledException tce)
            {
                // This occurs if draw operation is canceled or new operation is started before previous was finished.
                Debug.WriteLine("Previous edit operation was canceled.");
            }
            finally
            {
                _selection.Unselect();
                _selection.SetVisible(); // Show selected graphic from the UI
            }
        }
        private async void DrawButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Geometry geometry = null;
                Graphic  graphic  = null;

                CancelButton.IsEnabled = true;
                ClearButton.IsEnabled  = false;

                // Draw geometry and create a new graphic using it
                switch ((DrawShape)DrawShapes.SelectedValue)
                {
                case DrawShape.Point:
                    geometry = await SceneEditHelper.CreatePointAsync(MySceneView);

                    graphic = new Graphic(geometry);
                    _pointsOverlay.Graphics.Add(graphic);
                    break;

                case DrawShape.Polygon:
                    geometry = await SceneEditHelper.CreatePolygonAsync(MySceneView);

                    graphic = new Graphic(geometry);
                    _polygonsOverlay.Graphics.Add(graphic);
                    break;

                case DrawShape.Polyline:
                    geometry = await SceneEditHelper.CreatePolylineAsync(MySceneView);

                    graphic = new Graphic(geometry);
                    _polylinesOverlay.Graphics.Add(graphic);
                    break;

                default:
                    break;
                }
            }
            catch (TaskCanceledException)
            {
                // This occurs if draw operation is canceled or new operation is started before previous was finished.
                Debug.WriteLine("Previous draw operation was canceled.");
            }
            finally
            {
                CancelButton.IsEnabled = false;
                ClearButton.IsEnabled  = true;
            }
        }
        private async void EditButton_Click(object sender, RoutedEventArgs e)
        {
            if (_selection == null)
            {
                return;                         // Selection missing
            }
            // Cancel previous edit
            if (SceneEditHelper.IsActive)
            {
                SceneEditHelper.Cancel();
            }

            Geometry editedGeometry = null;

            DrawButton.IsEnabled   = false;
            ClearButton.IsEnabled  = false;
            EditButton.IsEnabled   = false;
            CancelButton.IsEnabled = true;

            try
            {
                // Edit selected geometry and set it back to the selected graphic
                switch (_selection.GeometryType)
                {
                case GeometryType.Point:
                    editedGeometry = await SceneEditHelper.CreatePointAsync(
                        MySceneView);

                    break;

                case GeometryType.Polyline:
                    _selection.SetHidden();                     // Hide selected graphic from the UI
                    editedGeometry = await SceneEditHelper.EditPolylineAsync(
                        MySceneView,
                        _selection.SelectedGraphic.Geometry as Polyline);

                    break;

                case GeometryType.Polygon:
                    _selection.SetHidden();                     // Hide selected graphic from the UI
                    editedGeometry = await SceneEditHelper.EditPolygonAsync(
                        MySceneView,
                        _selection.SelectedGraphic.Geometry as Polygon);

                    break;

                default:
                    break;
                }

                _selection.SelectedGraphic.Geometry = editedGeometry;         // Set edited geometry to selected graphic
            }
            catch (TaskCanceledException)
            {
                // This occurs if draw operation is canceled or new operation is started before previous was finished.
                Debug.WriteLine("Previous edit operation was canceled.");
            }
            finally
            {
                _selection.Unselect();
                _selection.SetVisible();                 // Show selected graphic from the UI
                DrawButton.IsEnabled   = true;
                ClearButton.IsEnabled  = true;
                CancelButton.IsEnabled = false;
            }
        }