-
Notifications
You must be signed in to change notification settings - Fork 471
Expand file tree
/
Copy pathMap style options.html
More file actions
401 lines (353 loc) · 18.5 KB
/
Map style options.html
File metadata and controls
401 lines (353 loc) · 18.5 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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
<!DOCTYPE html>
<html lang="en">
<head>
<title>Map style 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 style options of the map affect rendering." />
<meta name="keywords" content="Microsoft maps, map, gis, API, SDK, style, logo, lighting, map options" />
<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]'
}
});
//Add events to update the map-info panel.
map.events.add("dragend", () => updateState());
map.events.add("zoomend", () => updateState());
//Wait until the map resources are ready.
map.events.add('ready', function () {
defaultOptions = map.getStyle();
//Update the map with the options in the input fields.
updateStyles();
updateState();
});
new ClipboardJS('.copyBtn');
}
function updateStyles() {
var options = getInputOptions();
//Update the maps style options.
map.setStyle(options);
document.getElementById('CodeOutput').value = JSON.stringify(options, null, '\t').replace(/\"([^(\")"]+)\":/g, "$1:");
}
function getInputOptions() {
removeDefaults = document.getElementById('RemoveDefaults').checked;
var light = {};
var a = getSelectValue('anchor');
if (!removeDefaults || a !== 'map') {
light.anchor = a;
}
var c = document.getElementById('color').value.toUpperCase();
if (!removeDefaults || c!== '#FFFFFF') {
light.color = c;
}
var int = parseFloat(document.getElementById('intensity').value);
if (!removeDefaults || int !== 0.5) {
light.intensity = int;
}
var r = parseFloat(document.getElementById('RadialCoordinate').value);
var az = parseFloat(document.getElementById('AzimuthalAngle').value);
var pa = parseFloat(document.getElementById('PolarAngle').value);
if (!removeDefaults || r !== defaultOptions.light.position[0] || az !== defaultOptions.light.position[1] || pa !== defaultOptions.light.position[2]) {
light.position = [r, az, pa];
}
return {
autoResize: getPropertyValue('autoResize', document.getElementById('autoResize').checked),
renderWorldCopies: getPropertyValue('renderWorldCopies', document.getElementById('renderWorldCopies').checked),
showFeedbackLink: getPropertyValue('showFeedbackLink', document.getElementById('showFeedbackLink').checked),
showLogo: getPropertyValue('showLogo', document.getElementById('showLogo').checked),
showLabels: getPropertyValue('showLabels', document.getElementById('showLabels').checked),
showTileBoundaries: getPropertyValue('showTileBoundaries', document.getElementById('showTileBoundaries').checked),
style: getPropertyValue('style', getSelectValue('style')),
light: (Object.keys(light).length > 0)? light: undefined,
styleOverrides: (obj => Object.keys(obj).length > 0 ? obj : undefined)(Object.fromEntries([
['countryRegion', { borderVisible: document.getElementById('showCountryBorders').checked }],
['adminDistrict', { borderVisible: document.getElementById('showAdminDistrictBorders').checked }],
['adminDistrict2', { borderVisible: document.getElementById('showSecondAdminDistrictBorders').checked }],
['buildingFootprint', { visible: document.getElementById('showBuildingFootprints').checked }],
['roadDetails', { visible: document.getElementById('showRoadDetails').checked }]
].filter(([_, v]) => !removeDefaults || !v.visible))),
};
}
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 getSelectValue(id) {
var elm = document.getElementById(id);
return elm.options[elm.selectedIndex].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 updateState() {
var camera = map.getCamera();
document.getElementById("map-info").innerText =
`Zoom: ${camera.zoom.toFixed(1)} / ` +
`Lat: ${camera.center[1].toFixed(5)} / ` +
`Lng: ${camera.center[0].toFixed(5)}`;
}
</script>
<style>
#myMap {
position: relative;
width: calc(100% - 365px);
min-width: 290px;
height: 600px;
float: left;
}
#panel {
position: absolute;
top: 14px;
left: 378px;
padding: 10px;
border-radius: 5px;
background-color: white;
}
.sidePanel {
width: 325px;
height: 580px;
float: left;
margin-right: 10px;
}
#CodeOutput {
width: 290px;
height: 390px;
overflow-y: auto;
tab-size: 4;
}
.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 style options</legend>
This sample shows how the different style options of the map affect rendering.
<br /><br />
<div class="tab">
<button class="tablinks active" onclick="openTab(this, 'MapStyleOptions')">Style Options</button>
<button class="tablinks" onclick="openTab(this, 'LightingOptions')">Lighting Options</button>
<button class="tablinks" onclick="openTab(this, 'Code')">Code</button>
</div>
<div id="MapStyleOptions" class="tabcontent" style="display:block;">
<table>
<tr title="If true the map will automatically resize whenever the window's size changes. Otherwise map.resize() must be called.">
<td>Auto resize:</td>
<td><input id="autoResize" type="checkbox" onclick="updateStyles()" checked="checked" /></td>
</tr>
<tr title="Specifies if multiple copies of the world should be rendered when zoomed out. ">
<td>Render world copies:</td>
<td><input id="renderWorldCopies" type="checkbox" onclick="updateStyles()" checked="checked" /></td>
</tr>
<tr title="Specifies if the feedback link should be displayed on the map or not.">
<td>Show feedback link:</td>
<td><input id="showFeedbackLink" type="checkbox" onclick="updateStyles()" checked="checked" /></td>
</tr>
<tr title="Specifies if the Microsoft logo should be hidden or not. If set to true a Microsoft copyright string will be added to the map.">
<td>Show logo:</td>
<td><input id="showLogo" type="checkbox" onclick="updateStyles()" checked="checked" /></td>
</tr>
<tr title="Specifies if the map should display labels.">
<td>Show labels:</td>
<td><input id="showLabels" type="checkbox" onclick="updateStyles()" checked="checked" /></td>
</tr>
<tr title="Specifies if the map should display country borders.">
<td>Show country borders:</td>
<td><input id="showCountryBorders" type="checkbox" onclick="updateStyles()" checked="checked" /></td>
</tr>
<tr title="Specifies if the map should display admin district borders.">
<td>Show admin district borders:</td>
<td><input id="showAdminDistrictBorders" type="checkbox" onclick="updateStyles()" checked="checked" /></td>
</tr>
<tr title="Specifies if the map should display second admin district borders.">
<td>Show second admin district borders:</td>
<td><input id="showSecondAdminDistrictBorders" type="checkbox" onclick="updateStyles()" checked="checked" /></td>
</tr>
<tr title="Specifies if the map should display building footprints.">
<td>Show building footprints:</td>
<td><input id="showBuildingFootprints" type="checkbox" onclick="updateStyles()" checked="checked" /></td>
</tr>
<tr title="Specifies if the map should display road details.">
<td>Show road details:</td>
<td><input id="showRoadDetails" type="checkbox" onclick="updateStyles()" checked="checked" /></td>
</tr>
<tr title="Specifies if the map should render an outline around each tile and the tile ID. These tile boundaries are useful for debugging. The uncompressed file size of the first vector source is drawn in the top left corner of each tile, next to the tile ID. ">
<td>Show tile boundaries:</td>
<td><input id="showTileBoundaries" type="checkbox" onclick="updateStyles()" /></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>Style:</td>
<td></td>
</tr>
<tr>
<td colspan="2">
<select id="style" onchange="updateStyles()">
<option value="blank">blank</option>
<option value="blank_accessible">blank_accessible</option>
<option value="grayscale_dark">grayscale_dark</option>
<option value="grayscale_light">grayscale_light</option>
<option value="high_contrast_dark">high_contrast_dark</option>
<option value="night">night</option>
<option value="road" selected="selected">road</option>
<option value="road_shaded_relief">road_shaded_relief</option>
<option value="satellite">satellite</option>
<option value="satellite_road_labels">satellite_road_labels</option>
</select>
</td>
</tr>
</table>
<p>
In addition to the options in this tool, the map also supports the following style options;
<ul>
<li>preserveDrawingBuffer - allows the map canvas to be exported as an image.</li>
<li>language - the language of the map.</li>
<li>view - the geopolitical region view to align with.</li>
</ul>
</p>
</div>
<div id="LightingOptions" class="tabcontent">
The following are style options for lighting used for shading building models and extruded polygons.
<br /> <br />
<table>
<tr title="Specifies wether extruded geometries are lit relative to the map or viewport.">
<td>Anchor:</td>
<td>
<select id="anchor" onchange="updateStyles()">
<option value="map" selected="selected">map</option>
<option value="viewport">viewport</option>
</select>
</td>
</tr>
<tr title="The color of the light.">
<td>Color:</td>
<td><input type="color" id="color" value="#FFFFFF" onchange="updateStyles()" /></td>
</tr>
<tr title="Intensity of lighting (on a scale from 0 to 1). Higher numbers will present as more extreme contrast.">
<td>Intensity:</td>
<td>
<form oninput="int.value=intensity.value">
<input type="range" id="intensity" value="0.5" min="0" max="1" step="0.1" oninput="updateStyles()" onchange="updateStyles()" />
<output name="int" for="intensity">0.5</output>
</form>
</td>
</tr>
<tr title="Position of the light source relative to lit (extruded) geometries, in [r radial coordinate, a azimuthal angle, p polar angle].">
<td colspan="2">Position:</td>
</tr>
<tr title="Indicates the distance from the center of the base of an object to its light.">
<td> Radial coordinate:</td>
<td>
<form oninput="r.value=RadialCoordinate.value">
<input type="range" id="RadialCoordinate" value="1.15" min="0" max="3.5" step="0.05" oninput="updateStyles()" onchange="updateStyles()" />
<output name="r" for="RadialCoordinate">1.15</output>
</form>
</td>
</tr>
<tr title="Indicates the position of the light relative to 0° (0° when light.anchor is set to viewport corresponds to the top of the viewport, or 0° when light.anchor is set to map corresponds to due north, and degrees proceed clockwise).">
<td> Azimuthal angle</td>
<td>
<form oninput="az.value=AzimuthalAngle.value">
<input type="range" id="AzimuthalAngle" value="210" min="0" max="360" step="1" oninput="updateStyles()" onchange="updateStyles()" />
<output name="az" for="AzimuthalAngle">210</output>
</form>
</td>
</tr>
<tr title="Indicates the height of the light (from 0°, directly above, to 180°, directly below).">
<td> Polar angle:</td>
<td>
<form oninput="pa.value=PolarAngle.value">
<input type="range" id="PolarAngle" value="30" min="0" max="180" step="1" oninput="updateStyles()" onchange="updateStyles()" />
<output name="pa" for="PolarAngle">30</output>
</form>
</td>
</tr>
</table>
</div>
<div id="Code" class="tabcontent">
<textarea id="CodeOutput"></textarea><br /><br />
<input id="RemoveDefaults" type="checkbox" onclick="updateStyles()" checked="checked" /> Remove defaults
<button class="copyBtn" data-clipboard-target="#CodeOutput">Copy to clipboard</button>
</div>
</fieldset>
<div id="myMap"></div>
<div id="panel">
<div id="map-info"></div>
</div>
</body>
</html>