Repository navigation
Expand file tree
/
Copy pathMap user interaction options.html
More file actions
263 lines (224 loc) · 11.2 KB
/
Copy pathMap user interaction options.html
File metadata and controls
263 lines (224 loc) · 11.2 KB
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<!DOCTYPE html>
<html lang="en">
<head>
<title>Map user interaction 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 how the different user interaction options of the map to modify how the map reacts when the user interacts with it." />
<meta name="keywords" content="Microsoft maps, map, gis, API, SDK, interact, map options, keyboard, mouse, pan, zoom" />
<meta name="author" content="Microsoft Azure Maps" /><meta name="version" content="1.0" />
<meta name="screenshot" content="screenshot.jpg" />
<!-- 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 src="/lib/clipboard/dist/clipboard.min.js"></script>
<script>
var map, defaultOptions, removeDefaults;
function getMap() {
//Initialize a map instance.
map = new atlas.Map('myMap', {
view: 'Auto',
language: 'Auto',
//Add authentication details for connecting to Azure Maps.
authOptions: {
// Use SAS token for authentication
authType: 'sas',
getToken: function (resolve, reject, map) {
// URL to your authentication service that retrieves a SAS Token
var tokenServiceUrl = 'https://samples.azuremaps.com/api/GetAzureMapsSasToken';
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 until the map resources are ready.
map.events.add('ready', function () {
defaultOptions = map.getUserInteraction();
//Update the map with the options in the input fields.
updateOptions();
});
new ClipboardJS('.copyBtn');
}
function updateOptions() {
var options = getInputOptions();
//Update the maps user interaction options.
map.setUserInteraction(options);
document.getElementById('CodeOutput').value = JSON.stringify(options, null, '\t').replace(/\"([^(\")"]+)\":/g, "$1:");
}
function getInputOptions() {
removeDefaults = document.getElementById('RemoveDefaults').checked;
var wheelZoomRate = parseFloat(document.getElementById('wheelZoomRate').value);
//Acccount for offset of the min value of the range.
if (wheelZoomRate > 1) {
wheelZoomRate--;
}
document.getElementById('wzr').value = '1/' + wheelZoomRate;
wheelZoomRate = 1 / wheelZoomRate;
if (removeDefaults && isWheelScrollZoomSame(wheelZoomRate)) {
wheelZoomRate = undefined;
}
return {
boxZoomInteraction: getPropertyValue('boxZoomInteraction', document.getElementById('boxZoomInteraction').checked),
dblClickZoomInteraction: getPropertyValue('dblClickZoomInteraction', document.getElementById('dblClickZoomInteraction').checked),
dragPanInteraction: getPropertyValue('dragPanInteraction', document.getElementById('dragPanInteraction').checked),
dragRotateInteraction: getPropertyValue('dragRotateInteraction', document.getElementById('dragRotateInteraction').checked),
interactive: getPropertyValue('interactive', document.getElementById('interactive').checked),
keyboardInteraction: getPropertyValue('keyboardInteraction', document.getElementById('keyboardInteraction').checked),
scrollZoomInteraction: getPropertyValue('scrollZoomInteraction', document.getElementById('scrollZoomInteraction').checked),
touchInteraction: getPropertyValue('touchInteraction', document.getElementById('touchInteraction').checked),
wheelZoomRate: wheelZoomRate
};
}
function getPropertyValue(propertyName, value) {
if (removeDefaults) {
if (propertyName.indexOf('.') > -1) {
var p = propertyName.split('.');
var val = defaultOptions;
for (var i = 0; i < p.length; i++) {
val = val[p[i]];
}
if (val === value) {
return undefined;
}
} else if (defaultOptions[propertyName] === value) {
return undefined;
}
}
return value;
}
function openTab(elm, tabName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(tabName).style.display = "block";
elm.className += " active";
}
function isWheelScrollZoomSame(wheelZoomRate) {
return Math.round(wheelZoomRate * 10000) / 10000 === Math.round(defaultOptions.wheelZoomRate * 10000) / 10000;
}
</script>
<style>
#myMap {
position: relative;
width: calc(100% - 375px);
min-width: 290px;
height: 600px;
float: left;
}
.sidePanel {
width: 325px;
height: 580px;
float: left;
margin-right: 10px;
}
#CodeOutput {
width: 290px;
height: 380px;
overflow-y: auto;
}
.copyBtn {
float: right;
}
.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 6px 8px;
transition: 0.3s;
font-size: 14px;
}
.tab button:hover {
background-color: #ddd;
}
.tab button.active {
background-color: #ccc;
}
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
height: 440px;
overflow-y: auto;
}
</style>
</head>
<body onload="getMap()">
<fieldset class="sidePanel">
<legend>Map user interaction options</legend>
This sample shows how the different user interaction options of the map to modify how the map reacts when the user interacts with it.
<br /><br />
<div class="tab">
<button class="tablinks active" onclick="openTab(this, 'UserInteractionOptions')">User Interaction Options</button>
<button class="tablinks" onclick="openTab(this, 'Code')">Code</button>
</div>
<div id="UserInteractionOptions" class="tabcontent" style="display:block;">
<table>
<tr title='Whether the Shift + left click and drag will draw a zoom box. Default: true'>
<td>Box Zoom Interaction:</td>
<td><input id='boxZoomInteraction' type='checkbox' onclick='updateOptions()' checked='checked' /></td>
</tr>
<tr title='Whether double left click will zoom the map inwards. Default: true'>
<td>Double Click Zoom Interaction:</td>
<td><input id='dblClickZoomInteraction' type='checkbox' onclick='updateOptions()' checked='checked' /></td>
</tr>
<tr title='Whether left click and drag will pan the map. Default: true'>
<td>Drag Pan Interaction:</td>
<td><input id='dragPanInteraction' type='checkbox' onclick='updateOptions()' checked='checked' /></td>
</tr>
<tr title='Whether right click and drag will rotate and pitch the map. Default: true'>
<td>Drag Rotate Interaction:</td>
<td><input id='dragRotateInteraction' type='checkbox' onclick='updateOptions()' checked='checked' /></td>
</tr>
<tr title='Whether the map is interactive or static. If false, all user interaction is disabled. If true, only selected user interactions will enabled. Default: true'>
<td>Interactive:</td>
<td><input id='interactive' type='checkbox' onclick='updateOptions()' checked='checked' /></td>
</tr>
<tr title='Whether the keyboard interactions are enabled. Default: true'>
<td>Keyboard Interaction:</td>
<td><input id='keyboardInteraction' type='checkbox' onclick='updateOptions()' checked='checked' /></td>
</tr>
<tr title='Whether the map should zoom on scroll input. Default: true'>
<td>Scroll Zoom Interaction:</td>
<td><input id='scrollZoomInteraction' type='checkbox' onclick='updateOptions()' checked='checked' /></td>
</tr>
<tr title='Whether touch interactions are enabled for touch devices. Default: true'>
<td>Touch Interaction:</td>
<td><input id='touchInteraction' type='checkbox' onclick='updateOptions()' checked='checked' /></td>
</tr>
<tr title='Sets the zoom rate of the mouse wheel. Default: 1/450'>
<td>Wheel Zoom Rate:</td>
<td>
<form>
<input type="range" id="wheelZoomRate" value="450" min="1" max="1000" step="50" onchange="updateOptions()" />
<output id="wzr">1/450</output>
</form>
</td>
</tr>
</table>
</div>
<div id="Code" class="tabcontent">
<textarea id="CodeOutput"></textarea><br /><br />
<input id="RemoveDefaults" type="checkbox" onclick="updateOptions()" checked="checked" /> Remove defaults
<button class="copyBtn" data-clipboard-target="#CodeOutput">Copy to clipboard</button>
</div>
</fieldset>
<div id="myMap"></div>
</body>
</html>