-
Notifications
You must be signed in to change notification settings - Fork 449
/
Map Navigation Control Options.html
232 lines (208 loc) · 10.5 KB
/
Map Navigation Control Options.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Map Navigation Control Options - Azure Maps Web SDK Samples</title>
<meta charset="utf-8" />
<link rel="shortcut icon" href="/favicon.ico"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="This sample shows all the map navigation controls on the map and how they react with different option settings." />
<meta name="keywords" content="Microsoft maps, maps, map, API, SDK, GIS, navigation controls, pan, zoom, pitch, tilt, rotate, satellite, aerial, imagery" />
<meta name="author" content="Microsoft Azure Maps" /><meta name="version" content="1.0" />
<meta name="screenshot" content="screenshot.gif" />
<!-- Add references to the Azure Maps Map control JavaScript and CSS files. -->
<link href="https://atlas.microsoft.com/sdk/javascript/mapcontrol/3/atlas.min.css" rel="stylesheet" />
<script src="https://atlas.microsoft.com/sdk/javascript/mapcontrol/3/atlas.min.js"></script>
<script>
var map, controls = [];
function getMap() {
//Initialize a map instance.
map = new atlas.Map("myMap", {
center: [-122.33, 47.6],
zoom: 12,
view: 'Auto',
//Add authentication details for connecting to Azure Maps.
authOptions: {
//Use Microsoft Entra ID authentication.
authType: 'anonymous',
clientId: 'e6b6ab59-eb5d-4d25-aa57-581135b927f0', //Your Azure Maps client id for accessing your Azure Maps account.
getToken: function (resolve, reject, map) {
//URL to your authentication service that retrieves an Microsoft Entra ID Token.
var tokenServiceUrl = 'https://samples.azuremaps.com/api/GetAzureMapsToken';
fetch(tokenServiceUrl).then(r => r.text()).then(token => resolve(token));
}
//Alternatively, use an Azure Maps key. Get an Azure Maps key at https://azure.com/maps. NOTE: The primary key should be used as the key.
//authType: 'subscriptionKey',
//subscriptionKey: '[YOUR_AZURE_MAPS_KEY]'
}
});
//Wait for map resources to be ready before loading controls.
map.events.add('ready', addControls);
}
function addControls() {
//Remove all controls on the map.
map.controls.remove(controls);
controls = [];
//Get input options.
var positionOption = getSelectValue('controlPosition');
var controlStyle = getSelectValue('controlStyle');
var pickerLayout = getSelectValue('pickerLayout');
var mapStyles = [];
var pickerStyles = document.getElementById('pickerStyles');
for (var i = 0; i < pickerStyles.length; i++) {
if (pickerStyles.options[i].selected) {
mapStyles.push(pickerStyles.options[i].value);
}
}
//Create a zoom control.
controls.push(new atlas.control.ZoomControl({
zoomDelta: parseFloat(getSelectValue('zoomControlDelta')),
style: controlStyle
}));
//Create a pitch control and add it to the map.
controls.push(new atlas.control.PitchControl({
pitchDegreesDelta: parseFloat(getSelectValue('pitchControlDelta')),
style: controlStyle
}));
//Create a compass control and add it to the map.
controls.push(new atlas.control.CompassControl({
rotationDegreesDelta: parseFloat(getSelectValue('compassControlRotationDelta')),
style: controlStyle
}));
//Create a style control and add it to the map.
controls.push(new atlas.control.StyleControl({
style: controlStyle,
mapStyles: mapStyles,
layout: pickerLayout
}));
//Add controls to the map.
map.controls.add(controls, {
position: positionOption
});
}
function getSelectValue(id) {
var elm = document.getElementById(id);
return elm.options[elm.selectedIndex].value;
}
</script>
<style>
.sidePanel {
width: 350px;
height: 580px;
float: left;
margin-right: 10px;
}
#myMap {
position: relative;
width: calc(100% - 360px);
min-width:290px;
height: 600px;
float: left;
}
</style>
</head>
<body onload="getMap()">
<div class="sidePanel">
<fieldset style="width:320px;margin-bottom:10px;">
<legend>Map Navigation Control Options</legend>
This sample shows all the map navigation controls on the map and how they react with different option settings. <br /><br />
To test the zoom delta, simply press the zoom button to see how the map zoom per click changes, moving several levels at a time when the delta is greater than one. <br /><br />
To test the pitch and compass rotation deltas, hover over the appropriate control and use the addition buttons that appear to see how the new delta has changed the behavior of the button. <br /><br />
See the <a href="https://docs.microsoft.com/azure/azure-maps/map-add-controls" target="_blank">Add map controls</a> and <a href="https://docs.microsoft.com/azure/azure-maps/choose-map-style" target="_blank">Choose map style</a> documentation for more examples using the map navigation controls.
</fieldset>
<table>
<tr title="The position the control will be placed on the map. If not specified, the control will be located at the default position it defines.">
<td>Control Position:</td>
<td>
<select id="controlPosition" onchange="addControls()" title="Control Position">
<option>bottom-left</option>
<option>bottom-right</option>
<option>non-fixed</option>
<option>top-left</option>
<option selected="selected">top-right</option>
</select>
</td>
</tr>
<tr title="The style of the control.">
<td>Control Style:</td>
<td>
<select id="controlStyle" onchange="addControls()" title="Control Style">
<option>dark</option>
<option selected="selected">light</option>
</select>
</td>
</tr>
<tr title="The extent to which the map will zoom with each click of the control.">
<td>Zoom Delta:</td>
<td>
<select id="zoomControlDelta" onchange="addControls()" title="Zoom Delta">
<option selected="selected">1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</td>
</tr>
<tr title="The angle that the map will tilt with each click of the control.">
<td>Pitch Delta:</td>
<td>
<select id="pitchControlDelta" onchange="addControls()" title="Pitch Delta">
<option>5</option>
<option selected="selected">10</option>
<option>15</option>
<option>20</option>
<option>25</option>
<option>30</option>
<option>35</option>
<option>40</option>
<option>45</option>
</select>
</td>
</tr>
<tr title="The angle that the map will rotate with each click of the control.">
<td>Compass Rotation Delta:</td>
<td>
<select id="compassControlRotationDelta" onchange="addControls()" title="Compass Rotation Delta">
<option>5</option>
<option>10</option>
<option selected="selected">15</option>
<option>20</option>
<option>25</option>
<option>30</option>
<option>35</option>
<option>40</option>
<option>45</option>
</select>
</td>
</tr>
<tr title="The name of the style to use when rendering the map. Available styles can be found in the supported styles article.">
<td>Picker Styles:</td>
<td>
<select id="pickerStyles" multiple="multiple" onchange="addControls()" title="Picker Styles">
<option value="blank">blank</option>
<option value="blank_accessible">blank_accessible</option>
<option value="grayscale_dark" selected="selected">grayscale_dark</option>
<option value="grayscale_light" selected="selected">grayscale_light</option>
<option value="high_contrast_dark">high_contrast_dark</option>
<option value="night" selected="selected">night</option>
<option value="road" selected="selected">road</option>
<option value="road_shaded_relief" selected="selected">road_shaded_relief</option>
<option value="satellite">satellite</option>
<option value="satellite_road_labels">satellite_road_labels</option>
</select>
</td>
</tr>
<tr title="The style of the control.">
<td>Style Picker Layout:</td>
<td>
<select id="pickerLayout" onchange="addControls()" title="Style Picker Layout">
<option selected="selected">icons</option>
<option>list</option>
</select>
</td>
</tr>
</table>
</div>
<div id="myMap"></div>
</body>
</html>