From a7b979347c48a995732748cfdef216aa9eb9a49f Mon Sep 17 00:00:00 2001 From: PeterZhong Date: Mon, 14 Oct 2024 12:18:24 +0800 Subject: [PATCH] 3.10 Add coordinate dislay --- GisDevelop_Exp/App.xaml.cs | 2 +- GisDevelop_Exp/MainWindow.xaml | 7 +++++- GisDevelop_Exp/MainWindow.xaml.cs | 39 +++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/GisDevelop_Exp/App.xaml.cs b/GisDevelop_Exp/App.xaml.cs index 94a747b..a062275 100644 --- a/GisDevelop_Exp/App.xaml.cs +++ b/GisDevelop_Exp/App.xaml.cs @@ -38,7 +38,7 @@ namespace GisDevelop_Exp // Initialize the ArcGIS Maps SDK runtime before any components are created. ArcGISRuntimeEnvironment.Initialize(config => config // .UseLicense("[Your ArcGIS Maps SDK license string]") - .UseApiKey("AAPTxy8BH1VEsoebNVZXo8HurGPYSDOnAeIwA4pOmn4FxReGCVGizofL_NQAK3uvzuar2NmXR05j3u3x4g02LDdUvuS2vHqxHTPyUTYWgjjqXXiEBKefOwcK-XJXp68tFHTc0f6JAgnPMVNzfluXceV0TzpdU9OfkGsrTPtIAIwBB_jw0BKZT_c6Qa2RCP5J7gZSlOuuebJ4oo488So-4Lh0WrIObQPjmc5wsc7MxoWn6rg.AT1_A4CN5Ivr") + .UseApiKey("AAPTxy8BH1VEsoebNVZXo8HurGPYSDOnAeIwA4pOmn4FxRfMsbp3zN7aIhAzuRolPS6JUAtf98pdWdQp1jjclJhIB-7QXbTXrBITqXti07DnOLsRnS9lGLYGImGh5vW_jSlnEBqxbbZQCs4S0y5-tHC0_kSFW9RD3Kv8hiDGt1IGSrs-96vwz6rycPenwu_cAwZHZyTahSAEHOR5A7j2y9sUsZ8HoYLcn2O9SI8OYw2tzr4xAAwqN1fcw6FMiVVpBSYWAT1_A4CN5Ivr") .ConfigureAuthentication(auth => auth .UseDefaultChallengeHandler() // Use the default authentication dialog // .UseOAuthAuthorizeHandler(myOauthAuthorizationHandler) // Configure a custom OAuth dialog diff --git a/GisDevelop_Exp/MainWindow.xaml b/GisDevelop_Exp/MainWindow.xaml index c80dab4..21547a6 100644 --- a/GisDevelop_Exp/MainWindow.xaml +++ b/GisDevelop_Exp/MainWindow.xaml @@ -25,7 +25,7 @@ - + @@ -38,6 +38,11 @@ + diff --git a/GisDevelop_Exp/MainWindow.xaml.cs b/GisDevelop_Exp/MainWindow.xaml.cs index 4f7b553..10fb498 100644 --- a/GisDevelop_Exp/MainWindow.xaml.cs +++ b/GisDevelop_Exp/MainWindow.xaml.cs @@ -15,9 +15,13 @@ using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Esri.ArcGISRuntime.Geometry; +using Esri.ArcGISRuntime.Portal; +using Esri.ArcGISRuntime.Security; using Esri.ArcGISRuntime.Symbology; using Esri.ArcGISRuntime.UI; +using Esri.ArcGISRuntime.UI.Controls; using Color = System.Drawing.Color; +using Geometry = Esri.ArcGISRuntime.Geometry.Geometry; using Polygon = Esri.ArcGISRuntime.Geometry.Polygon; namespace GisDevelop_Exp @@ -59,6 +63,14 @@ namespace GisDevelop_Exp MainMapView.Map = new Map(_basemapOptions.Values.First()); BasemapChooser.ItemsSource = _basemapOptions.Keys; BasemapChooser.SelectedIndex = 0; + string token = + "AAPTxy8BH1VEsoebNVZXo8HurGPYSDOnAeIwA4pOmn4FxRfMsbp3zN7aIhAzuRolPS6JUAtf98pdWdQp1jjclJhIB-7QXbTXrBITqXti07DnOLsRnS9lGLYGImGh5vW_jSlnEBqxbbZQCs4S0y5-tHC0_kSFW9RD3Kv8hiDGt1IGSrs-96vwz6rycPenwu_cAwZHZyTahSAEHOR5A7j2y9sUsZ8HoYLcn2O9SI8OYw2tzr4xAAwqN1fcw6FMiVVpBSYWAT1_A4CN5Ivr"; + InitializeAuthenticationManagerWithToken(token); + } + + private void InitializeAuthenticationManagerWithToken(string token) + { + AuthenticationManager.Current.AddCredential(new OAuthTokenCredential(new Uri("https://services3.arcgis.com/Po7vxnPH4Do7ht5I/arcgis/rest/services/test/MapServer"),token)); } private void Menu_OpenShp_Click(object sender, RoutedEventArgs e) @@ -252,5 +264,32 @@ namespace GisDevelop_Exp Application.Current.Shutdown(); } } + + private void Btn_Add_Online_OnClick(object sender, RoutedEventArgs e) + { + AddPrivateOnlineMap(); + } + + private async void AddPrivateOnlineMap() + { + Map map = new Map(BasemapStyle.ArcGISTopographic); + // Create an ArcGIS Portal object. + ArcGISPortal portal = await ArcGISPortal.CreateAsync(); + // Create a portal item from the ArcGIS Portal object using a portal item string. + PortalItem portalItem = await PortalItem.CreateAsync(portal, "29d7c59212ef479995f5b42bacc9de4c"); + FeatureLayer featureLayer = new FeatureLayer(portalItem,0); + map.OperationalLayers.Add(featureLayer); + MainMapView.Map = map; + } + + private void MainMapView_OnGeoViewTapped(object? sender, GeoViewInputEventArgs e) + { + MapPoint mapLocation = e.Location; + Geometry myGeometry = mapLocation.Project(SpatialReferences.Wgs84); + MapPoint projectedLocation = (MapPoint)myGeometry; + string mapLocationDescription = string.Format("纬度: {0:F3} 经度:{1:F3}", projectedLocation.Y, projectedLocation.X); + CalloutDefinition myCalloutDefinition = new CalloutDefinition("当前位置:", mapLocationDescription); + MainMapView.ShowCalloutAt(mapLocation, myCalloutDefinition); + } } }