private async void DistanceAzimuthItem_Click(object sender, RoutedEventArgs e) { try { var line = await RequestUserShape(DrawShape.LineSegment, _lineSymbol) as Polyline; // Requesting shape canceled if (line == null) { return; } var parameters = new MensurationLengthParameters() { AngularUnit = comboAngularUnit.SelectedItem as AngularUnit, LinearUnit = comboLinearUnit.SelectedItem as LinearUnit }; var result = await _mensurationTask.DistanceAndAngleAsync( line.Parts.First().StartPoint, line.Parts.First().EndPoint, parameters); ShowResults(result, ((MenuFlyoutItem)sender).Text); } catch (Exception ex) { var _ = new MessageDialog(ex.Message, "Sample Error").ShowAsync(); } }
private async void OnMeasureCommand(object param) { if (_editState == EditState.None && _mapView != null && !_mapView.Editor.IsActive) { _lineSymbol = new SimpleLineSymbol() { Color = Colors.Red, Style = SimpleLineStyle.Solid, Width = 2 } as Symbol; _graphicsOverlay = _mapView.GraphicsOverlays["graphicsOverlay"]; // World Topo Map doesn't support mensuration //var temp = _mapView.Map.Layers["World Topo Map"]; var temp = _mapView.Map.Layers["MensurationMapServiceLayer"]; _mensurationTask = new MensurationTask(new Uri((temp as ArcGISTiledMapServiceLayer).ServiceUri)); // lets do a basic distance measure try { var line = await RequestUserShape(DrawShape.LineSegment, _lineSymbol) as Polyline; // Requesting shape cancelled if (line == null) { return; } var parameters = new MensurationLengthParameters() { AngularUnit = AngularUnits.Degrees, LinearUnit = LinearUnits.Meters }; var result = await _mensurationTask.DistanceAndAngleAsync( line.Parts.First().StartPoint, line.Parts.First().EndPoint, parameters); if (result.Distance != null) { ShowResults(result, "Measure results"); } else { MessageBox.Show("Error", "Mensuration Error"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Mensuration Error"); } finally { _graphicsOverlay.Graphics.Clear(); } } }
private async void DistanceAzimuthButton_Click(object sender, RoutedEventArgs e) { var line = await RequestUserShape(DrawShape.LineSegment, _lineSymbol) as Polyline; try { MapPoint pointOne = new MapPoint(line.Paths[0][0], mapView.SpatialReference); MapPoint pointTwo = new MapPoint(line.Paths[0][1], mapView.SpatialReference); var parameters = new MensurationLengthParameters() { AngularUnit = comboAngularUnit.SelectedItem as AngularUnit, LinearUnit = comboLinearUnit.SelectedItem as LinearUnit }; var result = await _mensurationTask.DistanceAndAngleAsync(pointOne, pointTwo, parameters); ShowResults(result, ((Button)sender).Tag.ToString()); } catch (Exception ex) { MessageBox.Show(ex.Message, "Mensuration Error"); } }
void drawtool_DrawComplete(object sender, DrawEventArgs e) { e.Geometry.SpatialReference = MyMap.SpatialReference; Graphic graphic = new Graphic() { Geometry = e.Geometry }; if (e.Geometry is MapPoint) { graphic.Symbol = LayoutRoot.Resources["DrawPointSymbol"] as SimpleMarkerSymbol; } else if (e.Geometry is Polyline) { graphic.Symbol = LayoutRoot.Resources["DrawPolylineSymbol"] as SimpleLineSymbol; } else if (e.Geometry is Polygon || e.Geometry is Envelope) { graphic.Symbol = LayoutRoot.Resources["DrawPolygonSymbol"] as SimpleFillSymbol; } drawGraphicsLayer.Graphics.Add(graphic); draw.IsEnabled = false; Geometry fromGeometry = null; Geometry toGeometry = null; switch (mensurationOperation) { case MensurationOperation.DistanceAndAngle: case MensurationOperation.HeightFromBaseAndTop: case MensurationOperation.HeightFromBaseAndTopShadow: case MensurationOperation.HeightFromTopAndTopShadow: fromGeometry = (e.Geometry as Polyline).Paths[0][0]; fromGeometry.SpatialReference = MyMap.SpatialReference; toGeometry = (e.Geometry as Polyline).Paths[0][1]; toGeometry.SpatialReference = MyMap.SpatialReference; break; case MensurationOperation.AreaAndPerimeter: case MensurationOperation.Centroid: case MensurationOperation.Point: fromGeometry = e.Geometry; break; } esriUnits?LinearUnit = null; switch (comboLinearUnit.SelectedIndex) { case 0: LinearUnit = esriUnits.esriUnknownUnits; break; case 1: LinearUnit = esriUnits.esriInches; break; case 2: LinearUnit = esriUnits.esriPoints; break; case 3: LinearUnit = esriUnits.esriFeet; break; case 4: LinearUnit = esriUnits.esriYards; break; case 5: LinearUnit = esriUnits.esriMiles; break; case 6: LinearUnit = esriUnits.esriNauticalMiles; break; case 7: LinearUnit = esriUnits.esriMillimeters; break; case 8: LinearUnit = esriUnits.esriCentimeters; break; case 9: LinearUnit = esriUnits.esriMeters; break; case 10: LinearUnit = esriUnits.esriKilometers; break; case 11: LinearUnit = esriUnits.esriDecimalDegrees; break; case 12: LinearUnit = esriUnits.esriDecimeters; break; } DirectionUnit AngularUnit = DirectionUnit.Default; switch (comboAngularUnit.SelectedIndex) { case 0: AngularUnit = DirectionUnit.Default; break; case 1: AngularUnit = DirectionUnit.Radians; break; case 2: AngularUnit = DirectionUnit.DecimalDegrees; break; case 3: AngularUnit = DirectionUnit.DegreesMinutesSeconds; break; case 4: AngularUnit = DirectionUnit.Gradians; break; case 5: AngularUnit = DirectionUnit.Gons; break; } AreaUnit AreaUnits = AreaUnit.Default; switch (comboAreaUnit.SelectedIndex) { case 0: AreaUnits = AreaUnit.Default; break; case 1: AreaUnits = AreaUnit.SquareInches; break; case 2: AreaUnits = AreaUnit.SquareFeet; break; case 3: AreaUnits = AreaUnit.SquareYards; break; case 4: AreaUnits = AreaUnit.Acres; break; case 5: AreaUnits = AreaUnit.SquareMiles; break; case 6: AreaUnits = AreaUnit.SquareMillimeters; break; case 7: AreaUnits = AreaUnit.SquareCentimeters; break; case 8: AreaUnits = AreaUnit.SquareDecimeters; break; case 9: AreaUnits = AreaUnit.SquareMeters; break; case 10: AreaUnits = AreaUnit.Ares; break; case 11: AreaUnits = AreaUnit.Hectares; break; case 12: AreaUnits = AreaUnit.SquareKilometers; break; } if (!mensurationTask.IsBusy) { switch (mensurationOperation) { case MensurationOperation.AreaAndPerimeter: MensurationAreaParameter p1 = new MensurationAreaParameter(); p1.LinearUnit = LinearUnit; p1.AreaUnits = AreaUnits; mensurationTask.AreaAndPerimeterAsync(fromGeometry as Polygon, p1); break; case MensurationOperation.Centroid: MensurationPointParameter p3 = new MensurationPointParameter(); mensurationTask.CentroidAsync(fromGeometry as Polygon, p3); break; case MensurationOperation.DistanceAndAngle: MensurationLengthParameter p5 = new MensurationLengthParameter(); p5.LinearUnit = LinearUnit; p5.AngularUnit = AngularUnit; mensurationTask.DistanceAndAngleAsync(fromGeometry as MapPoint, toGeometry as MapPoint, p5); break; case MensurationOperation.Point: MensurationPointParameter p7 = new MensurationPointParameter(); mensurationTask.PointAsync(fromGeometry as MapPoint, p7); break; case MensurationOperation.HeightFromBaseAndTop: MensurationHeightParameter p9 = new MensurationHeightParameter(); p9.LinearUnit = LinearUnit; mensurationTask.HeightFromBaseAndTopAsync(fromGeometry as MapPoint, toGeometry as MapPoint, p9); break; case MensurationOperation.HeightFromBaseAndTopShadow: MensurationHeightParameter p10 = new MensurationHeightParameter(); p10.LinearUnit = LinearUnit; mensurationTask.HeightFromBaseAndTopShadowAsync(fromGeometry as MapPoint, toGeometry as MapPoint, p10); break; case MensurationOperation.HeightFromTopAndTopShadow: MensurationHeightParameter p11 = new MensurationHeightParameter(); p11.LinearUnit = LinearUnit; mensurationTask.HeightFromTopAndTopShadowAsync(fromGeometry as MapPoint, toGeometry as MapPoint, p11); break; } } }
private async void OnMeasureCommand(object param) { if (_editState == EditState.None && _mapView != null && !_mapView.Editor.IsActive) { _lineSymbol = new SimpleLineSymbol() { Color = Colors.Red, Style = SimpleLineStyle.Solid, Width = 2 } as Symbol; _graphicsOverlay = _mapView.GraphicsOverlays["graphicsOverlay"]; // World Topo Map doesn't support mensuration //var temp = _mapView.Map.Layers["World Topo Map"]; var temp = _mapView.Map.Layers["MensurationMapServiceLayer"]; _mensurationTask = new MensurationTask(new Uri((temp as ArcGISTiledMapServiceLayer).ServiceUri)); // lets do a basic distance measure try { var line = await RequestUserShape(DrawShape.LineSegment, _lineSymbol) as Polyline; // Requesting shape cancelled if (line == null) return; var parameters = new MensurationLengthParameters() { AngularUnit = AngularUnits.Degrees, LinearUnit = LinearUnits.Meters }; var result = await _mensurationTask.DistanceAndAngleAsync( line.Parts.First().StartPoint, line.Parts.First().EndPoint, parameters); if (result.Distance != null) { ShowResults(result, "Measure results"); } else { MessageBox.Show("Error", "Mensuration Error"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Mensuration Error"); } finally { _graphicsOverlay.Graphics.Clear(); } } }