-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
78 lines (72 loc) · 2.49 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@v10.2.1/ol.css">
<style>
#map {
width: 100%;
height: 90vh;
}
</style>
</head>
<body>
<div id="container">
<div id="map"></div>
</div>
</div>
<div>
<span id="node-status"></span>
<span id="way-status"></span>
</div>
<script src="https://cdn.jsdelivr.net/npm/ol@v10.2.1/dist/ol.js"></script>
<script src="https://www.unpkg.com/ol-osmoverpass/dist/bundle/index.js"></script>
<script lang="js">
const basemap = new ol.layer.Tile({ source: new ol.source.OSM() });
// Choose one instance from https://wiki.openstreetmap.org/wiki/Overpass_API#Public_Overpass_API_instances
const overpassEndpointURL = 'https://...';
const nodeLayer = new ol.layer.Vector({
source: new OSMOverpass.OSMOverpassNodeSource({
maximumResolution: 5,
fetchBufferSize: 250,
overpassQuery: 'node["amenity"="restaurant"];',
overpassEndpointURL
})
});
const wayLayer = new ol.layer.Vector({
source: new OSMOverpass.OSMOverpassWaySource({
maximumResolution: 5,
fetchBufferSize: 250,
overpassQuery: '(way["highway"];>;);',
overpassEndpointURL
})
});
nodeLayer.getSource().on('featuresloadstart', () => {
document.getElementById('node-status').innerHTML = 'Loading nodes from OSM…';
});
nodeLayer.getSource().on('featuresloadend', () => {
document.getElementById('node-status').innerHTML = '';
});
nodeLayer.getSource().on('featuresloaderror', () => {
document.getElementById('node-status').innerHTML = 'ERROR';
});
wayLayer.getSource().on('featuresloadstart', () => {
document.getElementById('way-status').innerHTML = 'Loading ways from OSM…';
});
wayLayer.getSource().on('featuresloadend', () => {
document.getElementById('way-status').innerHTML = '';
});
wayLayer.getSource().on('featuresloaderror', () => {
document.getElementById('way-status').innerHTML = 'ERROR';
});
const map = new ol.Map({
target: 'map',
layers: [basemap, nodeLayer, wayLayer],
view: new ol.View({
center: [11018989, 2130015],
zoom: 16
})
});
</script>
</body>
</html>