forked from Azure-Samples/AzureMapsCodeSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample_Rangierbahnhof_München_Ost.html
517 lines (443 loc) · 23.3 KB
/
Example_Rangierbahnhof_München_Ost.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
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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
<!DOCTYPE html>
<html lang="en">
<head>
<title>Polygon Extrusion Layer 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 options of the polygon extrusion layer affect rendering." />
<meta name="keywords" content="Microsoft maps, map, gis, API, SDK, polygon, layer" />
<meta name="author" content="Microsoft Azure Maps" />
<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/2/atlas.min.css" rel="stylesheet" />
<script src="https://atlas.microsoft.com/sdk/javascript/mapcontrol/2/atlas.min.js"></script>
<link rel="stylesheet" href="https://atlas.microsoft.com/sdk/javascript/drawing/1/atlas-drawing.min.css" type="text/css" />
<script src="https://atlas.microsoft.com/sdk/javascript/drawing/1/atlas-drawing.min.js"></script>
<script src="/Static/lib/azure-maps-animations.min.js"></script>
<script src="/Static/lib/clipboard.min.js"></script>
<script src="data.js"></script>
<script>
var animation, map, datasource, polygonLayer, defaultOptions, removeDefaults, selectedFillPatternIdx = 0;
subscriptionKey = prompt("Azure Maps Subscription Key")
var fillPatterns = [
'fill-checker-blue', 'fill-checker-darkblue', 'fill-checker-green', 'fill-checker-red', 'fill-checker-yellow',
'fill-diamond-blue', 'fill-diamond-darkblue', 'fill-diamond-green', 'fill-diamond-red', 'fill-diamond-yellow',
'fill-grid-blue', 'fill-grid-darkblue', 'fill-grid-green', 'fill-grid-red', 'fill-grid-yellow',
'fill-smallgrid-blue', 'fill-smallgrid-darkblue', 'fill-smallgrid-green', 'fill-smallgrid-red', 'fill-smallgrid-yellow',
'fill-stripes-downwards-blue', 'fill-stripes-downwards-darkblue', 'fill-stripes-downwards-green', 'fill-stripes-downwards-red', 'fill-stripes-downwards-yellow',
'fill-stripes-upwards-blue', 'fill-stripes-upwards-darkblue', 'fill-stripes-upwards-green', 'fill-stripes-upwards-red', 'fill-stripes-upwards-yellow',
];
function GetMap() {
//Initialize a map instance.
map = new atlas.Map('myMap', {
// center: [-122.1333, 47.637],
center: [11.495255431122871, 48.19577681707284], // rangierbahnhof münchen nord: https://www.deutschebahn.com/de/presse/pressestart_zentrales_uebersicht/Automatisierte-Zugbildung-Gueterzuege-starten-kuenftig-deutlich-schneller-6868340
zoom: 17,
style: "satellite",
pitch: 60,
view: 'Auto',
//Add authentication details for connecting to Azure Maps.
authOptions: {
//Use Azure Active Directory 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 Azure Active Directory 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: subscriptionKey
}
});
//Wait until the map resources are ready.
map.events.add('ready', function () {
//Create a style control and add it to the map.
map.controls.add(
new atlas.control.StyleControl(
{
style: 'satellite',
mapStyles: "all",
}
),
{
position: 'top-right'
}
);
//Create a data source and add it to the map.
datasource = new atlas.source.DataSource();
map.sources.add(datasource);
//Add polygon to data source.
//datasource.add(new atlas.data.Polygon([[[-122.132815, 47.636661], [-122.133631, 47.636676], [-122.133636, 47.63652], [-122.133523, 47.63651], [-122.133545, 47.636361], [-122.133759, 47.636361], [-122.133759, 47.636173], [-122.132703, 47.63617], [-122.132713, 47.636343], [-122.13303, 47.636347], [-122.133035, 47.636528], [-122.13281, 47.636528], [-122.132815, 47.636661]]]));
trains.forEach(train => {
train.features.forEach(wagon => {
datasource.add(new atlas.data.Polygon(wagon.geometry.coordinates));
})
});
//Create a layer to render the polygon data.
polygonLayer = new atlas.layer.PolygonExtrusionLayer(datasource);
map.layers.add(polygonLayer, 'labels');
defaultOptions = polygonLayer.getOptions();
//Update the polygon layer with the options in the input fields.
createFillPatternOptions();
fillPatternSelected(document.getElementById('fillPatternDropdown').childNodes[0], 0);
toggleFillPatternDropdown();
});
new ClipboardJS('.copyBtn');
map.events.add('ready', function() {
//Create an instance of the drawing manager and display the drawing toolbar.
drawingManager = new atlas.drawing.DrawingManager(map, {
toolbar: new atlas.control.DrawingToolbar({
position: 'top-right',
style: 'dark'
})
});
});
}
factor = 0.1
function animate(){
map.layers.userLayers[0].layer.getSource().shapes.forEach(wagon => {
var newCoordinates = []
wagon.getCoordinates()[0].forEach(
coord => {
newCoordinates.push([coord[0] + (0.0001 * factor), coord[1] - (0.000022 * factor)]);
}
)
wagon.setCoordinates(newCoordinates);
})
// 0,0
// -50, -25
// 50,11
}
animation = atlas.animations.interval(10 * factor, animate);
//Start playing the animation.
//animation.play();
function updatePolygonLayer() {
var options = getInputOptions();
//Update all the options in the polygon layer.
polygonLayer.setOptions(options);
document.getElementById('CodeOutput').value = JSON.stringify(options, null, '\t').replace(/\"([^(\")"]+)\":/g, "$1:");
}
function getInputOptions() {
removeDefaults = document.getElementById('RemoveDefaults').checked;
var options = {
height: getPropertyValue('height', parseFloat(document.getElementById('Height').value)),
base: getPropertyValue('base', parseFloat(document.getElementById('Base').value)),
fillOpacity: getPropertyValue('fillOpacity', parseFloat(document.getElementById('FillOpacity').value)),
minZoom: getPropertyValue('minZoom', parseFloat(document.getElementById('MinZoom').value)),
maxZoom: getPropertyValue('maxZoom', parseFloat(document.getElementById('MaxZoom').value)),
translateAnchor: getPropertyValue('translateAnchor', document.getElementById('TranslateAnchor').value),
translate: getPropertyValue('translate', [
parseFloat(document.getElementById('TranslateX').value),
parseFloat(document.getElementById('TranslateY').value)
]),
verticalGradient: getPropertyValue('verticalGradient', document.getElementById('VerticalGradient').checked),
visible: getPropertyValue('visible', document.getElementById('Visible').checked)
};
//Need to make the fill pattern undefined to override it.
polygonLayer.setOptions({ fillPattern: undefined });
if (document.getElementById('fillColorBtn').checked || document.getElementById('FillColorTransparent').checked) {
options.fillColor = getPropertyValue('fillColor', document.getElementById('FillColorTransparent').checked ? 'transparent' : document.getElementById('FillColor').value);
} else {
options.fillPattern = fillPatterns[selectedFillPatternIdx];
}
return options;
}
function getPropertyValue(propertyName, value) {
if (removeDefaults && 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 createFillPatternOptions() {
var html = [];
for (var i = 0; i < fillPatterns.length; i++) {
map.imageSprite.add(fillPatterns[i], '/static/images/fill-patterns/' + fillPatterns[i] + '.png');
html.push('<a class="pattern-selector" href="javascript:void(0);" onclick="fillPatternSelected(this, ', i, ');" style="background-image:url(\'/static/images/fill-patterns/', fillPatterns[i], '.png\')" title="', fillPatterns[i], '"></a>');
}
document.getElementById('fillPatternDropdown').innerHTML = html.join('');
}
function fillPatternSelected(elm, idx) {
selectedFillPatternIdx = idx;
document.getElementById('fillPatternBtn').style.backgroundImage = elm.style.backgroundImage;
toggleFillPatternDropdown();
updatePolygonLayer();
}
function toggleFillPatternDropdown() {
document.getElementById("fillPatternDropdown").classList.toggle("show");
}
</script>
<style>
#myMap {
position: relative;
width: calc(100% - 375px);
min-width: 290px;
height: 900px;
float: left;
}
.sidePanel {
width: 325px;
height: 580px;
float: left;
margin-right: 10px;
}
#CodeOutput {
width: 300px;
height: 420px;
overflow-y: auto;
}
.copyBtn {
float: right;
}
table td:nth-of-type(1) {
width: 120px;
}
table td:nth-of-type(2) {
width: 200px;
}
.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;
}
/* Dropdown Button */
.dropbtn {
background-color: white;
color: white;
height: 20px;
width: 150px;
border: none;
cursor: pointer;
}
/* Dropdown button on hover & focus */
.dropbtn:hover, .dropbtn:focus {
background-color: white;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
max-height: 400px;
overflow-y: auto;
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 6px;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {
background-color: #ddd
}
/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
.show {
display: block;
}
.pattern-selector {
background-repeat: repeat;
height: 10px;
width: 150px;
}
</style>
</head>
<body onload="GetMap()">
<fieldset class="sidePanel">
<legend>Polygon Extrusion Layer Options</legend>
This sample shows how the different options of the polygon extrusion layer affect rendering.
<br /><br />
<div class="tab">
<button class="tablinks active" onclick="openTab(this, 'StyleOptions')">Layer Options</button>
<button class="tablinks" onclick="openTab(this, 'PolygonStyleOptions')">Polygon Options</button>
<button class="tablinks" onclick="openTab(this, 'Code')">Code</button>
</div>
<div id="StyleOptions" class="tabcontent" style="display:block;">
<table>
<tr title="An integer specifying the minimum zoom level to render the layer at.">
<td>Min Zoom:</td>
<td>
<form oninput="minz.value=MinZoom.value">
<input type="range" id="MinZoom" value="0" min="0" max="24" step="1" oninput="updatePolygonLayer()" onchange="updatePolygonLayer()" />
<output name="minz" for="MinZoom">0</output>
</form>
</td>
</tr>
<tr title="An integer specifying the maximum zoom level to render the layer at.">
<td>Max Zoom:</td>
<td>
<form oninput="maxz.value=MaxZoom.value">
<input type="range" id="MaxZoom" value="24" min="0" max="24" step="1" oninput="updatePolygonLayer()" onchange="updatePolygonLayer()" />
<output name="maxz" for="MaxZoom">24</output>
</form>
</td>
</tr>
<tr title="Specifies if the layer is visible or not.">
<td>Visible:</td>
<td><input id="Visible" type="checkbox" onclick="updatePolygonLayer()" /></td>
</tr>
</table>
<p>
In addition to the options in this tool, the PolygonLayer also has options for;
<ul>
<li>sourceLayer - used with VectorTileSource.</li>
<li>filter - used to filter data in layer.</li>
</ul>
Many options in this layer also support Expressions which are not demonstrated in this sample.
</p>
</div>
<div id="PolygonStyleOptions" class="tabcontent">
<table>
<tr title="The height in meters to extrude this layer. This height is relative to the ground. Must be a number greater or equal to 0.">
<td>Height:</td>
<td>
<form oninput="o.value=Height.value">
<input type="range" id="Height" value="4" min="0" max="100" step="1" oninput="updatePolygonLayer()" onchange="updatePolygonLayer()" />
<output name="o" for="Height">4</output>
</form>
</td>
</tr>
<tr title="The height in meters to extrude the base of this layer. This height is relative to the ground. Must be a number greater or equal to 0.">
<td>Base:</td>
<td>
<form oninput="o.value=Base.value">
<input type="range" id="Base" value="0" min="0" max="100" step="1" oninput="updatePolygonLayer()" onchange="updatePolygonLayer()" />
<output name="o" for="Base">0</output>
</form>
</td>
</tr>
<tr title="The color to fill the polygons with.">
<td><input id="fillColorBtn" name="fillGroup" type="radio" onclick="updatePolygonLayer()" checked="checked" /> Fill Color:</td>
<td>
<input type="color" value="#ec0016" id="FillColor" onchange="updatePolygonLayer()" />
<input type="checkbox" id="FillColorTransparent" onclick="updatePolygonLayer()" />Transparent
</td>
</tr>
<tr title="The color gradient expression to colorize the heat map.">
<td><input name="fillGroup" type="radio" onclick="updatePolygonLayer()" />Fill Pattern:</td>
<td>
<div class="dropdown">
<button id="fillPatternBtn" onclick="toggleFillPatternDropdown()" class="dropbtn"></button>
<div id="fillPatternDropdown" class="dropdown-content">
</div>
</div>
</td>
</tr>
<tr title="A number between 0 and 1 that indicates the opacity at which the fill will be drawn.">
<td>Fill Opacity:</td>
<td>
<form oninput="o.value=FillOpacity.value">
<input type="range" id="FillOpacity" value="0.9" min="0" max="1" step="0.1" oninput="updatePolygonLayer()" onchange="updatePolygonLayer()" />
<output name="o" for="FillOpacity">0.9</output>
</form>
</td>
</tr>
<tr title="Specifies the frame of reference for `translate`.">
<td>Translate Anchor:</td>
<td>
<select id="TranslateAnchor" onchange="updatePolygonLayer()">
<option value="map">map</option>
<option value="viewport" selected="selected">viewport</option>
</select>
</td>
</tr>
<tr title="The polygons' pixel offset.">
<td>Translate:</td>
<td></td>
</tr>
<tr title="Specifies an offset distance of the polygon in pixels. Positive values indicate right and down, while negative values indicate left and up. Each component is multiplied by the value of size to obtain the final offset in pixels. When combined with rotation the offset will be as if the rotated direction was up.">
<td align="right">x:</td>
<td>
<form oninput="x.value=TranslateX.value">
<input type="range" id="TranslateX" value="0" min="-50" max="50" step="1" oninput="updatePolygonLayer()" onchange="updateSymbolLayer()" />
<output name="x" for="TranslateX">0</output>
</form>
</td>
</tr>
<tr title="Specifies an offset distance of the polygon in pixels. Positive values indicate right and down, while negative values indicate left and up. Each component is multiplied by the value of size to obtain the final offset in pixels. When combined with rotation the offset will be as if the rotated direction was up.">
<td align="right">y:</td>
<td>
<form oninput="y.value=TranslateY.value">
<input type="range" id="TranslateY" value="0" min="-50" max="50" step="01" oninput="updatePolygonLayer()" onchange="updateSymbolLayer()" />
<output name="y" for="TranslateY">0</output>
</form>
</td>
</tr>
<tr title="Specifies if the polygon should have a vertical gradient on the sides of the extrusion.">
<td>Vertical Gradient:</td>
<td><input id="VerticalGradient" type="checkbox" onclick="updatePolygonLayer()" checked="checked" /></td>
</tr>
</table>
</div>
<div id="Code" class="tabcontent">
<textarea id="CodeOutput"></textarea><br /><br />
<input id="RemoveDefaults" type="checkbox" onclick="updatePolygonLayer()" checked="checked" /> Remove defaults
<button class="copyBtn" data-clipboard-target="#CodeOutput">Copy to clipboard</button>
</div>
</fieldset>
<div style="position:absolute;top:10px;left:10px;background-color:white;padding:5px;">
<input type="button" value="Play" onclick="animation.play()" />
<input type="button" value="Pause" onclick="animation.pause()" />
<input type="button" value="Stop" onclick="animation.stop()"/>
<input type="button" value="Reset" onclick="GetMap()"/>
</div>
<!-- <fieldset style="width:calc(100% - 30px);min-width:290px;margin-top:10px;">
<legend>Morph shape animation</legend>
This sample shows how to animate the morphing of a shape from one geometry to another.
This sample uses the open source <a href="https://github.com/Azure-Samples/azure-maps-animations" target="_blank">Azure Maps Animation module</a>
</fieldset> -->
<div id="myMap"></div>
<div>
<a href="https://www.deutschebahn.com/de/presse/pressestart_zentrales_uebersicht/Automatisierte-Zugbildung-Gueterzuege-starten-kuenftig-deutlich-schneller-6868340">Automatisierte Zugbildung: Güterzüge starten künftig deutlich schneller</a>
</div>
</body>
</html>