-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.html
918 lines (806 loc) · 39.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
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
<!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>Refill</title>
<!-- 3rd party libraries -->
<!-- Leaflet -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.1/leaflet.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.1/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 -->
<script src="https://www.nextzen.org/tangram/0.16/tangram.min.js"></script>
<!-- production debug -->
<!-- <script src="https://www.nextzen.org/tangram/0.16/tangram.debug.js"></script> -->
<!-- dev -->
<!-- <script src="https://precog.mapzen.com/tangrams/tangram/master/dist/tangram.debug.js"></script> -->
<!-- dev branch -->
<!-- <script src="https://precog.mapzen.com/tangrams/tangram/multi-label-textures/dist/tangram.debug.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;
}
// So many themes
var theme_defaults = { color: 'black', detail: 10, label: 5 };
var all_theme_imports = { road_shields_usa: 'themes/refill-road-shields-usa.yaml',
road_shields_international: 'themes/refill-road-shields-international.yaml',
color: 'themes/color-' + theme_defaults.color + '.yaml',
label: 'themes/label-' + theme_defaults.label + '.yaml',
detail: 'themes/detail-' + theme_defaults.detail + '.yaml',
texture: '',
terrain: ''
};
var old_theme_imports = { road_shields_usa: 'themes/refill-road-shields-usa.yaml',
road_shields_international: 'themes/refill-road-shields-international.yaml',
color: 'themes/color-' + theme_defaults.color + '.yaml',
label: 'themes/label-' + theme_defaults.label + '.yaml',
detail: 'themes/detail-' + theme_defaults.detail + '.yaml',
texture: '',
terrain: ''
};
/*** 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 = 'refill-style.yaml';
var dev_or_prod = 'prod';
// prod
var sdk_api_key = 'NaqqS33fTUmyQcvbuIUCKA';
if( dev_or_prod == 'dev' ) {
sdk_api_key = '1YJOees7QwmlS0uYDTc8zg';
}
var tg_global = { 'sdk_api_key': sdk_api_key, 'sdk_bathymetry': false, 'sdk_coastline': true };
var layer = Tangram.leafletLayer({
// more: 'vector-tiles-TTucZYU'
// default (some): 'vector-tiles-W2tPU-Y'
// no: 'vector-tiles-haXTO7g'
scene: { import: [ tg_baseScene,
'themes/refill-road-shields-usa.yaml',
'themes/refill-road-shields-international.yaml',
'themes/color-' + theme_defaults.color + '.yaml',
'themes/label-' + theme_defaults.label + '.yaml',
'themes/detail-' + theme_defaults.detail + '.yaml' ],
global: tg_global },
attribution: '<a href="https://mapzen.com/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;
anchor.addEventListener('click', function (event) {
trackOutboundLink(url, 'mapzen_carto_debug', type);
}, false);
el.appendChild(anchor);
return el;
}
/**
* Function that tracks a click on an outbound link in Google Analytics.
* This function takes a valid URL string as an argument, and uses that URL string
* as the event label. Setting the transport method to 'beacon' lets the hit be sent
* using 'navigator.sendBeacon' in browser that support it.
*/
function trackOutboundLink (url, post_name, editor) {
// ga('send', 'event', [eventCategory], [eventAction], [eventLabel], [eventValue], [fieldsObject]);
ga('send', 'event', 'outbound', post_name, url, {
'transport': 'beacon',
// If opening a link in the current window, this opens the url AFTER
// registering the hit with Analytics. Disabled because here want the
// link to open in a new window, so this hit can occur in the current tab.
//'hitCallback': function(){document.location = url;}
});
}
// 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 = 'http://tile.';
if( dev_or_prod == 'dev' ) {
url += 'dev.';
}
url += 'nextzen.org/tilezen/vector/v1/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) {
tg_global['ux_language'] = value;
scene.config.global.ux_language = tg_global['ux_language'];
scene.updateConfig();
//window.location.search = 'language=' + value;
});
gui.fallback_lang = query.language_fallback || false;
gui.fallback_button = gui.add(gui, 'fallback_lang', langs).onChange(function(value) {
tg_global['ux_language_fallback'] = value;
scene.config.global.ux_language_fallback = tg_global['ux_language_fallback'];
scene.updateConfig();
//window.location.search = 'language=' + value;
});
gui.fallback_button.name('lang fallback');
// So many themes
var all_theme_imports = { road_shields_usa: 'themes/refill-road-shields-usa.yaml',
road_shields_international: 'themes/refill-road-shields-international.yaml',
detail: null,
label: null,
color: null };
function update_scene_with_themes() {
if( old_theme_imports.road_shields_usa === all_theme_imports.road_shields_usa &&
old_theme_imports.road_shields_international === all_theme_imports.road_shields_international &&
old_theme_imports.color === all_theme_imports.color &&
old_theme_imports.detail === all_theme_imports.detail &&
old_theme_imports.label === all_theme_imports.label &&
old_theme_imports.texture === all_theme_imports.texture &&
old_theme_imports.terrain === all_theme_imports.terrain ) {
//console.log( 'no change' );
} else {
//console.log( all_theme_imports, old_theme_imports );
// construct the import array
themes_as_array = [tg_baseScene];
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 );
}
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.detail ) {
themes_as_array.push( all_theme_imports.detail );
}
if( all_theme_imports.texture ) {
themes_as_array.push( all_theme_imports.texture );
}
if( all_theme_imports.terrain ) {
themes_as_array.push( all_theme_imports.terrain );
}
//console.log ( themes_as_array );
scene.load({ import: themes_as_array, global: tg_global });
old_theme_imports.road_shields_usa = all_theme_imports.road_shields_usa;
old_theme_imports.road_shields_international = all_theme_imports.road_shields_international;
old_theme_imports.color = all_theme_imports.color;
old_theme_imports.detail = all_theme_imports.detail;
old_theme_imports.label = all_theme_imports.label;
old_theme_imports.texture = all_theme_imports.texture;
old_theme_imports.terrain = all_theme_imports.terrain;
}
}
// label selector
gui.label = query.label || theme_defaults.label;
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;
});
// Level of Detail selector
gui.detail = query.detail || theme_defaults.detail;
gui.add(gui, 'detail', 0, 11).step(1).onChange(function(value) {
var import_theme = 'themes/detail-'+ value + '.yaml'
all_theme_imports.detail = import_theme;
update_scene_with_themes();
//window.location.color = 'color=' + 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/refill-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/refill-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();
});
// Color theme selector
var color = {
'(default)': 'black',
'black': 'black',
'high-contrast': 'high-contrast',
'gray': 'gray',
'COLOR - pink': 'pink',
'COLOR - blue': 'blue',
'COLOR - sepia': 'sepia',
'COLOR - pink-yellow': 'pink-yellow',
'COLOR - brown-orange': 'brown-orange',
'COLOR - blue-gray': 'blue-gray',
'DARK - inverted': 'inverted',
'DARK - inverted-dark': 'inverted-dark',
'DARK - purple-green': 'purple-green',
'DARK - gray-gold': 'gray-gold',
'DARK - zinc': 'zinc'
};
// use query language, else default to English
gui.color = query.color || theme_defaults.color;
gui.add(gui, 'color', color).onChange(function(value) {
var import_theme = 'themes/color-'+ value + '.yaml'
all_theme_imports.color = import_theme;
update_scene_with_themes();
//window.location.color = 'color=' + value;
});
// 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) {
tg_global['sdk_transit_overlay'] = (value === 'true' || value === true);
scene.config.global.sdk_transit_overlay = tg_global['sdk_transit_overlay']; // 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');
// Building extrusion selector
var building_3d = {
'(default)': true,
'Yes': true,
'No': false
};
gui.building_3d = query.building_3d || true;
gui.building_button = gui.add(gui, 'building_3d', building_3d).onChange(function(value) {
tg_global['sdk_building_extrude'] = (value === 'true' || value === true);
scene.config.global.sdk_building_extrude = tg_global['sdk_building_extrude']; // dat.gui passes a string
scene.updateConfig();
});
gui.building_button.name( '3D buildings' );
// Texture toggle
var texture = {
'(default)': true,
'Yes': true,
'No': false
};
gui.texture = query.texture || true;
gui.texture_button = gui.add(gui, 'texture', texture).onChange(function(value) {
//console.log( value );
if (value === 'false' || value === false) {
all_theme_imports.texture = 'themes/no-texture.yaml';
} else {
all_theme_imports.texture = '';
}
update_scene_with_themes();
});
gui.texture_button.name( 'texture' );
// Terrain toggle
var terrain = {
'(default)': false,
'None': false,
'Shading': 'shading',
'Shading - Dark': 'shading-dark',
'Pattern': 'pattern',
'Pattern - Dark': 'pattern-dark'
};
gui.terrain = query.terrain || false;
gui.terrain_button = gui.add(gui, 'terrain', terrain).onChange(function(value) {
//console.log( value );
updateTerrain(value);
});
(updateTerrain = function(value) {
if (value === 'shading' || value === 'shading-dark' || value === 'pattern' || value === 'pattern-dark') {
all_theme_imports.terrain = 'themes/terrain-' + value + '.yaml';
} else {
all_theme_imports.terrain = '';
}
update_scene_with_themes();
})(gui.terrain);
// Bathymetry selector
var bathymetry = {
'(default)': false,
'Yes': true,
'No': false
};
gui.bathymetry = query.bathymetry || false;
gui.bathymetry_button = gui.add(gui, 'bathymetry', bathymetry).onChange(function(value) {
tg_global['sdk_bathymetry'] = (value === 'true' || value === true);
scene.config.global.sdk_bathymetry = tg_global['sdk_bathymetry']; // dat.gui passes a string
scene.updateConfig();
});
gui.bathymetry_button.name( 'bathymetry' );
// Coastline selector
var coastline = {
'(default)': true,
'Yes': true,
'No': false
};
gui.coastline = query.coastline || true;
gui.coastline_button = gui.add(gui, 'coastline', coastline).onChange(function(value) {
tg_global['sdk_coastline'] = (value === 'true' || value === true);
scene.config.global.sdk_coastline = tg_global['sdk_coastline']; // dat.gui passes a string
scene.updateConfig();
});
gui.coastline_button.name( 'coastline' );
// Routing selector
var sdk_directions = {
'(default)': false,
'Hide': false,
'Car': 'car',
'Transit': 'transit',
'Bike': 'bike'
};
gui.sdk_directions = query.sdk_directions || false;
gui.directions_button = gui.add(gui, 'sdk_directions', sdk_directions).onChange(function(value) {
if( value === 'bike' ) {
scene.config.sources.mz_route_line = {};
scene.config.sources.mz_route_line_transit = {};
scene.config.sources.mz_dash_line = {};
scene.config.sources.mz_route_line_bicycle = { type: 'GeoJSON', url: 'https://gist.githubusercontent.com/nvkelso/8a066359dbe7e773926fe01c44c793d4/raw/d32bbf3221a8d8ef47cf22de706768a92ed645d9/map.geojson' }
scene.config.global.sdk_bike_network_overlay = false;
} else if( value === 'transit') {
scene.config.sources.mz_route_line = {};
scene.config.sources.mz_route_line_transit = { type: 'GeoJSON', url: 'https://gist.githubusercontent.com/anonymous/71ae88cbc6d62c4d141ecd6a61060050/raw/2254bbc18243f5dc609e663a580c9412a7447936/map.geojson' }
scene.config.sources.mz_dash_line = { type: 'GeoJSON', url: 'https://gist.githubusercontent.com/anonymous/d73b851c64c3e5fbfc2754aa32f44c10/raw/938ae435776e176919c4797bed1465a92e403ef3/map.geojson' }
scene.config.sources.mz_route_line_bicycle = {};
} else if( value === 'car') {
scene.config.sources.mz_route_line = { type: 'GeoJSON', url: 'https://gist.githubusercontent.com/anonymous/9a610ebda6fe4be7bccc/raw/8d217e43f2412d48d01534ba115f1e42dac72e68/map.geojson' }
scene.config.sources.mz_route_line_transit = {}
scene.config.sources.mz_dash_line = {}
scene.config.sources.mz_route_line_bicycle = {};
} else {
scene.config.sources.mz_route_line = {};
scene.config.sources.mz_route_line_transit = {};
scene.config.sources.mz_dash_line = {};
scene.config.sources.mz_route_line_bicycle = {}
scene.config.global.sdk_bike_network_overlay = true;
}
scene.updateConfig();
});
gui.directions_button.name('directions');
// // 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 {
var url = 'https://www.openstreetmap.org/edit?';
if (!selection || selection.feature == null || selection.feature.properties == null) {
picking = false;
popup.style.visibility = 'hidden';
return;
}
//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) {
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;
var josmUrl = 'http://www.openstreetmap.org/edit?editor=remote#map='+position;
popup.appendChild(createEditLinkElement( url, 'iD', 'Edit with iD ➹') );
popup.appendChild(createEditLinkElement( mapzenTileURL(), 'rawTile', 'View tile data ➹') );
//popup.appendChild(createEditLinkElement( josmUrl, 'JOSM', 'Edit with JOSM ➹') );
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>