drawObject = new Draw(MapApplication.Current.Map) { DrawMode = DrawMode.Point, IsEnabled = true, }; drawObject.DrawComplete += DrawObject_DrawComplete;
private void DrawObject_DrawComplete(object sender, DrawEventArgs args) { MapPoint point = args.Geometry as MapPoint; point.SpatialReference = MapApplication.Current.Map.SpatialReference; Graphic graphic = new Graphic() { Geometry = point, }; GraphicsLayer graphicsLayer = MapApplication.Current.Map.Layers["IdentifyResultsLayer"] as GraphicsLayer; if (graphicsLayer == null) { graphicsLayer = createResultsLayer(); MapApplication.Current.Map.Layers.Add(graphicsLayer); } else { graphicsLayer.ClearGraphics(); } //test attributes graphic.Attributes.Add("ObstacleClearanceSurfaceHeight", 100); graphic.Attributes.Add("GroundElevation", 150); graphic.Attributes.Add("Difference", 333); graphicsLayer.Graphics.Add(graphic); MapApplication.Current.ShowPopup(graphic, graphicsLayer); }
Hi Ryan:
I believe the trick here is to add a graphic containing attributes to the GraphicsLayer before adding the layer to the map. Since the API does not define a way to specify a GraphicsLayer's schema, the Viewer relies on the first graphic in a layer at the time the layer is added to the map to determine this.
private void DrawObject_DrawComplete(object sender, DrawEventArgs args) { MapPoint point = args.Geometry as MapPoint; point.SpatialReference = MapApplication.Current.Map.SpatialReference; Graphic graphic = new Graphic() { Geometry = point, }; //test attributes graphic.Attributes.Add("ObstacleClearanceSurfaceHeight", 100); graphic.Attributes.Add("GroundElevation", 150); graphic.Attributes.Add("Difference", 333); GraphicsLayer graphicsLayer = CreateResultsLayer(); graphicsLayer.Graphics.Add(graphic); MapApplication.Current.Map.Layers.Add(graphicsLayer); MapApplication.Current.ShowPopup(graphic, graphicsLayer); }
private GraphicsLayer createResultsLayer() { GraphicsLayer gl = new GraphicsLayer() { ID = "GraphicsLayer", Renderer = new SimpleRenderer() { Symbol = configDialog.Resources["RedMarkerSymbol"] as Symbol } }; // Set layer name in Map Contents gl.SetValue(MapApplication.LayerNameProperty, "Graphics Results"); return gl; }
<UserControl x:Class="ViewerApplication7.AddIns.MyConfigDialog" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:esri="http://schemas.esri.com/arcgis/client/2009" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <UserControl.Resources> <ResourceDictionary> <esri:SimpleMarkerSymbol x:Key="RedMarkerSymbol" Color="Red" Size="12" Style="Circle" /> </ResourceDictionary> </UserControl.Resources> <Grid x:Name="LayoutRoot" Background="Transparent"> <StackPanel Margin="10" Background="Transparent"></StackPanel> </Grid> </UserControl>[ATTACH=CONFIG]11824[/ATTACH]