-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbkp_index.html
115 lines (98 loc) · 4.12 KB
/
bkp_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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Display map navigation controls</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<script src='https://unpkg.com/@turf/turf/turf.min.js'></script>
<script src="https://api.mapbox.com/mapbox-gl-js/v1.10.0/mapbox-gl.js"></script>
<script src="https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v4.5.1/mapbox-gl-geocoder.min.js"></script>
<script src="https://github.com/mapbox-gl-indoor/mapbox-gl-indoor/releases/download/0.0.4-rc1/mapbox-gl-indoor.js"></script>
<link href="https://api.mapbox.com/mapbox-gl-js/v1.10.0/mapbox-gl.css" rel="stylesheet" />
<link rel="stylesheet"
href="https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v4.5.1/mapbox-gl-geocoder.css"
type="text/css" />
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoiY2xlbWVudGlnb25ldCIsImEiOiJjazl2Z2hzcmkwYmF6M21zN3RqcHg5anU4In0.blXhwZzYBGSm6fJe0z0e-Q'
const map = window.map = new mapboxgl.Map({
container: "map",
zoom: 18,
center: [2.3592843, 48.8767904],
style: 'mapbox://styles/mapbox/streets-v10'
});
map.addControl(new mapboxgl.FullscreenControl(), 'bottom-right');
/**
* Indoor specific
*/
// Create the indoor handler
const indoor = new mapboxgl_indoor.Indoor(map);
var customData;
// Retrieve the geojson from the path and add the map
fetch('https://raw.githubusercontent.com/openindoor-space/openindoor-space.github.io/master/gare-de-l-est.geojson')
.then(res => res.json())
.then(geojson => {
indoor.addMap(mapboxgl_indoor.IndoorMap.fromGeojson(geojson));
customData = geojson;
});
function forwardGeocoder(query) {
var matchingFeatures = [];
for (var i = 0; i < customData.features.length; i++) {
var feature = customData.features[i];
if (feature.properties.hasOwnProperty('name') &&
feature.properties['name']
.toLowerCase()
.search(query.toLowerCase()) !== -1
) {
feature['place_name'] = feature.properties['name'];
feature['center'] = turf.centroid(feature).geometry.coordinates;
feature['place_type'] = ['park'];
matchingFeatures.push(feature);
} else if (feature.properties.hasOwnProperty('name') &&
feature.properties.name
.toLowerCase()
.search(query.toLowerCase()) !== -1
) {
feature['place_name'] = feature.properties.name;
feature['center'] = turf.centroid(feature).geometry.coordinates;
feature['place_type'] = ['park'];
matchingFeatures.push(feature);
}
}
return matchingFeatures;
}
let geocoder = new MapboxGeocoder({
localGeocoderOnly: true,
localGeocoder: forwardGeocoder,
zoom: 19,
placeholder: 'Enter search e.g. Room',
mapboxgl: mapboxgl,
marker: true,
});
geocoder.on("result", (result) => {
console.log('result.result.properties:', result.result.properties);
indoor.setLevel(parseInt(result.result.properties.level));
})
map.addControl(geocoder, 'top-right');
// Add zoom and rotation controls to the map.
map.addControl(new mapboxgl.NavigationControl(), 'bottom-right');
// Add the specific control
map.addControl(new mapboxgl_indoor.IndoorControl(indoor), 'top-right');
</script>
</body>
</html>