-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.html
143 lines (123 loc) · 4.61 KB
/
map.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
<!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">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-beta.2/leaflet.css" />
<style>
body {
margin: 0px;
border: 0px;
padding: 0px;
}
#map {
height: 100%;
width: 100%;
position: absolute;
}
</style>
</head>
<body>
<div id="map"></div>
<!-- leaflet -->
<script src="lib/leaflet.js"></script>
<!-- Demo setup -->
<script>
var map, layer, scene;
function loadMap() {
map = L.map('map', {
keyboardZoomOffset : 1.,
attributionControl: false,
zoomControl: false
});
map.setView([0,0],1);
layer = Tangram.leafletLayer({
scene: 'empty.yaml',
debug: {
// disable Tangram animation effects
suppress_label_fade_in: true,
suppress_label_snap_animation: true
}
});
layer.addTo(map);
scene = layer.scene;
// console.log('map loaded')
}
</script>
<!-- Load Tangram by URL -->
<script>
// https://maymay.net/blog/2008/06/15/ridiculously-simple-javascript-version-string-to-object-parser/
function parseVersionString (str) {
if (typeof(str) !== 'string') { return false; }
// Remove extra non-numeric characters (e.g. `v` for version), preserves dots
// http://stackoverflow.com/a/9409894/738675
var x = str.replace(/[^\d.-]/g, '');
var parts = x.split('.');
// parse from string or default to 0 if can't parse
var maj = parseInt(parts[0], 10) || 0;
var min = parseInt(parts[1], 10) || 0;
var pat = parseInt(parts[2], 10) || 0;
return {
major: maj,
minor: min,
patch: pat
}
}
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}
var url = getQueryVariable("url");
url = encodeURI(url);
if (url == "") {
lib_url = "https://unpkg.com/tangram/dist/tangram.debug.js";
} else if (url.indexOf("/") > -1) {
// assume it's a full path
// check that it's a tangram library
if (url.match(/.+\/tangram\.(debug|min)\.m?js/) != null) {
var lib_url = url;
} else {
// noooo you don't
var errortext = 'lib param error: '+url+" is not a valid Tangram library. Stopping test.";
console.log(errortext);
}
} else if (url.indexOf("/") == -1) {
// assume it's a version # only
var v = parseVersionString(url);
if (v.minor < 13) {
// use rawgit
var version = v.major+"."+v.minor+"."+v.patch;
lib_url = "https://rawgit.com/tangrams/tangram/v"+version+"/dist/tangram.debug.js";
} else {
// use unpkg – it's faster
var ext = (v.minor < 16) ? 'js' : 'mjs'; // default to '.mjs' module build from v0.16 on
lib_url = "https://unpkg.com/tangram@"+url+"/dist/tangram.debug."+ext;
}
// Check if it's a version 0.8 or lower, which uses Leaflet@1.0.0-beta.2
if (v.major < 1 && v.minor < 8) {
legacyLeaflet = true;
}
}
// load Tangram library, first as regular <script>, then as <script type="module"> if needed
var scriptElement = document.createElement('script');
scriptElement.id = 'tangram';
scriptElement.src = lib_url;
if (lib_url.slice(lib_url.lastIndexOf('.')+1) === 'mjs') {
scriptElement.type = 'module';
}
scriptElement.onload = loadMap;
document.body.appendChild(scriptElement);
</script>
</body>
</html>