/// <summary> /// Initializes a new instance of the <see cref="MeasureToolbar"/> class. /// </summary> public MeasureToolbar() { DefaultStyleKey = typeof(MeasureToolbar); LinearUnits = new ObservableCollection <LinearUnit>() { Geometry.LinearUnits.Centimeters, Geometry.LinearUnits.Feet, Geometry.LinearUnits.Inches, Geometry.LinearUnits.Kilometers, Geometry.LinearUnits.Meters, Geometry.LinearUnits.Miles, Geometry.LinearUnits.Millimeters, Geometry.LinearUnits.NauticalMiles, Geometry.LinearUnits.Yards }; AreaUnits = new ObservableCollection <AreaUnit>() { Geometry.AreaUnits.Acres, Geometry.AreaUnits.Hectares, Geometry.AreaUnits.SquareCentimeters, Geometry.AreaUnits.SquareDecimeters, Geometry.AreaUnits.SquareFeet, Geometry.AreaUnits.SquareKilometers, Geometry.AreaUnits.SquareMeters, Geometry.AreaUnits.SquareMiles, Geometry.AreaUnits.SquareMillimeters, Geometry.AreaUnits.SquareYards }; LineSketchEditor = new SketchEditor(); AreaSketchEditor = new SketchEditor(); SelectionLineSymbol = LineSketchEditor.Style.LineSymbol; SelectionFillSymbol = AreaSketchEditor.Style.FillSymbol; }
public async Task EditGeometryAsync(Graphic graphic, SpatialReference mapSpatialReference) { if (IsActive) { return; } try { IsActive = true; SketchEditor.GeometryChanged += SketchEditor_GeometryChanged; // Maps geometry spatialreference var geometryToEdit = GeometryEngine.Project(graphic.Geometry, mapSpatialReference); var geometry = await SketchEditor.StartAsync(geometryToEdit); if (geometry == null) { return; } // Updates item in sqlite var item = await DatabaseRepository.Current.LoadAsync <GeometryItem>(id : int.Parse(graphic.GetId())); if (item == null) { return; } item.GeometryJson = geometry.ToJson(); item.GeometryType = geometry.GeometryType.ToString(); await DatabaseRepository.Current.InsertAsync(item); graphic.Geometry = geometry; } catch (Exception ex) { Debug.WriteLine("EditGeometryAsync Exception: " + ex.Message); } finally { IsActive = false; IsGeometryInfoVisible = false; SketchEditor.GeometryChanged -= SketchEditor_GeometryChanged; } }
public async Task CreateNewGeometry(SketchCreationMode creationMode, bool measure = false) { if (IsActive) { return; } try { IsActive = true; SketchEditor.GeometryChanged += SketchEditor_GeometryChanged; var geometry = await SketchEditor.StartAsync(creationMode, new SketchEditConfiguration()); if (geometry == null || measure) { return; } // Creates a sqlite object to save data var item = new GeometryItem { Color = Color.Red.Name, GeometryType = geometry.GeometryType.ToString(), GeometryJson = geometry.ToJson() }; // Saves data await DatabaseRepository.Current.InsertAsync(item); // Creates graphic var graphic = GraphicFactory.Current.CreateGraphic(geometry, Color.Red, item.Id); // Add graphic to overlay OverlayProvider.Current.GeometryOverlay.Graphics.Add(graphic); } catch (Exception ex) { Debug.WriteLine("CreateNewGeometry Exception: " + ex.Message); } finally { IsActive = false; IsGeometryInfoVisible = false; SketchEditor.GeometryChanged -= SketchEditor_GeometryChanged; } }
public async Task <Geometry> CreateAreaToDownloadAsync(string infoMessage) { if (IsActive) { return(null); } try { IsActive = true; GeometryInfo = infoMessage; IsGeometryInfoVisible = true; var geometry = await SketchEditor.StartAsync(SketchCreationMode.Polygon, new SketchEditConfiguration() { AllowMove = true, ResizeMode = SketchResizeMode.Stretch, AllowRotate = true }); return(geometry); } catch (Exception ex) { Debug.WriteLine("CreateNewGeometry Exception: " + ex.Message); } finally { IsActive = false; IsGeometryInfoVisible = false; } return(null); }
public override void OnApplyTemplate() #endif { base.OnApplyTemplate(); _measureLengthButton = GetTemplateChild("MeasureLength") as ToggleButton; if (_measureLengthButton != null) { _measureLengthButton.Click += OnToggleMeasureMode; } _measureAreaButton = GetTemplateChild("MeasureArea") as ToggleButton; if (_measureAreaButton != null) { _measureAreaButton.Click += OnToggleMeasureMode; } _measureFeatureButton = GetTemplateChild("MeasureFeature") as ToggleButton; if (_measureFeatureButton != null) { _measureFeatureButton.Click += OnToggleMeasureMode; } _clearButton = GetTemplateChild("Clear") as ButtonBase; if (_clearButton != null) { _measureFeatureResultOverlay.Graphics.CollectionChanged += (s, e) => { if (Mode == MeasureToolbarMode.Feature) { _clearButton.IsEnabled = _measureFeatureResultOverlay.Graphics.Any(); AddMeasureFeatureResultOverlay(MapView); } }; _clearButton.Click += OnClear; } _measureResultTextBlock = GetTemplateChild("MeasureResult") as TextBlock; _linearUnitsSelector = GetTemplateChild("LinearUnitsSelector") as UIElement; _areaUnitsSelector = GetTemplateChild("AreaUnitsSelector") as UIElement; if (LinearUnits == null || !LinearUnits.Any()) { LinearUnits = new LinearUnit[] { Geometry.LinearUnits.Centimeters, Geometry.LinearUnits.Feet, Geometry.LinearUnits.Inches, Geometry.LinearUnits.Kilometers, Geometry.LinearUnits.Meters, Geometry.LinearUnits.Miles, Geometry.LinearUnits.Millimeters, Geometry.LinearUnits.NauticalMiles, Geometry.LinearUnits.Yards }; } if (SelectedLinearUnit == null) { SelectedLinearUnit = LinearUnits.Any(u => u == Geometry.LinearUnits.Meters) ? Geometry.LinearUnits.Meters : LinearUnits.FirstOrDefault(); } if (AreaUnits == null || !AreaUnits.Any()) { AreaUnits = new AreaUnit[] { Geometry.AreaUnits.Acres, Geometry.AreaUnits.Hectares, Geometry.AreaUnits.SquareCentimeters, Geometry.AreaUnits.SquareDecimeters, Geometry.AreaUnits.SquareFeet, Geometry.AreaUnits.SquareKilometers, Geometry.AreaUnits.SquareMeters, Geometry.AreaUnits.SquareMiles, Geometry.AreaUnits.SquareMillimeters, Geometry.AreaUnits.SquareYards }; } if (SelectedAreaUnit == null) { SelectedAreaUnit = AreaUnits.Any(u => u == Geometry.AreaUnits.SquareMiles) ? Geometry.AreaUnits.SquareMiles : AreaUnits.FirstOrDefault(); } if (LineSketchEditor == null) { LineSketchEditor = new SketchEditor(); } if (AreaSketchEditor == null) { AreaSketchEditor = new SketchEditor(); } if (SelectionLineSymbol == null) { SelectionLineSymbol = LineSketchEditor?.Style?.LineSymbol; } if (SelectionFillSymbol == null) { SelectionFillSymbol = AreaSketchEditor?.Style?.FillSymbol; } Mode = MeasureToolbarMode.None; PrepareMeasureMode(); }