<esri:Map x:Name="_map" UseAcceleratedDisplay="True"> <esri:Map.ContextMenu> <ContextMenu x:Name="_contextMenu" Closed="_contextMenu_Closed"> <ContextMenu.ItemsSource> <CompositeCollection> <MenuItem Header="Some general fuctionality" Click="MenuItem_Click_1" /> <MenuItem Header="Show geometry (if had graphic)" Click="MenuItem_Click" IsEnabled="False"/> </CompositeCollection> </ContextMenu.ItemsSource> </ContextMenu> </esri:Map.ContextMenu> <esri:ArcGISLocalDynamicMapServiceLayer ID="USA" Path="C:\Program Files (x86)\ArcGIS SDKs\WPF10.2.2\sdk\samples\data\MPKs\USCitiesStates.mpk"/> <esri:GraphicsLayer ID="Example Graphic" MouseRightButtonUp="GraphicsLayer_MouseRightButtonUp"> <esri:Graphic x:Name="testGraphic"> <esri:Graphic.Symbol> <esri:SimpleMarkerSymbol Style="Circle" Color="Red"/> </esri:Graphic.Symbol> <esri:Graphic.Geometry> <esri:MapPoint X="0" Y="0" > <esri:MapPoint.SpatialReference> <esri:SpatialReference WKID="102100"/> </esri:MapPoint.SpatialReference> </esri:MapPoint> </esri:Graphic.Geometry> </esri:Graphic> </esri:GraphicsLayer> </esri:Map>
using System.Windows; using ESRI.ArcGIS.Client; using System.Windows.Controls; using System.Linq; namespace ArcGISWpfApplication1 { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } Graphic _graphic; private void GraphicsLayer_MouseRightButtonUp(object sender, GraphicMouseButtonEventArgs e) { (_contextMenu.Items[1] as MenuItem).IsEnabled = e.Graphic != null ? true : false; if (e.Graphic == null) { return; } var layer = _map.Layers.OfType<GraphicsLayer>().First(); _graphic = e.Graphic; } private void MenuItem_Click(object sender, RoutedEventArgs e) { MessageBox.Show(_graphic.Geometry.ToJson()); _graphic = null; (_contextMenu.Items[1] as MenuItem).IsEnabled = false; } private void MenuItem_Click_1(object sender, RoutedEventArgs e) { MessageBox.Show("Note that points in USA are not graphics, they are rendered in image on dynamic layer. There is red dot on 0,0 - click that"); } private void _contextMenu_Closed(object sender, RoutedEventArgs e) { _graphic = null; (_contextMenu.Items[1] as MenuItem).IsEnabled = false; } } }
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.