-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.html
executable file
·780 lines (681 loc) · 31.1 KB
/
index.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
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
<!doctype html>
<!--
Tangram: real-time WebGL rendering for OpenStreetMap
http://github.com/tangrams/tangram
http://mapzen.com
-->
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Bubble Wrap</title>
<!-- 3rd party libraries -->
<!-- Leaflet -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.4.0/leaflet.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.4.0/leaflet.js"></script>
<!-- bog-standard leaflet URL hash -->
<script type="text/javascript" src="https://cdn.rawgit.com/mlevans/leaflet-hash/master/leaflet-hash.js"></script>
<!-- Main tangram library -->
<!-- production npm -->
<!-- <script src="https://unpkg.com/tangram@latest/dist/tangram.min.js"></script> -->
<!-- production nextzen -->
<script src="https://www.nextzen.org/tangram/0.19/tangram.min.js"></script>
<!-- production debug -->
<!-- <script src="https://mapzen.com/tangram/0.19/tangram.debug.js"></script> -->
<!-- dev -->
<!-- <script src="https://line-label-repeats--tangram.netlify.com/dist/tangram.debug.js"></script> -->
<!-- <script src="https://precog.mapzen.com/tangrams/tangram/master/dist/tangram.debug.js"></script> -->
<!-- dev branch -->
<!-- <script src="https://precog.mapzen.com/tangrams/tangram/oriented-lines-rebase/dist/tangram.min.js"></script> -->
<!-- A lightweight graphical user interface for changing variables in JavaScript. -->
<script type="text/javascript" src="lib/dat.gui.min.js"></script>
<!-- FileSaver.js implements the HTML5 W3C saveAs(), used in the demo to save screenshots -->
<script type="text/javascript" src="lib/FileSaver.js"></script>
<!-- Keymaster handles keyboard input -->
<script type="text/javascript" src="lib/keymaster.js"></script>
<!-- End of 3rd party libraries -->
<style>
body {
margin: 0px;
border: 0px;
padding: 0px;
}
#map {
background: rgba(0, 0, 0, 0);
height: 100%;
width: 100%;
position: absolute;
}
.label {
width: auto;
/*margin-left: -100px;*/
position: absolute;
z-index: 500;
text-align: left;
margin: 10px;
/*background: #E1E1E1;*/
background: rgba(3,3,3,0.6);
opacity: 0.9;
padding: 2px;
visibility: hidden;
/*text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;*/
/*word-wrap: break-word;*/
}
.label a {
color: white;
}
.label a:hover {
color: lightblue;
}
.labelInner {
padding: 3px 0px;
font-family: Helvetica, sans-serif;
font-weight: bold;
font-size: 12px;
color: white;
opacity: 2.0;
margin: 0px;
}
.labelLine {
/*border: 2px solid gold;*/
}
.labelLine:hover {
/* border: 2px solid gold; */
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
cursor: default;
}
.title {
text-align: center;
font-weight: bold;
color: white;
margin-left: 6px;
}
hr {
border: 0;
height: 1px;
background: rgba(255,255,255,0.5);
}
.coorner {
position: absolute;
background-color: rgba(255,255,255,0.0);
width: 10px;
height: 10px;
z-index: 103;
}
div#coorner-top-left {
top: -2px;
left: -2px;
border-top: 2px solid rgba(255,255,255,0.7);
border-left: 2px solid rgba(255,255,255,0.7);
}
div#coorner-top-right {
top: -2px;
right: -2px;
border-top: 2px solid rgba(255,255,255,0.7);
border-right: 2px solid rgba(255,255,255,0.7);
}
div#coorner-bottom-left {
bottom: -2px;
left: -2px;
border-bottom: 2px solid rgba(255,255,255,0.7);
border-left: 2px solid rgba(255,255,255,0.7);
}
div#coorner-bottom-right {
bottom: -2px;
right: -2px;
border-bottom: 2px solid rgba(255,255,255,0.7);
border-right: 2px solid rgba(255,255,255,0.7);
}
</style>
</head>
<body>
<div class="label" id="popup"></div>
<div id="map"></div>
<!-- Demo module -->
<script>
/*** URL parsing ***/
var animated = true;
var url_search = window.location.search.slice(1);
if (url_search.length > 0) {
if (url_search.indexOf('animated=false') > -1) {
animated = false;
}
}
// location
var url_hash = window.location.hash.slice(1).split('/'); // map location as #z/x/y
var map_start_location = [37.7926, -122.4003, 15]; // San Francisco
var defaultpos = true; // use default position
// location is passed through url
if (url_hash.length == 3) {
var defaultpos = false;
if (url_hash[1] > 180) { // parse hash as tile coordinates
// example: http://localhost:9001/#15/5242/12663
// add .5 to coords to center tile on screen
map_start_location = [tile2lat(parseFloat(url_hash[2]) + .5, url_hash[0]), tile2long(parseFloat(url_hash[1]) + .5, url_hash[0]), url_hash[0]];
}
else { // parse hash as lat/lng coordinates
map_start_location = [url_hash[1],url_hash[2], url_hash[0]];
// convert from strings
map_start_location = map_start_location.map(Number);
}
}
// enable setting language by URL argument
// eg: '?language=en&this=no'
var query = splitQueryParams();
// { language: 'en', this: 'no'}
function splitQueryParams () {
var str = window.location.search;
var kvArray = str.slice(1).split('&');
// ['language=en', 'this=no']
var obj = {};
for (var i = 0, j=kvArray.length; i<j; i++) {
var value = kvArray[i].split('=');
var k = window.decodeURIComponent(value[0]);
var v = window.decodeURIComponent(value[1]);
obj[k] = v;
}
return obj;
}
/*** Map ***/
var map = L.map('map',
{"keyboardZoomOffset" : .05, maxZoom: 20, "scrollWheelZoom": false }
);
map.setView(map_start_location.slice(0, 2), map_start_location[2]);
var tg_baseScene = 'bubble-wrap-style.yaml';
var dev_or_prod = 'prod';
// prod
var sdk_api_key = '-ZTNBBKCS5WZa62pfZyUkA';
if( dev_or_prod == 'dev' ) {
sdk_api_key = '1YJOees7QwmlS0uYDTc8zg';
}
var tg_global = { sdk_api_key: sdk_api_key };
var layer = Tangram.leafletLayer({
scene: { import: [ tg_baseScene,
'themes/bubble-wrap-road-shields-usa.yaml',
'themes/bubble-wrap-road-shields-international.yaml'],
global: tg_global },
attribution: '<a href="https://github.com/tangrams/tangram" target="_blank">Tangram</a>, © OSM contributors'
});
var scene = layer.scene;
var latlng = {};
var popup = document.getElementById('popup'); // click-popup
var hash = new L.Hash(map);
function updateKey(value) {
keytext = value;
for (layer in scene.config.layers) {
if (layer == "earth") continue;
scene.config.layers[layer].properties.key_text = value;
}
scene.rebuildGeometry();
scene.requestRedraw();
}
function updateValue(value) {
valuetext = value;
for (layer in scene.config.layers) {
if (layer == "earth") continue;
scene.config.layers[layer].properties.value_text = value;
}
scene.rebuildGeometry();
scene.requestRedraw();
}
window.addEventListener('load', function () {
// Scene initialized
layer.scene.subscribe({
load: function (data) {
data.config.global.sdk_animated = animated;
}
});
layer.addTo(map);
});
// Feature selection
var picking = false;
function initFeatureSelection () {
layer.setSelectionEvents({
hover: function(selection) {
if (!picking) {
if (!selection || selection.feature == null || selection.feature.properties == null) {
picking = false;
popup.style.visibility = 'hidden';
return;
}
var properties = selection.feature.properties;
popup.style.width = 'auto';
popup.style.left = (selection.pixel.x + 0) + 'px';
popup.style.top = (selection.pixel.y + 0) + 'px';
popup.style.margin = '10px';
if (properties.name) {
popup.innerHTML = '<span class="labelInner">' + properties.name + '</span><br>';
} else {
popup.innerHTML = '<span class="labelInner">' + 'unnamed ' + properties.kind + '</span><br>';
}
popup.innerHTML += '<span class="labelInner" style="font-size:10px;">' + 'Click to view more...' + '</span><br>';
popup.style.visibility = 'visible';
}
}
});
}
function createEditLinkElement (url, type, label) {
var el = document.createElement('div');
var anchor = document.createElement('a');
el.className = 'labelInner';
anchor.href = url;
anchor.target = '_blank';
anchor.textContent = label;
el.appendChild(anchor);
return el;
}
// convert tile coordinates to lat-lng
// from http://gis.stackexchange.com/questions/17278/calculate-lat-lon-bounds-for-individual-tile-generated-from-gdal2tiles
function tile2long(x,z) { return (x/Math.pow(2,z)*360-180); }
function tile2lat(y,z) {
var n=Math.PI-2*Math.PI*y/Math.pow(2,z);
return (180/Math.PI*Math.atan(0.5*(Math.exp(n)-Math.exp(-n))));
}
function long2tile(lon,zoom) { return (Math.floor((lon+180)/360*Math.pow(2,zoom))); }
function lat2tile(lat,zoom) { return (Math.floor((1-Math.log(Math.tan(lat*Math.PI/180) + 1/Math.cos(lat*Math.PI/180))/Math.PI)/2 *Math.pow(2,zoom))); }
function mapzenTileURL() {
// find minimum max_zoom of all sources
var max_zoom = 16;
for (source in scene.config.sources) {
if (scene.config.sources.hasOwnProperty(source)) {
if (scene.config.sources[source].max_zoom != "undefined") {
max_zoom = Math.min(max_zoom, scene.config.sources[source].max_zoom);
}
}
}
var zoom = max_zoom < map.getZoom() ? max_zoom : Math.floor(map.getZoom());
var tileCoords = { x : long2tile(latlng.lng,zoom), y: lat2tile(latlng.lat,zoom), z: zoom };
var url = 'https://tile.nextzen.org/tilezen/vector/v1/512/all/' + zoom + '/' + tileCoords.x + '/' + tileCoords.y + '.topojson' + '?api_key=' + sdk_api_key;
return url;
}
/***** Render loop *****/
// Create dat GUI
var gui = new dat.GUI({ autoPlace: true });
function addGUI() {
gui.domElement.parentNode.style.zIndex = 10000;
window.gui = gui;
// Language selector
var langs = {
'(default)': false,
'العربية (Arabic)': 'ar',
'中文 (Chinese)': 'zh',
'English': 'en',
'français (French)': 'fr',
'Русский (Russian)': 'ru',
'español (Spanish)': 'es',
'বাংলা (Bengali)': 'bn',
'Deutsch (German)': 'de',
'ελληνικά (Greek)': 'el',
'हिन्दी (Hindi)': 'hi',
'Bahasa Indonesia (Indonesian)': 'id',
'italiano (Italian)': 'it',
'日本語 (Japanese)': 'ja',
'한국어 (Korean)': 'ko',
'Português (Portuguese)': 'pt',
'Türkçe (Turkish)': 'tr',
'Tiếng Việt (Vietnamese)': 'vi'
};
// use query language, else default to English
gui.language = query.language || false;
gui.add(gui, 'language', langs).onChange(function(value) {
scene.config.global.ux_language = value;
scene.updateConfig();
//window.location.search = 'language=' + value;
});
gui.fallback_lang = query.language || false;
gui.fallback_button = gui.add(gui, 'fallback_lang', langs).onChange(function(value) {
scene.config.global.ux_language_fallback = value;
scene.updateConfig();
//window.location.search = 'language=' + value;
});
gui.fallback_button.name('lang fallback');
// POV (point of view) selector
var pov = {
'(default)': false,
'ISO': 'iso',
'Argentina': 'ar',
'Bangladesh': 'bd',
'Brazil': 'br',
'China': 'cn',
'Egypt': 'eg',
'France': 'fr',
'Germany': 'de',
'Greece': 'gr',
'India': 'in',
'Indonesia': 'id',
'Israel': 'il',
'Italy': 'it',
'Japan': 'jp',
'Morocco': 'ma',
'Nepal': 'np',
'Netherlands': 'nl',
'Pakistan': 'pk',
'Palestine': 'ps',
'Poland': 'pl',
'Portugal': 'pt',
'Russia': 'ru',
'Saudi Arabia': 'sa',
'South Korea': 'ko',
'South Africa': 'za', // this isn't supported
'Spain': 'es',
'Sweden': 'se',
'Taiwan': 'tw',
'Turkey': 'tr',
'Ukraine': 'ua',
'United Kingdom': 'gb',
'United States': 'us',
'Vietnam': 'vn'
};
// use query POV, else default to defacto + most the disputed lines
gui.pov = query.pov || false;
gui.add(gui, 'pov', pov).onChange(function(value) {
scene.config.global.ux_point_of_view = value;
scene.updateConfig();
});
gui.fallback_pov = query.pov || false;
gui.pov_fallback_button = gui.add(gui, 'fallback_pov', pov).onChange(function(value) {
scene.config.global.ux_point_of_view_fallback = value;
scene.updateConfig();
});
gui.pov_fallback_button.name('pov fallback');
// So many themes
var all_theme_imports = { color: null,
detail: null,
label: null,
road_shields_usa: 'themes/bubble-wrap-road-shields-usa.yaml',
road_shields_international: 'themes/bubble-wrap-road-shields-international.yaml' };
function update_scene_with_themes() {
//console.log( all_theme_imports );
// construct the import array
themes_as_array = [tg_baseScene];
if( all_theme_imports.color ) {
themes_as_array.push( all_theme_imports.color );
}
if( all_theme_imports.label ) {
themes_as_array.push( all_theme_imports.label );
}
if( all_theme_imports.road_shields_usa ) {
themes_as_array.push( all_theme_imports.road_shields_usa );
}
if( all_theme_imports.road_shields_international ) {
themes_as_array.push( all_theme_imports.road_shields_international );
}
scene.load({ import: themes_as_array, global: tg_global });
//console.log( scene.config );
scene.updateConfig();
//scene.rebuild();
}
// Labels selector
gui.label = query.label || 5;
gui.add(gui, 'label', 0, 11).step(1).onChange(function(value) {
var import_theme = 'themes/label-'+ value + '.yaml'
all_theme_imports.label = import_theme;
update_scene_with_themes();
//window.location.search = 'language=' + value;
});
// Enable/disable USA state road shields
var shields_usa = 'USA shields';
gui[shields_usa] = true;
gui.add(gui, shields_usa).onChange(function(value) {
var import_theme = 'themes/bubble-wrap-road-shields-usa.yaml'
if( value ) {
all_theme_imports.road_shields_usa = import_theme;
} else {
all_theme_imports.road_shields_usa = null;
}
update_scene_with_themes();
});
// Enable/disable international road shields
var shields_international = 'International shields';
gui[shields_international] = true;
gui.add(gui, shields_international).onChange(function(value) {
var import_theme = 'themes/bubble-wrap-road-shields-international.yaml'
if( value ) {
all_theme_imports.road_shields_international = import_theme;
} else {
all_theme_imports.road_shields_international = null;
}
update_scene_with_themes();
});
// Transit selector
var transit_overlay = {
'(default)': false,
'Show': true,
'Hide': false
};
// use transit ux, else default to false
gui.transit_overlay = query.transit_overlay || false;
gui.transit_button = gui.add(gui, 'transit_overlay', transit_overlay).onChange(function(value) {
scene.config.global.sdk_transit_overlay = (value === 'true' || value === true); // dat.gui passes a string
if (value === 'true' || value === true) {
scene.config.global.sdk_road_shields = false;
} else {
if( scene.config.global.text_visible_roads ) {
scene.config.global.sdk_road_shields = true;
}
}
scene.updateConfig();
});
gui.transit_button.name('transit');
// Toll Road selector
var toll_roads = 'Toll roads';
gui[toll_roads] = false;
gui.add(gui, toll_roads).onChange(function(value) {
scene.config.global.sdk_toll_road_overlay = (value === 'true' || value === true); // dat.gui passes a string
if (value === 'true' || value === true) {
scene.config.global.sdk_toll_road_overlay = true;
} else {
scene.config.global.sdk_toll_road_overlay = false;
}
scene.updateConfig();
});
// Heavy Goods Vehicle selector
var hgv = 'HGV restriction';
gui[hgv] = false;
gui.add(gui, hgv).onChange(function(value) {
scene.config.global.hgv_overlay = (value === 'true' || value === true); // dat.gui passes a string
if (value === 'true' || value === true) {
scene.config.global.sdk_hgv_overlay = true;
} else {
scene.config.global.sdk_hgv_overlay = false;
}
scene.updateConfig();
});
// Building extrusion selector
var building_3d = {
'(default)': true,
'Yes': true,
'No': false
};
// use transit ux, else default to false
gui.building_3d = query.building_3d || true;
gui.building_button = gui.add(gui, 'building_3d', building_3d).onChange(function(value) {
scene.config.global.sdk_building_extrude = (value === 'true' || value === true); // dat.gui passes a string
scene.updateConfig();
});
gui.building_button.name( '3D buildings' );
//
// // Animation selector
// var animated = {
// '(default)': true,
// 'Yes': true,
// 'No': false
// };
// gui.animated = query.animated || true;
// gui.add(gui, 'animated', animated).onChange(function(value) {
// scene.config.global.sdk_animated = (value === 'true' || value === true); // dat.gui passes a string
// scene.updateConfig();
// //window.location.search = 'animated=' + value;
// });
// Enable/disable interactivity for all features
var interactive_label = 'interactive';
gui[interactive_label] = false;
gui.add(gui, interactive_label).onChange(function(value) {
scene.setIntrospection(value);
});
scene.setIntrospection(gui[interactive_label]);
// Take a screenshot and save to file
gui.save_screenshot = function () {
return scene.screenshot().then(function(screenshot) {
// uses FileSaver.js: https://github.com/eligrey/FileSaver.js/
timestamp = new Date();
month = timestamp.getMonth()+1;
if( month < 10 ) { month = '0' + month; }
prettydate = timestamp.getFullYear() + month + timestamp.getDate() + timestamp.getHours() + timestamp.getMinutes();
map_location = map.getZoom() + '-' + map.getCenter().lat.toFixed(5) + '-' + map.getCenter().lng.toFixed(5);
saveAs(screenshot.blob, 'tangram-' + map_location + '-' + prettydate + '.png');
});
};
gui.screenshot = gui.add(gui, 'save_screenshot');
gui.screenshot.name('save screenshot');
// Take a video capture and save to file
if (typeof window.MediaRecorder == 'function') {
gui.video = function () {
if (!gui.video_capture) {
if (scene.startVideoCapture()) {
gui.video_capture = true;
gui.video_button.name('stop video');
}
}
else {
return scene.stopVideoCapture().then(function(video) {
gui.video_capture = false;
gui.video_button.name('capture video');
saveAs(video.blob, 'tangram-video-' + (+new Date()) + '.webm');
});
}
};
gui.video_button = gui.add(gui, 'video');
gui.video_button.name('capture video');
gui.video_capture = false;
}
// Link to edit in OSM - hold 'e' and click
map.getContainer().addEventListener('dblclick', function (event) {
//console.log( 'dblclick was had' );
if( timer ) { clearTimeout( timer ); timer = null; }
popup.style.visibility = 'hidden';
});
var timer;
map.getContainer().addEventListener('mousemove', function (event) {
picking = false;
popup.style.visibility = 'hidden';
return;
});
layer.setSelectionEvents({
click: function(selection) {
if( timer ) { clearTimeout( timer ); timer = null; }
timer = setTimeout( function() {
picking = true;
latlng = selection.leaflet_event.latlng;
if( key.cmd || key.alt ) {
window.open( mapzenTileURL(), '_blank' );
} else {
if (!selection || selection.feature == null || selection.feature.properties == null) {
picking = false;
popup.style.visibility = 'hidden';
return;
}
var url = 'https://www.openstreetmap.org/edit?';
//console.log(selection.feature, selection.changed);
// enable iD to show properties sidebar for selected feature
osm_type = 'node';
osm_zoom = '19'
// tilezen adds sort_rank for any way or relation thing, but because we generate
// label positions for area features, we need to do two tests
if( selection.feature.properties.sort_rank || selection.feature.properties.area ) {
osm_type = 'way';
osm_zoom = Math.max( 17, map.getZoom() );
}
osm_id = selection.feature.properties.id;
if( osm_id < 0 ) {
osm_type = 'relation'
osm_id = Math.abs( osm_id );
// zoom out a bit because we assume this is a larger feature
// but don't zoom out too far, as iD breaks
osm_zoom = Math.max( 16, map.getZoom() );
}
url += osm_type + '=' + osm_id;
// and position the map so it's at a similar zoom to Tangram
if (latlng) {
url += '#map=' + osm_zoom + '/' + latlng.lat + '/' + latlng.lng;
}
if( key.shift ) {
window.open(url, '_blank');
} else {
var properties = selection.feature.properties;
var label = '';
//console.log(properties);
for (var x in properties) {
var val = properties[x]
label += "<span class='labelLine' key="+x+" value="+val+"'>"+x+" : "+val+"</span><br>"
}
var layers = selection.feature.layers;
label += "<span class='labelLine'>Layers:</span><br>"
layers.forEach(function(val) {
if( !val.includes("name:") ) {
label += "<span class='labelLine' value="+val+"'> "+val+"</span><br>"
}
});
if (label != '') {
popup.style.left = (selection.pixel.x) + 'px';
popup.style.top = (selection.pixel.y) + 'px';
popup.style.margin = '0px';
popup.innerHTML = '<span class="labelInner">' + label + '</span>';
}
// JOSM editor link
var position = '19' + '/' + latlng.lat + '/' + latlng.lng;
if( selection.feature.properties.source == 'whosonfirst.mapzen.com' ) {
var wofUrl = 'https://www.whosonfirst.org/boundaryissues/id/'+selection.feature.properties.id+'/';
popup.appendChild(createEditLinkElement( wofUrl, 'WOF', 'Edit with Boundary Issues ➹') );
} else {
popup.appendChild(createEditLinkElement( url, 'iD', 'Edit with iD ➹') );
//var josmUrl = 'http://www.openstreetmap.org/edit?editor=remote#map='+position;
//popup.appendChild(createEditLinkElement( josmUrl, 'JOSM', 'Edit with JOSM ➹') );
}
popup.appendChild(createEditLinkElement( mapzenTileURL(), 'rawTile', 'View tile data ➹') );
popup.style.visibility = 'visible';
}
}
timer = null;
}, 200 );
}
});
}
function inIframe () {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
// Add map
window.addEventListener('load', function () {
// Scene initialized
layer.on('init', function() {
var camera = scene.config.cameras[scene.getActiveCamera()];
// if a camera position is set in the scene file, use that
if (defaultpos && typeof camera.position != "undefined") {
map_start_location = [camera.position[1], camera.position[0], camera.position[2]]
}
map.setView([map_start_location[0], map_start_location[1]], map_start_location[2]);
if (!inIframe()) {
addGUI();
}
});
if (!inIframe()) {
map.scrollWheelZoom.enable();
initFeatureSelection();
}
function addToMap () {
layer.addTo(map);
}
});
</script>
</body>
</html>