<esri:Map x:Name="MyMap" Extent="-16574645.619,-5541958.774,13341035.686,10559275.713" Loaded="MyMap_Loaded" esri:Editor.SnapDistance="30" MouseClick="MyMap_MouseClick" MouseMove="MyMap_MouseMove" MouseLeftButtonUp="MyMap_MouseLeftButtonUp" MouseRightButtonDown="MyMap_OnMouseRightButtonDown">
private void MyMap_OnMouseRightButtonDown(object sender, MouseButtonEventArgs e) { PointCollection pointCollection = new PointCollection { new MapPoint(0, 0), MyMap.ScreenToMap(e.GetPosition(MyMap)) }; Polyline polyline = new Polyline(); polyline.Paths.Add(pointCollection); Graphic graphic = new Graphic { Symbol = LayoutRoot.Resources["MyScaleBox"] as ESRI.ArcGIS.Client.Symbols.Symbol, Geometry = polyline }; ((GraphicsLayer)MyMap.Layers["MyGraphicsLayer"]).Graphics.Add(graphic); ((GraphicsLayer)MyMap.Layers["MyGraphicsLayer"]).Refresh(); }
<Grid x:Name="LayoutRoot" Background="White"> <Grid.Resources> <esri:SimpleFillSymbol x:Key="RedFillSymbol" Fill="#66FF0000" BorderBrush="Red" BorderThickness="2" /> </Grid.Resources> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition/> </Grid.ColumnDefinitions> <esri:Map x:Name="MyMap" WrapAround="True" Background="White"> <esri:ArcGISTiledMapServiceLayer ID="PhysicalTiledLayer" Url="http://services.arcgisonline.com/ArcGIS/rest/services/NGS_Topo_US_2D/MapServer"/> <esri:GraphicsLayer ID="MyLayer" MouseLeftButtonDown="GraphicsLayer_MouseLeftButtonDown" Initialized="GraphicsLayer_Initialized"> <esri:GraphicsLayer.Graphics> <esri:Graphic Symbol="{StaticResource RedFillSymbol}"> <esri:Polygon > <esri:Polygon.Rings> <esri:PointCollection> <esri:MapPoint X="110.039" Y="-20.303" /> <esri:MapPoint X="132.539" Y="-7.0137" /> <esri:MapPoint X="153.281" Y="-13.923" /> <esri:MapPoint X="162.773" Y="-35.174" /> <esri:MapPoint X="133.594" Y="-43.180" /> <esri:MapPoint X="111.797" Y="-36.032" /> <esri:MapPoint X="110.039" Y="-20.303" /> </esri:PointCollection> </esri:Polygon.Rings> </esri:Polygon> </esri:Graphic> </esri:GraphicsLayer.Graphics> </esri:GraphicsLayer> </esri:Map> <esri:Map x:Name="MirroredMap" Grid.Column="1" /> </Grid>
EditGeometry editGeometry; public MainPage() { InitializeComponent(); editGeometry = new EditGeometry(MyMap); editGeometry.IsEnabled = true; MyMap.ExtentChanged += (s, e) => { MirroredMap.Extent = MyMap.Extent; }; MyMap.Layers.LayersInitialized += (s, e) => { foreach (var l in MyMap.Layers) { if (l is ArcGISTiledMapServiceLayer) { MirroredMap.Layers.Add(new ArcGISTiledMapServiceLayer() { ID = l.ID, Url = (l as ArcGISTiledMapServiceLayer).Url }); } else if (l is GraphicsLayer) { var graphicsLayer = new GraphicsLayer() { ID = l.ID }; if ((l as GraphicsLayer).Graphics != null) { foreach (var g in (l as GraphicsLayer).Graphics) { g.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(g_PropertyChanged); var clonedGraphic = new Graphic() { Geometry = Geometry.Clone(g.Geometry), Symbol = g.Symbol }; foreach (var item in g.Attributes) clonedGraphic.Attributes[item.Key] = item.Value; graphicsLayer.Graphics.Add(clonedGraphic); } } MirroredMap.Layers.Add(graphicsLayer); } } }; } void g_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == "Geometry") { var graphic = sender as Graphic; var layer = MirroredMap.Layers["MyLayer"] as GraphicsLayer; var clonedGraphic = layer.Graphics.FirstOrDefault(g => (int) g.Attributes["ObjectID"] == (int) graphic.Attributes["ObjectID"]); clonedGraphic.Geometry = Geometry.Clone(graphic.Geometry); } } private void GraphicsLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs e) { editGeometry.StartEdit(e.Graphic); } private void GraphicsLayer_Initialized(object sender, EventArgs e) { var l = sender as GraphicsLayer; int i = 0; foreach (var g in l.Graphics) { g.Attributes["ObjectID"] = ++i; } }
if (e.Action == EditGeometry.Action.VextedMoved || e.Action == EditGeometry.Action.VertexAdded) { editGeometry.StopEdit(); editGeometry.StartEdit(editGraphic); } else if(e.Action == EditGeometry.Action.EditCompleted) layer.Refresh();
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.