3.10 Add coordinate dislay

This commit is contained in:
PeterZhong 2024-10-14 12:18:24 +08:00
parent e1e8fdcff4
commit a7b979347c
3 changed files with 46 additions and 2 deletions

View File

@ -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

View File

@ -25,7 +25,7 @@
<MenuItem x:Name="Menu_Wrap_Around" Header="开启漫游" Click="Menu_Wrap_Around_OnClick"></MenuItem>
</MenuItem>
</Menu>
<esri:MapView x:Name="MainMapView" Map="{Binding Map, Source={StaticResource MapViewModel}}" Margin="0,19,0,0" ViewpointChanged="MainMapView_OnViewpointChanged"/>
<esri:MapView x:Name="MainMapView" Map="{Binding Map, Source={StaticResource MapViewModel}}" Margin="0,19,0,0" ViewpointChanged="MainMapView_OnViewpointChanged" GeoViewTapped="MainMapView_OnGeoViewTapped"/>
<Border BorderBrush="#FF8B1D76" BorderThickness="2,2,2,2" HorizontalAlignment="Right" Height="180" Width="202" VerticalAlignment="Top" IsEnabled="False">
<esri:MapView x:Name="EagleMapView"/>
</Border>
@ -38,6 +38,11 @@
<ImageBrush ImageSource="D:\01_Development\10_Visual_Studio_Project\GisDevelop\GisDevelop_Exp\GisDevelop_Exp\add.png"/>
</Button.Background>
</Button>
<Button x:Name="Btn_Add_Online" Height="32" Width="32" Click="Btn_Add_Online_OnClick">
<Button.Background>
<ImageBrush ImageSource="D:\01_Development\10_Visual_Studio_Project\GisDevelop\GisDevelop_Exp\GisDevelop_Exp\online.png"/>
</Button.Background>
</Button>
</ToolBar>
</Grid>
</Window>

View File

@ -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);
}
}
}