-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.js
86 lines (68 loc) · 2.46 KB
/
main.js
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
/*jslint browser: true*/
/*global Tangram, gui */
function parseQuery (qstr) {
var query = {};
var a = qstr.split('&');
for (var i in a) {
var b = a[i].split('=');
query[decodeURIComponent(b[0])] = decodeURIComponent(b[1]);
}
return query;
}
map = (function () {
'use strict';
var map_start_location = [37.8090, -122.2220, 12]; // Oakland
/*** URL parsing ***/
// leaflet-style URL hash pattern:
// #[zoom],[lat],[lng]
var url_hash = window.location.hash.slice(1, window.location.hash.length).split('/');
if (url_hash.length == 3) {
map_start_location = [url_hash[1],url_hash[2], url_hash[0]];
// convert from strings
map_start_location = map_start_location.map(Number);
}
// determine the scene url and content to load during start-up
var scene_url = 'styles/elevation-tiles.yaml';
// If there is a query, use it as the scene_url
var query = parseQuery(window.location.search.slice(1));
if (query.url) {
scene_url = query.url;
}
/*** Map ***/
var map = L.map('map', {
"keyboardZoomOffset" : 1.,
"minZoom" : 2,
"maxZoom" : 16,
}
);
var layer = Tangram.leafletLayer({
scene: scene_url,
attribution: '<a href="https://github.com/tangrams/tangram" target="_blank">Tangram</a> | © OSM contributors | <a href="https://nextzen.org/" target="_blank">Nextzen</a>'
});
if (query.quiet) {
layer.options.attribution = "";
map.attributionControl.setPrefix('');
window.addEventListener("load", function() {
var div = document.getElementById("mz-bug");
if (div != null) {div.style.display = "none";}
div = document.getElementById("mz-citysearch");
if (div != null) {div.style.display = "none";}
div = document.getElementById("mz-geolocator");
if (div != null) {div.style.display = "none";}
});
}
if (query.noscroll) {
map.scrollWheelZoom.disable();
}
window.layer = layer;
var scene = layer.scene;
window.scene = scene;
// setView expects format ([lat, long], zoom)
map.setView(map_start_location.slice(0, 3), map_start_location[2]);
var hash = new L.Hash(map);
// wait to add map until window is loaded, to avoid race condition with API key replacement
window.addEventListener('load', function () {
layer.addTo(map);
});
return map;
}());