private async void MyTemplatePicker_TemplatePicked(object sender, Esri.ArcGISRuntime.Toolkit.Controls.TemplatePicker.TemplatePickedEventArgs e) { try { TemplateName.Text = e.FeatureTemplate.Name; TargetedLayer.Text = e.Layer.DisplayName; TemplateDescription.Text = e.FeatureTemplate.Description; GeometryType geometryType = GeometryType.Unknown; var gdbFeatureTable = e.Layer.FeatureTable as ServiceFeatureTable; if (gdbFeatureTable != null && gdbFeatureTable.ServiceInfo != null) { geometryType = gdbFeatureTable.ServiceInfo.GeometryType; } Esri.ArcGISRuntime.Symbology.Symbol symbol = null; // Get symbol from the renderer if that is defined if (e.Layer.Renderer != null) { var g = new Graphic(e.FeatureTemplate.Prototype.Attributes ?? Enumerable.Empty <KeyValuePair <string, object> >()); symbol = e.Layer.Renderer.GetSymbol(g); SelectedSymbol.Source = await symbol.CreateSwatchAsync(32, 32, 96, Colors.Transparent, geometryType); } // Define what we shape we request from the editor DrawShape requestedShape = DrawShape.Point; if (e.FeatureTemplate.DrawingTool == FeatureEditTool.Polygon) { requestedShape = DrawShape.Polygon; } if (e.FeatureTemplate.DrawingTool == FeatureEditTool.Line) { requestedShape = DrawShape.Polyline; } Selection.Visibility = Visibility.Collapsed; SelectedInfo.Visibility = Visibility.Visible; // Request location for the new feature var addedGeometry = await MyMapView.Editor.RequestShapeAsync(requestedShape, symbol); // Add new feature to the MapView. Note that this doesn't commit changes automatically to the service var id = await gdbFeatureTable.AddAsync(e.FeatureTemplate.Prototype.Attributes, addedGeometry); } catch (TaskCanceledException) { } // Editing canceled catch (Exception exception) { var _x = new MessageDialog(string.Format("Error occured : {0}", exception.ToString()), "Sample error").ShowAsync(); } Selection.Visibility = Visibility.Visible; SelectedInfo.Visibility = Visibility.Collapsed; }
// Draw and add a single graphic to the graphic layer private async Task AddSingleGraphicAsync() { try { var drawShape = (DrawShape)comboDrawShape.SelectedValue; Esri.ArcGISRuntime.Symbology.Symbol symbol = null; switch (drawShape) { case DrawShape.Point: symbol = Resources["BluePointSymbol"] as Esri.ArcGISRuntime.Symbology.Symbol; break; case DrawShape.LineSegment: case DrawShape.Freehand: case DrawShape.Polyline: symbol = Resources["GreenLineSymbol"] as Esri.ArcGISRuntime.Symbology.Symbol; break; case DrawShape.Arrow: case DrawShape.Circle: case DrawShape.Ellipse: case DrawShape.Polygon: case DrawShape.Rectangle: case DrawShape.Triangle: case DrawShape.Envelope: symbol = Resources["RedFillSymbol"] as Esri.ArcGISRuntime.Symbology.Symbol; break; } // wait for user to draw the shape var geometry = await MyMapView.Editor.RequestShapeAsync(drawShape, symbol); // add the new graphic to the graphic layer var graphic = new Graphic(geometry, symbol); _graphicsLayer.Graphics.Add(graphic); } catch (TaskCanceledException) { // Ignore cancelations from selecting new shape type } catch (Exception ex) { var _x = new MessageDialog("Error drawing graphic: " + ex.Message, "Add Graphic Interactively").ShowAsync(); } }