-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathOverviewMap.cs
244 lines (219 loc) · 9.45 KB
/
OverviewMap.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
// /*******************************************************************************
// * Copyright 2012-2018 Esri
// *
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// *
// * http://www.apache.org/licenses/LICENSE-2.0
// *
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// * See the License for the specific language governing permissions and
// * limitations under the License.
// ******************************************************************************/
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using Microsoft.Maui.Controls.Internals;
using Map = Esri.ArcGISRuntime.Mapping.Map;
namespace Esri.ArcGISRuntime.Toolkit.Maui;
/// <summary>
/// Defines a small "overview" (or "inset") map displaying a representation of the attached <see cref="GeoView"/>'s current viewpoint.
/// </summary>
public class OverviewMap : TemplatedView
{
private OverviewMapController? _controller;
private static readonly ControlTemplate DefaultControlTemplate;
private MapView? _overviewMapView;
static OverviewMap()
{
DefaultControlTemplate = new ControlTemplate(() =>
{
var converter = new Internal.LoadStatusToVisibilityConverter();
Frame rootFrame = new Frame
{
Padding = new Thickness(1), HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Fill,
CornerRadius = 0, HasShadow = false, BorderColor = Colors.Black, BackgroundColor = Colors.White
};
Grid root = new Grid();
MapView mapView = new MapView()
{
IsAttributionTextVisible = false
};
ActivityIndicator activity = new ActivityIndicator();
activity.SetBinding(ActivityIndicator.IsRunningProperty, static (MapView mapView) => mapView.Map?.LoadStatus, converter: converter, converterParameter: "Loading", source: mapView);
root.Add(activity);
Label label = new Label()
{
TextColor = Colors.Black, Text = "Map failed to load. Did you forget an API key?"
};
label.SetBinding(VisualElement.IsVisibleProperty, static (MapView mapView) => mapView.Map?.LoadStatus, converter: converter, converterParameter: "FailedToLoad", source: mapView);
root.Add(label);
mapView.SetBinding(VisualElement.IsVisibleProperty, static (MapView mapView) => mapView.Map?.LoadStatus, converter: converter, converterParameter: "Loaded", source: mapView);
root.Add(mapView);
INameScope nameScope = new NameScope();
NameScope.SetNameScope(rootFrame, nameScope);
nameScope.RegisterName("PART_MapView", mapView);
rootFrame.Content = root;
return rootFrame;
});
}
/// <summary>
/// Initializes a new instance of the <see cref="OverviewMap"/> class.
/// </summary>
public OverviewMap()
{
ControlTemplate = DefaultControlTemplate;
HeightRequest = 100;
WidthRequest = 100;
HorizontalOptions = LayoutOptions.End;
VerticalOptions = LayoutOptions.Start;
AreaSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Null, System.Drawing.Color.Transparent, new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Red, 1));
PointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Cross, System.Drawing.Color.Red, 16);
Map = new Map(BasemapStyle.ArcGISTopographic);
}
/// <summary>
/// <inheritdoc />
/// </summary>
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
if (_overviewMapView != null)
{
_controller?.Dispose();
_overviewMapView.Map = null;
}
_overviewMapView = GetTemplateChild("PART_MapView") as MapView;
if (_overviewMapView != null)
{
_overviewMapView.Map = Map;
_controller = new OverviewMapController(_overviewMapView)
{
ScaleFactor = ScaleFactor,
PointSymbol = PointSymbol,
AreaSymbol = AreaSymbol,
AttachedView = GeoView,
};
}
}
/// <summary>
/// Gets or sets the symbol used to draw the <see cref="GeoView"/>'s visible area.
/// </summary>
/// <remarks>
/// The default is an empty fill symbol with a 1 point red outline.
/// </remarks>
public Symbol? AreaSymbol
{
get => GetValue(AreaSymbolProperty) as Symbol;
set => SetValue(AreaSymbolProperty, value);
}
/// <summary>
/// Gets or sets the geoview whose extent is to be displayed.
/// </summary>
/// <remarks>
/// Note that by default interaction with <see cref="OverviewMap"/> will navigate the attached GeoView.
/// </remarks>
public GeoView? GeoView
{
get => GetValue(GeoViewProperty) as GeoView;
set => SetValue(GeoViewProperty, value);
}
/// <summary>
/// Gets or sets the Map shown in the inset/overview map.
/// </summary>
/// <remarks>
/// Defaults to a map with a basemap in style <see cref="BasemapStyle.ArcGISTopographic"/>.
/// </remarks>
public Map? Map
{
get => GetValue(MapProperty) as Map;
set => SetValue(MapProperty, value);
}
/// <summary>
/// Gets or sets the symbol used to draw the <see cref="GeoView"/>'s viewpoint when it isn't possible to show the visible area (for example, when showing a scene).
/// </summary>
/// <remarks>
/// The default is a red cross.
/// </remarks>
public Symbol? PointSymbol
{
get => GetValue(PointSymbolProperty) as Symbol;
set => SetValue(PointSymbolProperty, value);
}
/// <summary>
/// Gets or sets the amount to scale the overview map's viewpoint compared to the attached <see cref="GeoView"/>.
/// </summary>
/// <remarks>
/// The default is 25.
/// </remarks>
public double ScaleFactor
{
get => (double)GetValue(ScaleFactorProperty);
set => SetValue(ScaleFactorProperty, value);
}
/// <summary>
/// Identifies the <see cref="AreaSymbol"/> bindable property.
/// </summary>
public static readonly BindableProperty AreaSymbolProperty =
BindableProperty.Create(nameof(AreaSymbol), typeof(Symbol), typeof(OverviewMap), null, propertyChanged: OnAreaSymbolChanged);
/// <summary>
/// Identifies the <see cref="GeoView"/> bindable property.
/// </summary>
public static readonly BindableProperty GeoViewProperty =
BindableProperty.Create(nameof(GeoView), typeof(GeoView), typeof(OverviewMap), null, BindingMode.OneWay, null, propertyChanged: OnGeoViewPropertyChanged);
/// <summary>
/// Identifies the <see cref="Map"/> bindable property.
/// </summary>
public static readonly BindableProperty MapProperty =
BindableProperty.Create(nameof(Map), typeof(Map), typeof(OverviewMap), null, propertyChanged: OnMapPropertyChanged);
/// <summary>
/// Identifies the <see cref="PointSymbol"/> bindable property.
/// </summary>
public static readonly BindableProperty PointSymbolProperty =
BindableProperty.Create(nameof(PointSymbol), typeof(Symbol), typeof(OverviewMap), null, propertyChanged: OnPointSymbolChanged);
/// <summary>
/// Identifies the <see cref="ScaleFactor"/> bindable property.
/// </summary>
public static readonly BindableProperty ScaleFactorProperty =
BindableProperty.Create(nameof(ScaleFactor), typeof(double), typeof(OverviewMap), 25.0, propertyChanged: OnScaleFactorPropertyChanged);
private static void OnAreaSymbolChanged(BindableObject sender, object oldValue, object newValue)
{
if (((OverviewMap)sender)._controller is OverviewMapController controller)
{
controller.AreaSymbol = newValue as Symbol;
}
}
private static void OnGeoViewPropertyChanged(BindableObject sender, object oldValue, object newValue)
{
if (((OverviewMap)sender)._controller is OverviewMapController controller)
{
controller.AttachedView = newValue as GeoView;
}
}
private static void OnMapPropertyChanged(BindableObject sender, object oldValue, object newValue)
{
if ((OverviewMap)sender is OverviewMap sendingView && sendingView._overviewMapView is MapView overview)
{
overview.Map = (Map)newValue;
if (sendingView._controller is OverviewMapController controller && sendingView.GeoView != null)
{
controller.ApplyViewpoint(sendingView.GeoView, overview);
}
}
}
private static void OnPointSymbolChanged(BindableObject sender, object oldValue, object newValue)
{
if (((OverviewMap)sender)._controller is OverviewMapController controller)
{
controller.PointSymbol = newValue as Symbol;
}
}
private static void OnScaleFactorPropertyChanged(BindableObject sender, object oldValue, object newValue)
{
if (((OverviewMap)sender)._controller is OverviewMapController controller)
{
controller.ScaleFactor = (double)newValue;
}
}
}