ArcGIS_Runtime_SDK for.Net 鼠标移动获取坐标前端代码
时间: 2024-05-11 12:18:07 浏览: 217
以下是使用 ArcGIS Runtime SDK for .Net 获取鼠标移动坐标的前端代码示例:
```csharp
private void MyMapView_MouseMove(object sender, MouseEventArgs e)
{
// 获取鼠标所在的屏幕坐标
System.Windows.Point screenPoint = e.GetPosition(MyMapView);
// 将屏幕坐标转换为地图坐标
MapPoint mapPoint = MyMapView.ScreenToLocation(screenPoint);
// 显示地图坐标信息
txtMapPoint.Text = string.Format("X:{0:F4} Y:{1:F4}", mapPoint.X, mapPoint.Y);
}
```
上述代码中,`MyMapView` 是 ArcGIS Runtime SDK for .Net 中的地图控件,当鼠标移动时,会触发 `MyMapView_MouseMove` 事件。在该事件中,首先获取鼠标所在的屏幕坐标,然后将屏幕坐标转换为地图坐标,最后将地图坐标信息显示在界面上。
相关问题
ArcGIS_Runtime_SDK for.Net 鼠标移动获取坐标MainPage代码
以下是使用 ArcGIS_Runtime_SDK for .Net 的 MainPage 代码,其中包括鼠标移动获取坐标的功能:
```csharp
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.UI;
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace MapApp
{
public sealed partial class MainPage : Page
{
private MapView _mapView;
public MainPage()
{
this.InitializeComponent();
Initialize();
}
private async void Initialize()
{
// Create a new Map with the basemap of your choice
Map myMap = new Map(Basemap.CreateImageryWithLabels());
// Set the initial viewpoint
Envelope initialLocation = new Envelope(
-123.085428, 49.199165, -122.883469, 49.326968,
SpatialReferences.Wgs84);
myMap.InitialViewpoint = new Viewpoint(initialLocation);
// Create the MapView control
_mapView = new MapView
{
Map = myMap
};
// Add the MapView to the page
MyMapView.Content = _mapView;
// Listen for mouse movement events
_mapView.MouseMove += MapView_MouseMove;
}
private async void MapView_MouseMove(object sender, Esri.ArcGISRuntime.UI.Controls.MapViewInputEventArgs e)
{
// Get the coordinates of the mouse pointer
MapPoint geoPoint = (MapPoint)GeometryEngine.Project(e.Location, SpatialReferences.Wgs84);
// Display the coordinates in a TextBlock
CoordinatesTextBlock.Text = $"Latitude: {geoPoint.Y:F4}, Longitude: {geoPoint.X:F4}";
}
}
}
```
在此代码中,我们首先创建了一个 MapView 控件,并将其添加到页面中。然后,我们启用了鼠标移动事件处理程序 MapView_MouseMove。在该事件处理程序中,我们使用 GeometryEngine.Project 方法将屏幕坐标转换为地理坐标,并将其显示在 TextBlock 中。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![vsix](https://img-home.csdnimg.cn/images/20250102104920.png)
![vsix](https://img-home.csdnimg.cn/images/20250102104920.png)