-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapToolStreetView.cs
87 lines (75 loc) · 2.9 KB
/
MapToolStreetView.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
namespace PAMStreetView
{
using System.Collections.Generic;
using System.Threading.Tasks;
using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Framework;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;
/// <summary>
/// MapTool StreetView
/// </summary>
internal class MapToolStreetView : MapTool
{
private DStreetViewViewModel pane = FrameworkApplication.DockPaneManager.Find("PAMStreetView_DStreetView") as DStreetViewViewModel;
/// <summary>
/// event OnToolMouseDown
/// </summary>
/// <param name="e">MapView MouseButton EventArgs</param>
protected override void OnToolMouseDown(MapViewMouseButtonEventArgs e)
{
if (e.ChangedButton == System.Windows.Input.MouseButton.Left)
{
// Handle the event args to get the call to the corresponding async method
e.Handled = true;
}
}
/// <summary>
/// Handle MouseDown Async
/// </summary>
/// <param name="e">MapView MouseButton EventArgs</param>
/// <returns>object task</returns>
protected override Task HandleMouseDownAsync(MapViewMouseButtonEventArgs e)
{
return QueuedTask.Run(async() =>
{
try
{
// Convert the clicked point in client coordinates to the corresponding map coordinates.
var mapPoint = MapView.Active.ClientToMap(e.ClientPoint);
SpatialReference sr = MapView.Active.Map.SpatialReference;
if (!sr.IsEqual(SpatialReferences.WGS84))
{
mapPoint = await Project(mapPoint, sr);
}
pane.currentX = mapPoint.X;
pane.currentY = mapPoint.Y;
pane.WebBrowserUpdate();
}
catch
{
}
});
}
private Task<MapPoint> Project(MapPoint p, SpatialReference sr)
{
return QueuedTask.Run(() =>
{
SpatialReference srInput = SpatialReferenceBuilder.CreateSpatialReference(sr.LatestWkid);
ProjectionTransformation projTransFromSRs = ProjectionTransformation.Create(srInput, SpatialReferences.WGS84);
MapPoint projectedEnvEx = GeometryEngine.Instance.ProjectEx(p, projTransFromSRs) as MapPoint;
return projectedEnvEx;
});
}
private class Geometries
{
public List<Point> geometries =null;
public object error = null;
}
private class Point
{
public double x = double.NaN;
public double y = double.NaN;
}
}
}