private void Initialize() { // Create a light gray canvas map Map myMap = new Map(Basemap.CreateLightGrayCanvas()); // Create graphics overlay to display sketch geometry _sketchOverlay = new GraphicsOverlay(); _myMapView.GraphicsOverlays.Add(_sketchOverlay); // Assign the map to the MapView _myMapView.Map = myMap; // Set the sketch editor configuration to allow vertex editing, resizing, and moving SketchEditConfiguration config = _myMapView.SketchEditor.EditConfiguration; config.AllowVertexEditing = true; config.ResizeMode = SketchResizeMode.Uniform; config.AllowMove = true; // Listen to the sketch editor tools CanExecuteChange so controls can be enabled/disabled _myMapView.SketchEditor.UndoCommand.CanExecuteChanged += CanExecuteChanged; _myMapView.SketchEditor.RedoCommand.CanExecuteChanged += CanExecuteChanged; _myMapView.SketchEditor.CompleteCommand.CanExecuteChanged += CanExecuteChanged; // Listen to collection changed event on the graphics overlay to enable/disable controls that require a graphic _sketchOverlay.Graphics.CollectionChanged += GraphicsChanged; }
private void Initialize() { // Create a light gray canvas map Map myMap = new Map(Basemap.CreateLightGrayCanvas()); // Create graphics overlay to display sketch geometry _sketchOverlay = new GraphicsOverlay(); MyMapView.GraphicsOverlays.Add(_sketchOverlay); // Assign the map to the MapView MyMapView.Map = myMap; // Fill the combo box with choices for the sketch modes (shapes) SketchModeComboBox.ItemsSource = System.Enum.GetValues(typeof(SketchCreationMode)); SketchModeComboBox.SelectedIndex = 0; // Set the sketch editor configuration to allow vertex editing, resizing, and moving SketchEditConfiguration config = MyMapView.SketchEditor.EditConfiguration; config.AllowVertexEditing = true; config.ResizeMode = SketchResizeMode.Uniform; config.AllowMove = true; // Set the sketch editor as the page's data context DataContext = MyMapView.SketchEditor; }
} // end CreateGraphic /// <summary> /// Draw Button Callback /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void DrawButtonClick(object sender, RoutedEventArgs e) { if (selectedLayers == null) { MessageBox.Show("Please select at least one layer", "LAYER SELECTION ERROR"); haveLayer = false; } else if (selectedLayers.Count < 1) { haveLayer = false; MessageBox.Show("Please select at least one layer", "LAYER SELECTION ERROR"); } else try { // Clear out previous graphics if they exist sketchOverlay.Graphics.Clear(); // Set Buttons AOIDraw.IsEnabled = true; AOIClear.IsEnabled = true; AOICancel.IsEnabled = true; AOISelect.IsEnabled = true; // Create graphics area for a redrawable rectangle w/labels SketchCreationMode creationMode = (SketchCreationMode)6; SketchEditConfiguration sketchEdit = new SketchEditConfiguration { AllowMove = true, AllowRotate = false, ResizeMode = (SketchResizeMode)1 }; // Let the user draw on the map view using the chosen sketch mode Esri.ArcGISRuntime.Geometry.Geometry geometry = await BasemapView.SketchEditor.StartAsync(creationMode, true); // Create and add a graphic from the geometry the user drew Graphic graphic = CreateGraphic(geometry); sketchOverlay.Graphics.Add(graphic); haveSketch = true; } catch (TaskCanceledException) { sketchOverlay.Graphics.Clear(); haveSketch = false; AOIDraw.IsEnabled = true; AOIClear.IsEnabled = true; AOICancel.IsEnabled = true; AOISelect.IsEnabled = true; } catch (Exception ex) { // Report exceptions MessageBox.Show("Error drawing graphic shape: " + ex.Message); } } // end DrawButtonClick
private void Initialize() { // Create a light gray canvas map Map myMap = new Map(Basemap.CreateLightGrayCanvas()); // Create graphics overlay to display sketch geometry _sketchOverlay = new GraphicsOverlay(); MyMapView.GraphicsOverlays.Add(_sketchOverlay); // Assign the map to the MapView MyMapView.Map = myMap; // Fill the combo box with choices for the sketch modes (shapes) Array sketchModes = System.Enum.GetValues(typeof(SketchCreationMode)); foreach (object mode in sketchModes) { SketchModePicker.Items.Add(mode.ToString()); } SketchModePicker.SelectedIndex = 0; // Set the sketch editor configuration to allow vertex editing, resizing, and moving SketchEditConfiguration config = MyMapView.SketchEditor.EditConfiguration; config.AllowVertexEditing = true; config.ResizeMode = SketchResizeMode.Uniform; config.AllowMove = true; // Set a gray background color for Android if (Device.RuntimePlatform == Device.Android) { DrawToolsGrid.BackgroundColor = Color.Gray; } // Hack to get around linker being too aggressive - this should be done with binding. UndoButton.Command = MyMapView.SketchEditor.UndoCommand; RedoButton.Command = MyMapView.SketchEditor.RedoCommand; CompleteButton.Command = MyMapView.SketchEditor.CompleteCommand; }
private void drawAndEditCheckBox_Checked(object sender, RoutedEventArgs e) { Window w = Window.GetWindow(this); myMapView = (MapView)w.FindName("myMapView"); //////////////////////////////////////////////////////////////////////////////////////////////// SketchModeComboBox.ItemsSource = System.Enum.GetValues(typeof(SketchCreationMode)); SketchModeComboBox.SelectedIndex = 0; //SketchEditConfiguration config = myMapView.SketchEditor.EditConfiguration; //config.AllowVertexEditing = true; //config.ResizeMode = SketchResizeMode.Uniform; //config.AllowMove = true; // Set the sketch editor configuration to allow vertex editing, resizing, and moving SketchEditConfiguration config = myMapView.SketchEditor.EditConfiguration; config.AllowVertexEditing = true; config.ResizeMode = SketchResizeMode.Uniform; config.AllowMove = true; // Set the sketch editor as the page's data context DataContext = myMapView.SketchEditor; }