-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
206 lines (192 loc) · 6.76 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
<!DOCTYPE html>
<html>
<head>
<title>VectorGrid.RoutableTiles example</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="stylesheet"
href="https://unpkg.com/[email protected]/dist/leaflet.css"
/>
<script src="https://unpkg.com/[email protected]/geojson-vt.js"></script>
<script
type="text/javascript"
src="https://unpkg.com/[email protected]/dist/leaflet.js"
></script>
<script src="https://unpkg.com/leaflet.vectorgrid@latest/dist/Leaflet.VectorGrid.bundled.js"></script>
</head>
<body style="margin:0">
<div id="map" style="width: 100vw; height: 100vh; background: white"></div>
<div id="selectordiv" style="position: absolute; right: 10vw; top: 2em;">
<select name="city-selector">
<option value="[51.053822,3.722270]">Ghent, Belgium</option>
<option value="[51.219448,4.402464]">Antwerp, Belgium</option>
<option value="[48.864716, 2.349014]">Paris, France</option>
<option value="[40.730610, -73.935242]">New York, US</option>
<option value="[37.774929,-122.419418]">San Francisco, US</option>
<option value="[52.373169,4.890660]">Amsterdam, NL</option>
<option value="[45.434330,6.637370]">French Alps</option>
<option value="[43.811340,5.595570]">Mt. Ventoux, France</option>
<option value="[60.391262,5.322054]">Bergen, Norway</option>
<option value="[35.689487,139.691711]">Tokyo, Japan</option>
<option value="[-33.851520,18.544150]">Capetown, South Africa</option>
<option value="[-4.315173,15.295873]">Kinshasa, Congo</option>
</select>
</div>
<div id="notice" style="position: absolute; left: 25vw; top: 50vh; font-size: 2em;text-align: center">
Click 2 times anywhere on the map
</div>
<script src="dist/main.js"></script>
<script>
var map = L.map("map", {
zoomControl: false,
minZoom: 14,
maxZoom: 14
});
let client = new RoutableTilesClient();
var fromLatLng, toLatLng;
var lineLayer;
async function onMapClick(e) {
if (lineLayer) {
document.getElementById("notice").innerHTML = "Click 2 times anywhere on the map";
lineLayer.remove();
fromLatLng = undefined;
toLatLng = undefined;
lineLayer = undefined;
} else {
if (!fromLatLng) {
document.getElementById("notice").innerHTML = "Click another time elsewhere";
fromLatLng = e.latlng;
} else {
document.getElementById("notice").innerHTML = "Downloading the right data...";
toLatLng = e.latlng;
let geojsonResult = await client.query(
Object.values(fromLatLng),
Object.values(toLatLng)
);
document.getElementById("notice").innerHTML = "Boom! Click again to reset the map.";
lineLayer = L.geoJSON(geojsonResult, {
style: { color: "#3b6790" }
}).addTo(map);
}
}
}
map.on("click", onMapClick);
if (window.location.hash) {
let arguments = window.location.hash.substr(1).split("&");
let point = [];
for (let arg of arguments) {
var [key, val] = arg.split("=");
if (key === "latitude") point[0] = parseFloat(val);
else if (key === "longitude") point[1] = parseFloat(val);
}
document.querySelector('select[name="city-selector"]').value = "";
map.setView(point, 14);
} else {
//Focus on Ghent (the first item in the list)
map.setView({ lat: 51.0261, lng: 3.72071 }, 14);
}
map.addEventListener("moveend", function() {
let latlng = map.getCenter();
window.location.hash =
"#latitude=" + latlng.lat + "&longitude=" + latlng.lng;
});
//Process when a city is selected in the selector
document.addEventListener(
"DOMContentLoaded",
function() {
document.querySelector(
'select[name="city-selector"]'
).onchange = changeEventHandler;
},
false
);
function changeEventHandler(event) {
var parsedLatLong = JSON.parse(event.target.value);
map.setView(parsedLatLong, 14);
}
var vectorTileStyling = {
"Routable Tiles": properties => {
if (properties.highway === "osm:Motorway") {
return {
weight: 3,
fillColor: "black",
color: "orange",
fillOpacity: 1,
opacity: 0.9,
radius: 5
};
} else if (properties.highway === "osm:MotorwayLink") {
return {
weight: 2,
fillColor: "black",
color: "orange",
fillOpacity: 0.6,
opacity: 0.6
};
} else if (properties.highway === "osm:Footway") {
return {
weight: 0.5,
color: "green",
dashArray: "2",
fillOpacity: 0.9,
opacity: 1
};
} else if (properties.highway === "osm:Cycleway") {
return {
weight: 0.5,
color: "red",
dashArray: "2",
fillOpacity: 0.9,
opacity: 1
};
} else if (properties.highway === "") {
return null;
/*tunnel: { // mapbox only
weight: 0.5,
fillColor: '#f2b648',
color: '#f2b648',
fillOpacity: 0.2,
opacity: 0.4,
// dashArray: [4, 4]
},
bridge: { // mapbox only
weight: 0.5,
fillColor: '#f2b648',
color: '#f2b648',
fillOpacity: 0.2,
opacity: 0.4,
// dashArray: [4, 4]
} */
} else {
return {
weight: 1,
fillColor: "#f2b648",
color: "gray",
fillOpacity: 0.6,
opacity: 0.8 /*
weight: 1,
fillColor: 'black',
color: 'black',
fillOpacity: 1,
opacity: 1,
radius: 5*/
};
}
s;
}
};
var routableTilesUrl =
"https://tiles.openplanner.team/planet/14/{x}/{y}/";
var routableTilesOptions = {
rendererFactory: L.canvas.tile,
attribution:
'© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="https://www.mapbox.com/about/maps/">MapBox</a>',
vectorTileLayerStyles: vectorTileStyling
};
var routableTilesLayer = L.vectorGrid
.routableTiles(routableTilesUrl, routableTilesOptions)
.addTo(map);
</script>
</body>
</html>