ArcGIS_Runtime_SDK for.Net 鼠标移动获取坐标前端代码
时间: 2024-05-11 17:18:07 浏览: 23
以下是使用 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 中。
arcgis runtime sdk for.net中图查功能的实现的代码
ArcGIS Runtime SDK for .NET 中实现图查功能的代码可以参考以下示例代码:
1. 创建 MapView 和 GraphicsOverlay:
```csharp
// 创建 Map
Map myMap = new Map(Basemap.CreateImagery());
// 创建 MapView
MapView myMapView = new MapView();
myMapView.Map = myMap;
// 创建 GraphicsOverlay
GraphicsOverlay myGraphicsOverlay = new GraphicsOverlay();
myMapView.GraphicsOverlays.Add(myGraphicsOverlay);
```
2. 实现图查功能:
```csharp
// 创建图查工具
IdentifyGraphicsOverlay myIdentifyGraphicsOverlay = new IdentifyGraphicsOverlay(myGraphicsOverlay);
// 监听 MapView 的 Tap 事件
myMapView.GeoViewTapped += async (sender, args) =>
{
try
{
// 清空图查结果
myIdentifyGraphicsOverlay.Graphics.Clear();
// 执行图查操作
IReadOnlyList<IdentifyGraphicsOverlayResult> results = await myMapView.IdentifyGraphicsOverlaysAsync(args.Position, 10, false, 10);
// 遍历图查结果
foreach (IdentifyGraphicsOverlayResult result in results)
{
// 获取图形
Graphic graphic = result.Graphics.FirstOrDefault();
// 添加到图查结果中
if (graphic != null)
{
myIdentifyGraphicsOverlay.Graphics.Add(graphic);
}
}
}
catch (Exception ex)
{
// 处理异常
}
};
```
3. 将图查结果渲染到 MapView 上:
```csharp
// 创建渲染器
SimpleRenderer myRenderer = new SimpleRenderer();
myRenderer.Symbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Colors.Yellow, null);
// 将渲染器应用到 GraphicsOverlay
myGraphicsOverlay.Renderer = myRenderer;
// 将图查结果添加到 GraphicsOverlay
myGraphicsOverlay.Graphics.AddRange(myIdentifyGraphicsOverlay.Graphics);
```
以上是一个简单的图查功能的实现示例,具体实现方式可以根据需求进行调整。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![exe](https://img-home.csdnimg.cn/images/20210720083343.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)