-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
executable file
·724 lines (651 loc) · 26.5 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
<!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>Morphology</title>
<!-- Mapzen JS & styleguide -->
<link rel="stylesheet" href="https://www.nextzen.org/js/nextzen.css" />
<link rel="stylesheet" href="https://www.nextzen.org/styleguide.min.css">
<script src="https://www.nextzen.org/js/nextzen.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>
<style>
body {
margin: 0px;
padding: 0px;
}
.form-container {
width: 320px;
padding: 6px 21px 6px 6px;
border-radius: 5px;
background: rgba(255, 255, 255, 0.8);
border: 2px solid rgba(0,0,0,0.2);;
box-sizing: content-box;
}
@media screen and (max-width: 768px) {
.leaflet-right .form-container {
margin-top: 60px;
}
}
.form-container select {
font-size: 14px;
}
.form-container .btn{
width: calc(50% - 5px);
}
.form-container label {
font-size: 14px;
padding-top: 6px;
padding-bottom: 6px;
}
#map {
height: 100%;
width: 100%;
}
.label {
width: auto;
border-radius: 6px;
position: absolute;
z-index: 500;
text-align: left;
margin: 10px;
/*background: #E1E1E1;*/
background: rgba(30, 14, 51,0.8);
opacity: 0.9;
padding: 6px;
display: none;/
}
.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: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;
}
</style>
</head>
<body>
<div id="map"></div>
<div class="label" id="popup"></div>
<script>
// for hash
var Formatter = {
parseHashToObj: function (_rawHash) {
var dObj = {};
var rawHash = _rawHash || window.location.hash;
if (this.isEmpty(rawHash)) {
return null;
} else {
var hashVal = rawHash.replace('#', '');
var valArrs = hashVal.split('&');
for (var val in valArrs) {
var keyAndValue = valArrs[val].split('=');
dObj[keyAndValue[0]] = decodeURIComponent(keyAndValue[1]);
}
return dObj;
}
},
isEmpty: function (str) {
if (str.length === 0 || !str) return true;
else return false;
}
};
// Form theme selector
var form = {
'morphology (default)': 'morphology',
'airports z9+': 'airports',
'bridges z13+': 'bridges',
'bridges + water': 'bridges-water',
'bridges + tunnels': 'bridges-tunnels',
'bridges + tunnels + transit': 'bridges-tunnels-transit',
'buildings z13+': 'buildings',
'canals z9+': 'canals',
'canals + water': 'canals-water',
'citywalls': 'citywalls',
'coastlines single': 'coastlines-single',
'coastlines outline': 'coastlines-outline',
'coastlines animated z13+': 'coastlines-animated',
'earth': 'earth',
'farms': 'farms',
'green': 'green',
'industrial': 'industrial',
'labels': 'labels',
'libraries': 'libraries',
'links': 'links',
'parking': 'parking',
'piers z13+': 'piers',
'piers + water': 'piers-water',
'place of worship z14+': 'place-of-worship',
'quarries': 'quarries',
'racetracks z13+': 'racetracks',
'rail z11+': 'rail',
'roads z5+': 'roads',
'schools z13+': 'schools',
'ski z13+': 'ski',
'transit z8+': 'transit',
'tunnels z13+': 'tunnels',
'water': 'water'
};
// Form theme selector
var bookmark = {
'select one': "14,37.6193,-122.3763",
'airports - APC': "15,38.21541,-122.27798",
'airports - DFW': "14,32.8963,-97.0399",
'airports - Florida': "11,30.5806,-86.7404",
'airports - IST': "14,40.9811,28.8154",
'airports - MHV': "14,35.0578,-118.1499",
'airports - NY': "11,40.7527,-74.0444",
'airports - ORD': "13.7,41.9792,-87.9050",
'airports - SAN': "15,32.73269,-117.19196",
'airports - SBA': "15,34.42505,-119.84155",
'airports - SFO': "14,37.6193,-122.3763",
'airports - YUL': "14,45.47112,-73.74047",
'bridges - Alexandria': "17,38.79381,-77.05581",
'bridges - Amsterdam': "14,52.3722,4.8959",
'bridges - Berlin z16': "16,52.5191,13.3971",
'bridges - Berlin z17': "17,52.52368,13.36962",
'bridges - Cairo': "13,30.0322,31.2262",
'bridges - Cape Town': "19,-33.90727,18.41098",
'bridges - Hamburg': "14,53.5379,10.0261",
'bridges - Newark z15': "15,40.71339,-74.14428",
'bridges - Neward z17': "17.5,40.74342,-74.15674",
'bridges - Philadelphia': "15,39.9566,-75.1638",
'bridges - Pittsburgh': "14,40.4430,-79.9979",
'bridges - Portland z15': "15,45.5203,-122.6669",
'bridges - Portland z17': "17,45.51814,-122.66716",
'bridges - Prague': "17.25,50.11425,14.44576",
'bridges - Shanghai': "17,31.14043,121.53223",
'bridges - Sinagpore': "16,1.2906,103.8644",
'bridges - Sydney': "16,-33.8560,151.2088",
'bridges - Venice': "17.5,45.43723,12.34008",
'bridges - Vienna': "19.5,48.20985,16.38432",
'buildings - Amsterdam': "16,52.3127,4.6612",
'buildings - Barcelona': "17,41.39208,2.15853",
'buildings - Brooklyn': "16.8,40.64056,-74.00848",
'buildings - Chevy Chase': "17.5,38.96326,-77.06675",
'buildings - Dhaka': "16.3,23.73261,90.33955",
'buildings - Hongkong': "16.2,22.28437,114.21678",
'buildings - Kolkata': "17,22.48150,88.36739",
'buildings - LA z17': "17,33.76991,-118.08559",
'buildings - LA z18': "18,33.84349,-118.15802",
'buildings - Lucca': "15.75,43.8443,10.5063",
'buildings - Manhattan': "17,40.75810,-73.97171",
'buildings - Manila': "18,14.50248,121.06074",
'buildings - Moscow': "16,55.7951,37.7985",
'buildings - Nördlingen': "16,48.8516,10.4891",
'buildings - Paris': "16,48.87271,2.29738",
'buildings - Phoenix': "18,33.44883,-112.07590",
'buildings - Stockholm': "16.25,59.34326,18.04132",
'buildings - Tallinn': "15,59.4357,24.7449",
'buildings - Toledo': "16,39.8583,-4.0258",
'buildings - Wash D.C.': "16.5,38.95434,-77.02126",
'canals - Bergamo': "13,45.6954,9.6673",
'canals - Fort Lauderdale': "12.75,26.2736,-80.2122",
'canals - Nagoya': "10,35.1002,136.9446",
'canals - Santos': "13.5,-23.9617,-46.3240",
'canals - South Florida': "9,26.2090,-80.3319",
'canals - Yanagawa': "15,33.1633,130.4037",
'citywalls - Cairo': "17,30.02947,31.26170",
'citywalls - Jerusalem': "16,31.77842,35.23193",
'citywalls - London': "18,51.50809,-0.07619",
'citywalls - Nicosia': "15.5,35.1762,33.3638",
'citywalls - Niterói': "19,-22.93798,-43.13349",
'farms - California': "14,38.2167,-121.2146",
'farms - Cerro Punta': "13,8.8579,-82.5837",
'farms - Hamburg': "15,53.62630,8.97976",
'farms - Nevada': "16,37.57554,-117.95240",
'farms - Nicaragua': "14,11.0619,-84.5882",
'farms - Utah': "15,40.1054,-111.9573",
'green - Barcelona': "15.5,41.4176,2.1594",
'green - Delhi': "16.75,28.59322,77.24909",
'green - London': "18.5,51.51650,-0.14510",
'green - Munich': "15.5,48.1279,11.6968",
'green - San Diego': "17,32.76558,-117.22644",
'green - San Francisco': "20,37.80210,-122.41881",
'green - Saint Petersburg': "18,59.93850,30.29247",
'green - Santiago': "15.25,-33.6037,-70.5496",
'green - Toronto': "14,43.7053,-79.3358",
'green - Versailles': "15,48.8100,2.1010",
'green - Vienna': "17,48.18245,16.30911",
'industrial - Jakarta': "17.5,-6.11008,106.90324",
'industrial - Karachi': "17.5,24.81239,66.97991",
'industrial - Le Havre': "16,49.47547,0.55098",
'industrial - Linden': "16,40.60805,-74.23770",
'industrial - Moscow': "14.75,55.8892,37.5502",
'industrial - Mumbai': "16,19.0308,73.1094",
'links - Athens': "16.25,37.94439,23.67000",
'links - Beijing z15': "15.5,40.1539,116.4776",
'links - Beijing z17': "17,39.86122,116.44842",
'links - Beijing z18': "18,39.89174,116.41252",
'links - Cologne': "16.5,50.95798,6.97045",
'links - Fez': "17,33.99146,-5.02538",
'links - Hong Kong': "16.5,22.28726,114.21740",
'links - Houston': "17,29.69754,-95.28841",
'links - Istanbul': "16,40.98138,29.09565",
'links - Rome': "16.5,41.92054,12.61136",
'links - San Antonio': "16,29.50086,-98.54860",
'links - Shanghai': "16,31.15869,121.64373",
'links - Singapore': "16,1.3713,103.9378",
'piers - Antibes': "16,43.5863,7.1265",
'piers - Blankenberge': "16,51.31141,3.11825",
'piers - Boston': "17,42.36208,-71.04884",
'piers - Chicago': "17,41.88533,-87.61145",
'piers - Copenhagen': "16,55.6667,12.6328",
'piers - Durban': "17,-29.86343,31.02357",
'piers - Hillsboro Beach': "16.4,26.26337,-80.08258",
'piers - Ipswich': "16,52.0499,1.1603",
'piers - San Francisco': "17,37.80669,-122.44387",
'piers - San Mateo': "17,37.58887,-122.31677",
'piers - Sydney': "15,-33.8534,151.1806",
'place of worship - Bangkok z16': "16,13.7492,100.4986",
'place of worship - Bangkok z18': "18,13.74578,100.49279",
'place of worhsip - Istanbul': "19,41.00525,28.97687",
'place of worship - Jerusalem': "19,31.77175,35.22927",
'place of worship - Kanchipuram': "18,12.81928,79.72537",
'place of worship - Karbala': "18,32.61660,44.03437",
'place of worship - Kyoto': "14,35.0011,135.7710",
'place of worship - Mecca': "15.75,21.4246,39.8244",
'place of worship - Medina': "16,24.46893,39.61087",
'place of worship - Paris': "19,48.85300,2.34986",
'place of worship - Rome': "19,41.89863,12.47682",
'place of worship - Tokyo': "17,35.71367,139.79635",
'racetracks - Austin': "16,30.1354,-97.6333",
'racetracks - Francorchamps': "15,50.4375,5.9691",
'racetracks - Homestead': "17,25.45182,-80.40862",
'racetracks - Indiantown': "16,26.92273,-80.30637",
'racetracks - Lime Rock': "17,41.92755,-73.38363",
'racetracks - Milton Keynes': "15,52.0720,-1.0163",
'racetracks - Nantes': "17.5,47.19822,-1.64053",
'racetracks - Nürburg': "18.2,50.32672,6.93251",
'racetracks - Rosamond': "16,34.8753,-118.2636",
'racetracks - Sao Paolo': "16.2,-23.70139,-46.69669",
'racetracks - Suzuka': "16,34.84375,136.53263",
'rail - Antwerp': "15,51.29312,4.38148",
'rail - Bangalore': "16,12.97664,77.56837",
'rail - Beijing': "14,39.9872,116.5207",
'rail - Belgrade': "14.7,44.7400,20.3729",
'rail - Bishkek': "13,42.8615,74.5922",
'rail - Bratislava': "18.75,48.19849,17.16449",
'rail - Bucharest': "19.5,44.46088,26.05699",
'rail - Cologne': "16.75,50.95249,6.94652",
'rail - Duisburg': "14,51.4961,6.7248",
'rail - Moscow': "13.4,55.7388,37.7276",
'rail - Nagoya': "17,35.19598,136.86574",
'rail - New Delhi': "16.5,28.64861,77.21859",
'rail - Osaka': "16.5,34.70428,135.49910",
'rail - Salzburg': "18,47.81310,13.04565",
'rail - Tashkent': "12.5,41.3044,69.3074",
'rail - Tokyo': "16.5,35.61419,139.73323",
'rail - Urumqi': "17,43.83930,87.52657",
'rail - Xian': "13.2,34.2871,108.8598",
'rail - Yokohama': "17.5,35.48108,139.63693",
'roads1 - Addis Ababa': "11,9.0116,38.7522",
'roads1 - Aleppo': "12,36.2101,37.1609",
'roads1 - Amman': "12,31.9523,35.9188",
'roads1 - Ankara': "10,39.9292,32.7873",
'roads1 - Baghdad': "11,33.3251,44.3697",
'roads1 - Bangkok': "10,13.8681,100.5579",
'roads1 - Beijing': "10,39.9176,116.3617",
'roads1 - Bucharest': "11,44.4438,26.0994",
'roads1 - Cairo': "9,30.0418,31.1270",
'roads1 - Christchurch': "11,-43.5115,172.6041",
'roads1 - Cologne': "11,50.9647,6.9440",
'roads1 - Damascus': "12,33.5218,36.2896",
'roads1 - Jakarta': "11,-6.2078,106.8304",
'roads1 - Johannesburg': "11,-26.1601,28.0357",
'roads1 - Kuala Lumpur': "10,3.1042,101.6455",
'roads1 - London': "9,51.4788,-0.1648",
'roads1 - Madrid': "11,40.4253,-3.7072",
'roads1 - Moscow': "10,55.7638,37.6062",
'roads1 - Munich': "11,48.1356,11.5727",
'roads1 - Paris': "11,48.8559,2.3305",
'roads1 - Seoul': "10,37.5601,126.9511",
'roads1 - Seville': "12,37.3891,-5.9745",
'roads1 - Tokyo': "10,35.6991,139.7653",
'roads2 - Chicago': "15,41.9309,-87.7493",
'roads2 - Colombo': "14,7.0695,79.9843",
'roads2 - Dasmarinas': "13,14.3219,120.9653",
'roads2 - Denpasar': "12.5,-8.4785,115.2630",
'roads2 - New York': "16,40.7554,-73.9867",
'roads2 - Paris': "16,48.8739,2.2949",
'roads2 - Tokyo': "15,35.7094,139.6277",
'schools - Baghdad': "15.5,33.2735,44.3801",
'schools - Barcelona': "17.5,41.38740,2.16329",
'schools - Beijing': "14,39.9943,116.3328",
'schools - Boston': "15,42.3564,-71.1040",
'schools - Fez': "19,34.06477,-4.97339",
'schools - Ithaca': "15,42.4507,-76.4743",
'schools - Manila': "14,14.6519,121.0626",
'schools - London': "17,51.49944,-0.17741",
'schools - Philadelphia': "15,39.9515,-75.1955",
'schools - Toronto': "16,43.66367,-79.39581",
'ski - French Alps': "13,45.5705,6.8147",
'ski - Vail': "13.1,39.60116,-106.34795",
'ski - Breckenridge z13': "13.8,39.4750,-106.0759",
'ski - Breckenridge z14': "14.5,39.6287,-105.8732",
'ski - Nevada': "15,39.2547,-119.9141",
'ski - California z13': "13.75,38.9397,-119.9114",
'ski - California z14': "14.5,39.1929,-120.2508",
'ski - Park City': "13,40.6509,-111.5269",
'ski - St. Moritz': "14,46.5100,9.8157",
'ski - Tignes': "14,45.4523,6.9219",
'ski - Tschaval': "13,45.8603,7.8333",
'tunnels - Barcelona': "13,41.4002,2.1557",
'tunnels - Los Angeles': "19.4,34.04957,-118.25107",
'tunnels - Paris': "13,48.8607,2.3358",
'water - Port Charlotte': "14,26.8944,-82.2725"
};
/* global variables */
var tg_baseScene = './morphology.yaml';
var sdk_api_key = '3eqm2_bfTNGZ85ar20fVyA';
var tg_global = { 'sdk_api_key': sdk_api_key };
var popup = document.getElementById('popup');
var all_theme_imports = { form: null };
var layer, scene;
/*** Map ***/
var map = L.Mapzen.map('map', {
"iframeDetection": true,
"keyboardZoomOffset" : .05,
"scrollWheelZoom": true,
tangramOptions: {
scene: tg_baseScene
}
});
map.setView([37.6193, -122.3763], 14);
var hash = L.Mapzen.hash({map: map});
L.Mapzen.geocoder('ge-bdea4ebc9dad8ca3').addTo(map);
map.on('tangramloaded', function(e) {
layer = e.tangramLayer;
scene = layer.scene;
});
// Feature selection
var picking = false;
function addHoverEvent () {
layer.setSelectionEvents({
hover: function(selection) {
if (!picking) {
if (!selection || selection.feature == null || selection.feature.properties == null) {
popup.style.display = 'none';
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.display = 'block';
}
}
});
}
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;
}
function addClickEvent () {
// 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.display = 'none';
});
var timer;
map.getContainer().addEventListener('mousemove', function (event) {
picking = false;
popup.style.display = 'none';
return;
});
layer.setSelectionEvents({
click: function(selection) {
if( timer ) { clearTimeout( timer ); timer = null; }
timer = setTimeout( function() {
picking = true;
latlng = selection.leaflet_event.latlng;
var url = 'https://www.openstreetmap.org/edit?';
if (!selection || selection.feature == null || selection.feature.properties == null) {
picking = false;
popup.style.display = 'none';
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;
}
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>"
}
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>';
}
// ID 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.style.display = 'block';
timer = null;
}, 200 );
}
});
}
function update_scene_with_themes() {
// construct the import array
themes_as_array = [tg_baseScene];
if( all_theme_imports.form ) {
themes_as_array.push( all_theme_imports.form );
}
scene.load({ import: themes_as_array, global: tg_global });
scene.updateConfig();
}
function updateSceneWithForm (value) {
var import_theme = 'forms/form-'+ value + '.yaml'
if( value === 'morphology') {
import_theme = value + '.yaml'
}
all_theme_imports.form = import_theme;
update_scene_with_themes();
}
function updateQuery (key, value) {
hash._hashData[key] = value;
hash._updateHash();
}
// Add GUI as Leaflet Control
var GUIControl = L.Control.extend({
options: {
position: 'topright'
},
initialize: function (opts) {
L.Util.setOptions(this, opts);
},
onAdd: function () {
// Add each element of GUI panel
var containerDiv = L.DomUtil.create('div','form-container');
L.DomEvent.disableClickPropagation(containerDiv);
var formDropdown = this.getDropdown(form, 'form', function (value) {
updateQuery('form', value);
updateSceneWithForm(value);
});
var bookmarkDropdown = this.getDropdown(bookmark, 'bookmark', function (value) {
var location_as_array = value.split(',');
map.setView(new L.LatLng(location_as_array[1], location_as_array[2]), location_as_array[0]);
});
containerDiv.appendChild(formDropdown);
containerDiv.appendChild(bookmarkDropdown);
containerDiv.appendChild(this.getInteractiveCheckbox());
var buttonRow = L.DomUtil.create('div','row text-center');
var buttonCol = L.DomUtil.create('div','hidden-xs col-sm-12 pr-0');
var self = this;
buttonCol.appendChild(this.getButton('screenshot', function () {
scene.screenshot().then(function(screenshot) {
// uses FileSaver.js: https://github.com/eligrey/FileSaver.js/
saveAs(screenshot.blob, 'tangram-screenshot' + self.getFileNameSuffix() + '.png');
})
}));
if (typeof window.MediaRecorder == 'function') {
var videoRecording = false;
buttonCol.appendChild(this.getButton('record', function () {
if (!videoRecording) {
if (scene.startVideoCapture()) {
videoRecording = true;
document.getElementById('record').textContent = 'stop';
}
} else {
return scene.stopVideoCapture().then(function(video) {
videoRecording = false;
document.getElementById('record').textContent = 'record';
saveAs(video.blob, 'tangram-video-' + self.getFileNameSuffix() + '.webm');
});
}
}));
}
buttonRow.appendChild(buttonCol);
containerDiv.appendChild(buttonRow);
return containerDiv;
},
getFileNameSuffix: function () {
var timestamp = new Date();
var 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);
return map_location + '-' + prettydate;
},
getDropdown: function (data, id, callback) {
var dropdownRow = L.DomUtil.create('div', 'row');
var dropdownLabel = L.DomUtil.create('label', 'control-label col-xs-4');
var labelString = id.charAt(0).toUpperCase() + id.slice(1);
dropdownLabel.textContent = labelString;
dropdownRow.appendChild(dropdownLabel);
var dropdown = L.DomUtil.create('select', 'mb-1 col-xs-8');
dropdown.id = id;
for (var key in data) {
var option = document.createElement('option');
option.value = data[key];
option.textContent = key;
dropdown.appendChild(option);
}
var query = Formatter.parseHashToObj();
if (query.form && id == 'form') {
dropdown.value = query.form;
updateSceneWithForm(dropdown.value);
}
dropdown.onchange = function () {
callback(dropdown.value);
}
dropdownRow.appendChild(dropdown);
return dropdownRow;
},
getButton: function (text, callback) {
var button = L.DomUtil.create('button', 'btn btn-secondary');
button.textContent = text;
button.id = text;
button.onclick = callback;
return button;
},
getInteractiveCheckbox: function () {
var checkboxRow = L.DomUtil.create('div', 'row');
var checkboxWrapper = L.DomUtil.create('div', 'hidden-xs col-sm-12');
var checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.onchange = function () {
scene.setIntrospection(checkbox.checked);
scene.updateConfig();
}
var checkboxLabel = L.DomUtil.create('label', 'control-label');
checkboxLabel.textContent = 'Interactive';
checkboxWrapper.appendChild(checkbox);
checkboxWrapper.appendChild(checkboxLabel);
checkboxRow.appendChild(checkboxWrapper);
return checkboxRow;
}
});
function checkSceneToAddGui () {
// we can't say Tangram scene is available when dom is loaded
// so wait until tangram scene is loaded
if (scene) {
//addDatGui();
var gui = new GUIControl();
gui.addTo(map);
addHoverEvent();
addClickEvent();
} else {
setTimeout(checkSceneToAddGui, 100);
}
}
// Add gui
window.addEventListener('DOMContentLoaded', function () {
if (!map._isThisIframed()) {
checkSceneToAddGui();
}
});
L.Mapzen.bug({
name: 'Morphology',
link: 'https://mapzen.com/blog/morphology/',
tweet: 'Morphology',
repo: 'https://github.com/sensescape/morphology/'
});
</script>
</body>
</html>