-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
282 lines (236 loc) · 9.48 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://maps.googleapis.com/maps/api/js?libraries=geometry&key=AIzaSyAou_3CoLqEbuFr-r-KwHbKwppPmKRLhto"></script>
<script src="https://app.mapsindoors.com/mapsindoors/js/sdk/mapsindoors-3.0.0.js?apiKey=57e4e4992e74800ef8b69718"></script>
<title>MapsIndoors Samples for Web</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
overflow: hidden;
}
body {
display: flex;
}
nav {
display: flex;
flex-direction: column;
max-height: 100%;
width: 264px;
}
nav input.search {
width: calc(100% - 20px);
font-size: 16px;
height: 30px;
border-radius: 6px;
border: 1px solid grey;
padding: 5px;
margin: 10px;
outline: 0;
}
nav ul.results {
list-style: none;
padding: 0;
margin: 0;
overflow-y: auto;
overflow-x: hidden;
}
nav ul.results li {
display: flex;
align-items: center;
margin: 8px;
}
nav ul.results li img {
max-width: 40px;
margin-right: 8px;
}
nav ul.results li span {
overflow: hidden;
align-items: baseline;
}
nav ul.results li span h1 {
text-overflow: ellipsis;
overflow: hidden;
margin: 0;
font-size: 14px;
line-height: 22px;
white-space: nowrap;
}
nav ul.results li span p {
text-overflow: ellipsis;
overflow: hidden;
margin: 0;
font-size: 12px;
white-space: nowrap;
line-height: 12px;
}
main {
width: calc(100% - 264px);
}
@media only screen and (max-width: 600px) {
nav {
display: none;
flex-direction: column;
max-height: 100%;
width: 0px
}
main {
width: calc(100%);
}
}
</style>
</head>
<body>
<nav>
<input type="text" class="search" oninput="search(this.value)" />
<ul class="results" id="search:results"></ul>
<button onclick="nextLeg()">Next</button>
<button onclick="previousLeg()">Previous</button>
<button onclick="changeColor()">New color</button>
</nav>
<main id="map:canvas">
</main>
<script>
let floorSelector = document.createElement('div');
/*A new instance of google map is created. */
const googleMap = new google.maps.Map(document.getElementById('map:canvas'), {
center: { lat: 57.0588552, lng: 9.9468377 },
zoom: 15,
maxZoom: 21
});
/*A new instance of MapsIndoors is created. It's created with the google map as an argument. */
let mi = new mapsindoors.MapsIndoors({
map: googleMap
// ,
// buildingOutlineOptions: {
// strokeColor: '#123456',
// strokeWeight: 2
// }
});
let dr = new mapsindoors.DirectionsRenderer({ mapsindoors: mi });
/* We can now change the map view to show the default venue or pass in a venue id to go to another venue. */
mi.setVenue('586ca9f0bc1f5702406442b5');
mi.fitVenue();
/* Now we are ready to create the floor selector and add it to the map controls. */
new mapsindoors.FloorSelector(floorSelector, mi);
googleMap.controls[google.maps.ControlPosition.RIGHT_TOP].push(floorSelector);
/* Example of how to use labeOptions. */
// mi.setLabelOptions({
// style: {align:"left"},
// pixelOffset: {
// width:-10,
// height:-10
// }
// });
/* instance of the google.maps.InfoWindow for displaying callouts on the map */
const infoWindow = new google.maps.InfoWindow();
/* A list of events that can be subscribed to on the MapsIndoors object. */
/* Will fire when the MapsIndoors initialization is done and the object is ready to be used.*/
google.maps.event.addListener(mi, 'ready', (e) => {
console.log('ready', e);
});
/* Will fire if the map at some point is changed by calling setMap(map) on the MapsIndoors object */
google.maps.event.addListener(mi, 'map_changed', (e) => {
console.log('map_changed', e);
});
/* Will fire when the floor is changed either by the floor selector or by calling the setFloor(index) in the MapsIndoors object*/
google.maps.event.addListener(mi, 'floor_changed', () => {
console.log('floor_changed');
});
/* Will fire when a location or a room polygon is clicked on the map. */
google.maps.event.addListener(mi, 'click', (e) => {
console.log('click', e);
onClick(e);
});
/* Will fire when the venue is changed. */
google.maps.event.addListener(mi, 'venue_changed', (e) => {
console.log('venue_changed', e);
});
/* Will fire when the building in focus changes. This happens when the map is moved around and another building is in focus on the map. */
google.maps.event.addListener(mi, 'building_changed', (e) => {
console.log('building_changed', e);
});
/* A simple search function. (Debounce delay 500ms) */
let search = debounce((value) => {
const list = document.getElementById('search:results');
list.innerHTML = '';
if (value > '') {
/* The input is used to query the LocationsService and the returned result are displayed as a list */
mapsindoors.LocationsService.getLocations({ q: value }).then((locations) => {
locations.forEach(location => {
let displayRule = mi.getDisplayRule(location);
item = document.createElement('li');
list.appendChild(item);
item.innerHTML = '<img src="' + displayRule.icon + '" /><span><h1>' + location.properties.name + '</h1><p>' + location.properties.roomId + '</p></span>';
/* When the item in the list are clicked a info window will open at the corresponding location on the map. */
item.onclick = () => { onClick(location) };
});
/* A list of ids is used to filter the map view. */
let filter = locations.map(location => location.id);
/* The filter is applied to the map, and the "fitView" is set to true, so that the map will change the viewport to fit the result. */
mi.filter(filter, true);
});
} else {
/*The filter is cleared by calling the fitler function with no arguments. */
mi.filter();
}
}, 500);
/* Delays the search execution if the input is changed within the delay. */
function debounce(fn, delay) {
let timer;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => fn.apply(null, args), delay);
}
}
/* Returns the coordinates from a location as a google.maps.LatLngLiteral. */
function getLatLng(location) {
let coords;
if (location.geometry.type === 'Point') {
coords = location.geometry.coordinates;
} else {
coords = location.properties.anchor.coordinates;
}
return { lat: coords[1], lng: coords[0] };
}
function onClick(location) {
/* Perform a directions request from a fixed outdoor point to the selected location */
mapsindoors.DirectionsService.getRoute({origin: {lat: 57.0583601, lng: 9.9480611, floor: 0}, destination: {lat: location.geometry.coordinates[1], lng: location.geometry.coordinates[0], floor: location.properties.floor}}).then(res => {
dr.setRoute(res.routes[0])
})
/* Set floor */
mi.setFloor(location.properties.floor);
/* Convert to Google LatLng */
latLng = getLatLng(location);
/* Set an infowindow */
infoWindow.setContent(location.properties.name);
infoWindow.setPosition(latLng);
infoWindow.open(googleMap);
/* Center map */
googleMap.panTo(latLng);
}
/* Switch to next part of the currently displayed route */
function nextLeg() {
dr.nextLeg();
}
/* Switch to previous part of the currently displayed route */
function previousLeg() {
dr.previousLeg();
}
/* Change a random color of the currently displayed route */
function changeColor() {
dr.setOptions({ strokeColor: '#' + Math.random().toString(16).substr(2, 6) });
}
</script>
</body>
</html>