// Accepts two user shapes and adds them to the graphics layer private async Task AcceptShapeAsync() { // Shape One Geometry shapeOne = await mapView.Editor.RequestShapeAsync( (DrawShape)comboShapeOne.SelectedValue, _symbols[comboShapeOne.SelectedIndex]); _graphicsLayer.Graphics.Add(new Graphic(shapeOne, _symbols[comboShapeOne.SelectedIndex])); // Shape Two Geometry shapeTwo = await mapView.Editor.RequestShapeAsync( (DrawShape)comboShapeTwo.SelectedValue, _symbols[comboShapeTwo.SelectedIndex]); _graphicsLayer.Graphics.Add(new Graphic(shapeTwo, _symbols[comboShapeTwo.SelectedIndex])); var relations = new List <Tuple <string, bool> >(); relations.Add(new Tuple <string, bool>("Contains", GeometryEngine.Contains(shapeOne, shapeTwo))); relations.Add(new Tuple <string, bool>("Crosses", GeometryEngine.Crosses(shapeOne, shapeTwo))); relations.Add(new Tuple <string, bool>("Disjoint", GeometryEngine.Disjoint(shapeOne, shapeTwo))); relations.Add(new Tuple <string, bool>("Equals", GeometryEngine.Equals(shapeOne, shapeTwo))); relations.Add(new Tuple <string, bool>("Intersects", GeometryEngine.Intersects(shapeOne, shapeTwo))); relations.Add(new Tuple <string, bool>("Overlaps", GeometryEngine.Overlaps(shapeOne, shapeTwo))); relations.Add(new Tuple <string, bool>("Touches", GeometryEngine.Touches(shapeOne, shapeTwo))); relations.Add(new Tuple <string, bool>("Within", GeometryEngine.Within(shapeOne, shapeTwo))); resultsListView.ItemsSource = relations; resultsPanel.Visibility = Visibility.Visible; }
// Accepts two user shapes and adds them to the graphics layer private async Task AcceptShapeAsync() { // Shape One DrawShape drawShape1 = (DrawShape)comboShapeOne.SelectedItem; Geometry shapeOne = null; if (drawShape1 == DrawShape.Point) { shapeOne = await mapView.Editor.RequestPointAsync(); } else { shapeOne = await mapView.Editor.RequestShapeAsync(drawShape1, _symbols[comboShapeOne.SelectedIndex]); } graphicsLayer.Graphics.Add(new Graphic(shapeOne, _symbols[comboShapeOne.SelectedIndex])); // Shape Two Geometry shapeTwo = await mapView.Editor.RequestShapeAsync( (DrawShape)comboShapeTwo.SelectedItem, _symbols[comboShapeTwo.SelectedIndex]); graphicsLayer.Graphics.Add(new Graphic(shapeTwo, _symbols[comboShapeTwo.SelectedIndex])); Dictionary <string, bool> relations = new Dictionary <string, bool>(); relations["Contains"] = GeometryEngine.Contains(shapeOne, shapeTwo); relations["Crosses"] = GeometryEngine.Crosses(shapeOne, shapeTwo); relations["Disjoint"] = GeometryEngine.Disjoint(shapeOne, shapeTwo); relations["Equals"] = GeometryEngine.Equals(shapeOne, shapeTwo); relations["Intersects"] = GeometryEngine.Intersects(shapeOne, shapeTwo); relations["Overlaps"] = GeometryEngine.Overlaps(shapeOne, shapeTwo); relations["Touches"] = GeometryEngine.Touches(shapeOne, shapeTwo); relations["Within"] = GeometryEngine.Within(shapeOne, shapeTwo); resultsPanel.Visibility = Visibility.Visible; resultsListView.ItemsSource = relations; }
/// <summary> /// Edit existing <see cref="Polyline"/>. This will activate editing experience on the map. Edit is completed on double click. /// </summary> /// <param name="sceneView">The <see cref="SceneView"/> that is used for editing.</param> /// <exception cref="TaskCanceledException">If previous task wasn't completed, <see cref="TaskCanceledException"/> /// will be thrown. The task is cancelled if <see cref="Cancel"/> method or if any other draw or edit method is called. /// </exception> /// <returns>Return edited <see cref="Polygon"/> based on the user interactions.</returns> public static async Task <Polyline> EditPolylineAsync(SceneView sceneView, Polyline polyline) { Initialize(); var tcs = new TaskCompletionSource <Polyline>(); PolylineBuilder polylineBuilder = new PolylineBuilder(sceneView.SpatialReference); var sketchlayer = CreateSketchLayer(sceneView); var vertexlayer = CreateSketchLayer(sceneView); // Create vertices from the original polyline var vertices = new List <Graphic>(); foreach (var vertex in (polyline.Parts[0].GetPoints())) { vertices.Add(new Graphic(vertex, DefaultVertexSymbol)); } // Default to original polyline var newPolyline = new Polyline(polyline.Parts); Graphic lineGraphic = new Graphic(newPolyline) { Symbol = DefaultLineSymbol }; Graphic lineMoveGraphic = new Graphic() { Symbol = DefaultLineMoveSymbol }; sketchlayer.Graphics.AddRange(new Graphic[] { lineGraphic, lineMoveGraphic }); vertexlayer.Graphics.AddRange(vertices); CancellationTokenSource tokenSource = null; Graphic selectedVertex = null; bool isEditingVertex = false; Action cleanupEvents = SetUpHandlers(sceneView, (p) => //On mouse move, move completion line around { if (p != null && isEditingVertex) { // Update visual indicator polyline var vertexPoints = newPolyline.Parts[0].GetPoints().ToList(); var index = vertexPoints .IndexOf(vertexPoints.Where (point => GeometryEngine.Equals(point, selectedVertex.Geometry)).First()); var temporaryVertices = new List <MapPoint>(); if (index > 0) { temporaryVertices.Add(vertexPoints[index - 1]); // Add previous segment } temporaryVertices.Add(p); if (index != vertexPoints.Count() - 1) { temporaryVertices.Add(vertexPoints[index + 1]); // Add next segment } var builder = new PolylineBuilder(temporaryVertices); lineMoveGraphic.Geometry = builder.ToGeometry(); lineMoveGraphic.IsVisible = true; } }, async(p) => //On tap add a vertex { if (p == null) { return; } if (isEditingVertex) { return; } if (selectedVertex != null) { selectedVertex.IsSelected = false; } selectedVertex = await vertexlayer.HitTestAsync(sceneView, sceneView.LocationToScreen(p)); // No vertex found so return if (selectedVertex == null) { return; } isEditingVertex = true; selectedVertex.IsSelected = true; tokenSource = new CancellationTokenSource(); try { var newPoint = await SceneDrawHelper.DrawPointAsync(sceneView, tokenSource.Token); if (newPoint == null) { return; } var vertexPoints = newPolyline.Parts[0].GetPoints(); var index = vertexPoints.ToList() .IndexOf(vertexPoints.Where (point => GeometryEngine.Equals(point, selectedVertex.Geometry)).First()); var builder = new PolylineBuilder(vertexPoints); builder.Parts[0].MovePoint(index, newPoint); lineGraphic.Geometry = null; // Update polyline newPolyline = builder.ToGeometry(); lineGraphic.Geometry = newPolyline; // Update vertex selectedVertex.Geometry = newPoint; tokenSource = null; } catch (TaskCanceledException tce) { } finally { lineMoveGraphic.IsVisible = false; selectedVertex.IsSelected = false; selectedVertex = null; isEditingVertex = false; } }, (p) => // Double tapped - completes task and returns new polyline { tcs.SetResult(newPolyline); }); Action cleanup = () => { cleanupEvents(); sceneView.GraphicsOverlays.Remove(sketchlayer); sceneView.GraphicsOverlays.Remove(vertexlayer); if (tokenSource != null) { tokenSource.Cancel(); } Cleanup(); }; _drawTaskTokenSource.Token.Register(() => tcs.SetCanceled()); Polyline result = null; try { result = await tcs.Task; } finally { cleanup(); } return(result); }