mechanic-map 0.15.4 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +252 -66
- package/dist/map-dist.js +19 -19
- package/dist/map-dist.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
# Mechanic Map SDK
|
|
2
|
-
|
|
3
|
-
## Setup
|
|
4
|
-
|
|
5
|
-
```sh
|
|
6
|
-
node -v # v12.x.x
|
|
7
|
-
```
|
|
1
|
+
# Mechanic Map SDK v2 (package version v0.16.0)
|
|
8
2
|
|
|
9
3
|
```js
|
|
10
4
|
// Initialize MechanicMap
|
|
@@ -12,33 +6,76 @@ node -v # v12.x.x
|
|
|
12
6
|
const svgMapParams = {
|
|
13
7
|
id: "x-map", // map id - required
|
|
14
8
|
developer: false, // developer mode | default = false
|
|
15
|
-
rotate: 0, // map rotation
|
|
16
9
|
height: 800, // viewport height
|
|
17
10
|
maxScale: 2,
|
|
18
11
|
textOnRect: { // location text configs
|
|
19
12
|
enabled: true,
|
|
20
|
-
maxFontSize:
|
|
21
|
-
minFontSize:
|
|
13
|
+
maxFontSize: 48,
|
|
14
|
+
minFontSize: 8,
|
|
22
15
|
fontFamily: "sans-serif",
|
|
23
16
|
mode: "dynamic",
|
|
24
17
|
},
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
tooltip: {
|
|
19
|
+
navigation: {
|
|
20
|
+
text: 'Go to Here '
|
|
21
|
+
},
|
|
22
|
+
detail: {
|
|
23
|
+
text: 'Go to Details'
|
|
24
|
+
},
|
|
25
|
+
enterBuilding: {
|
|
26
|
+
text: 'ENTER'
|
|
27
|
+
}
|
|
27
28
|
},
|
|
28
29
|
stackMode: false,
|
|
30
|
+
servicesEnabled: true,
|
|
29
31
|
data: { // map data - required
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
buildings: content.buildings, // for multiple building
|
|
33
|
+
levels: [
|
|
34
|
+
{
|
|
35
|
+
// ...floor,
|
|
36
|
+
id: floor._id,
|
|
37
|
+
no: floor.no,
|
|
38
|
+
title: floor.name,
|
|
39
|
+
isInitial: floor.no === content.mall.mall_initial_floor,
|
|
40
|
+
isOutdoor: floor.is_outdoor, // for multiple building
|
|
41
|
+
building: floor.building, // for multiple building
|
|
42
|
+
map: {
|
|
43
|
+
initialScaleFactor: floor.scale,
|
|
44
|
+
svg: floor.svg,
|
|
45
|
+
width: floor.dimension.width,
|
|
46
|
+
height: floor.dimension.height
|
|
47
|
+
},
|
|
48
|
+
locations: [
|
|
49
|
+
{
|
|
50
|
+
id: location.s,
|
|
51
|
+
type: 'store',
|
|
52
|
+
title: store.name.en,
|
|
53
|
+
image_url: store.logo,
|
|
54
|
+
// just tests
|
|
55
|
+
...(store.pin && { pin: true }),
|
|
56
|
+
...(store.label && { label: true }),
|
|
57
|
+
rawData: store
|
|
58
|
+
},
|
|
59
|
+
// ... other stores
|
|
60
|
+
{
|
|
61
|
+
id: location.s,
|
|
62
|
+
type: 'service',
|
|
63
|
+
title: service.name.en,
|
|
64
|
+
image_url: service.image,
|
|
65
|
+
rawData: service
|
|
66
|
+
},
|
|
67
|
+
// ... other services
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
],
|
|
33
71
|
nodes: [], // required for SP
|
|
34
72
|
paths: [], // required for SP
|
|
35
|
-
}
|
|
73
|
+
},
|
|
36
74
|
}
|
|
37
75
|
|
|
38
76
|
(MechanicMap && MechanicMap.default)($);
|
|
39
77
|
const $svgMap = $("#svg-map"); // map container
|
|
40
78
|
const map = $svgMap.svgMap(svgMapParams).data("svg-map");
|
|
41
|
-
|
|
42
79
|
```
|
|
43
80
|
|
|
44
81
|
|
|
@@ -114,6 +151,15 @@ const svgMapParams = {
|
|
|
114
151
|
},
|
|
115
152
|
}
|
|
116
153
|
|
|
154
|
+
// add enter building text
|
|
155
|
+
const svgMapParams = {
|
|
156
|
+
tooltip: {
|
|
157
|
+
enabled: true,
|
|
158
|
+
enterBuilding: {
|
|
159
|
+
text: 'ENTER'
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
}
|
|
117
163
|
```
|
|
118
164
|
|
|
119
165
|
### Location Pin
|
|
@@ -131,6 +177,7 @@ const svgMapParams = {
|
|
|
131
177
|
}
|
|
132
178
|
```
|
|
133
179
|
|
|
180
|
+
|
|
134
181
|
### Animation Modes
|
|
135
182
|
```js
|
|
136
183
|
const svgMapParams = {
|
|
@@ -156,39 +203,73 @@ const svgMapParams = {
|
|
|
156
203
|
}
|
|
157
204
|
```
|
|
158
205
|
|
|
159
|
-
|
|
206
|
+
## Listeners
|
|
207
|
+
|
|
208
|
+
### Map Ready
|
|
160
209
|
```js
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
stackMode: {
|
|
165
|
-
enabled: true,
|
|
166
|
-
offset: 10, // distance between floors
|
|
167
|
-
switchFloorTime: 5 * SECOND
|
|
168
|
-
},
|
|
169
|
-
}
|
|
210
|
+
$svgMap.on('mapReady', function() {
|
|
211
|
+
console.log('on:mapReady');
|
|
212
|
+
});
|
|
170
213
|
```
|
|
171
214
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
### Selected Location (store)
|
|
215
|
+
### Levels Ready
|
|
175
216
|
```js
|
|
176
|
-
$svgMap.on(
|
|
177
|
-
console.log(
|
|
217
|
+
$svgMap.on('levelsReady', function(event, levels, levelId, isOutdoor) {
|
|
218
|
+
console.log('on:levelsReady', levels, levelId, isOutdoor);
|
|
219
|
+
|
|
220
|
+
// example level buttons...
|
|
221
|
+
// predefined - const $levels = $('#levels');
|
|
222
|
+
$levels.html(''); // clear levels
|
|
223
|
+
if (!isOutdoor) {
|
|
224
|
+
$('<a/>')
|
|
225
|
+
.addClass('btn-floor')
|
|
226
|
+
.data('floor-number', false)
|
|
227
|
+
.text('<- Go Back')
|
|
228
|
+
.appendTo($levels);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
for (const level of levels) {
|
|
232
|
+
const $a = $('<a/>')
|
|
233
|
+
.addClass('btn-floor')
|
|
234
|
+
.data('floor-number', level.no)
|
|
235
|
+
.text(level.title.en);
|
|
236
|
+
|
|
237
|
+
if (levelId === level.id) {
|
|
238
|
+
$a.addClass('active');
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
$a.appendTo($levels);
|
|
242
|
+
}
|
|
178
243
|
});
|
|
179
244
|
```
|
|
180
245
|
|
|
181
|
-
###
|
|
246
|
+
### Level Ready
|
|
182
247
|
```js
|
|
183
|
-
$svgMap.on(
|
|
184
|
-
console.log(
|
|
248
|
+
$svgMap.on('levelReady', function(event, levelId, levelNo, isOutdoor) {
|
|
249
|
+
console.log('on:levelReady', levelId, levelNo, isOutdoor);
|
|
250
|
+
|
|
185
251
|
});
|
|
186
252
|
```
|
|
187
253
|
|
|
188
254
|
### Level Switched
|
|
189
255
|
```js
|
|
190
|
-
$svgMap.on("
|
|
191
|
-
console.log("on:
|
|
256
|
+
$svgMap.on("levelSwitched", function (event, selectedLevelId, selectedLevelNo) {
|
|
257
|
+
console.log("on:levelSwitched", selectedLevelId, selectedLevelNo);
|
|
258
|
+
});
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Selected Location (store, service, building)
|
|
262
|
+
```js
|
|
263
|
+
$svgMap.on("locationOpened", function (event, location) {
|
|
264
|
+
// id, title, type, rawData
|
|
265
|
+
console.log("on:locationOpened", location);
|
|
266
|
+
});
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Unselected Location (store, service, building)
|
|
270
|
+
```js
|
|
271
|
+
$svgMap.on("locationClosed", function (event) {
|
|
272
|
+
console.log("on:locationClosed");
|
|
192
273
|
});
|
|
193
274
|
```
|
|
194
275
|
|
|
@@ -199,6 +280,7 @@ $svgMap.on("navigationClicked", function (event, locationId) {
|
|
|
199
280
|
});
|
|
200
281
|
```
|
|
201
282
|
|
|
283
|
+
|
|
202
284
|
### Detail Clicked (tooltip detail button)
|
|
203
285
|
```js
|
|
204
286
|
$svgMap.on("detailClicked", function (event, locationId) {
|
|
@@ -206,6 +288,14 @@ $svgMap.on("detailClicked", function (event, locationId) {
|
|
|
206
288
|
});
|
|
207
289
|
```
|
|
208
290
|
|
|
291
|
+
### Enter building Clicked (tooltip enter building button)
|
|
292
|
+
```js
|
|
293
|
+
$svgMap.on("enterBuildingClicked", function (event, $btn, buildingId, locationId) {
|
|
294
|
+
console.log('on:enterBuildingClicked -> buildingId', buildingId);
|
|
295
|
+
map.enterBuilding(buildingId);
|
|
296
|
+
});
|
|
297
|
+
```
|
|
298
|
+
|
|
209
299
|
### Close Clicked (tooltip close button)
|
|
210
300
|
```js
|
|
211
301
|
$svgMap.on("closeClicked", function (event, locationId) {
|
|
@@ -213,24 +303,93 @@ $svgMap.on("closeClicked", function (event, locationId) {
|
|
|
213
303
|
});
|
|
214
304
|
```
|
|
215
305
|
|
|
216
|
-
###
|
|
306
|
+
### Started a navigation
|
|
217
307
|
With this listener, you can: What floor am I on? Am I on the floor where navigation begins? Am I on the last floor? Is there a next floor?
|
|
218
308
|
```js
|
|
219
|
-
$svgMap.on('navigation', function(event, { isStartFloor, isEndFloor, currentFloorNo, nextFloorNo, levelChanger }) {
|
|
309
|
+
$svgMap.on('navigation', function(event, { isStartFloor, isEndFloor, currentFloorNo, nextFloorNo, levelChanger, hasPrevNavigate, hasNextNavigate, hasPrevBuildingNavigate, hasNextBuildingNavigate }) {
|
|
220
310
|
console.log('on:navigation', isStartFloor, isEndFloor, currentFloorNo, nextFloorNo, levelChanger);
|
|
311
|
+
|
|
312
|
+
// is multiple building?
|
|
313
|
+
console.log('on:navigation', hasPrevBuildingNavigate, hasPrevBuildingNavigate);
|
|
314
|
+
|
|
315
|
+
// If there is more than one building and isEndFloor is true, then next can navigate.
|
|
316
|
+
// hasPrevNavigate, hasNextNavigate
|
|
317
|
+
console.log('on:navigation', hasPrevNavigate, hasNextNavigate);
|
|
221
318
|
});
|
|
222
319
|
```
|
|
223
320
|
|
|
224
|
-
###
|
|
321
|
+
### Canceled a navigation
|
|
225
322
|
```js
|
|
226
|
-
$svgMap.on('navigationCancelled', function() {
|
|
227
|
-
|
|
323
|
+
$svgMap.on('navigationCancelled', function(event) {
|
|
324
|
+
console.log('on:navigationCancelled');
|
|
228
325
|
});
|
|
229
326
|
```
|
|
327
|
+
|
|
230
328
|
## Functions
|
|
231
329
|
|
|
330
|
+
### Update Localized Texts
|
|
331
|
+
```js
|
|
332
|
+
map.updateLocalized({
|
|
333
|
+
floorText: '',
|
|
334
|
+
navigationText: '',
|
|
335
|
+
detailText: '',
|
|
336
|
+
enterBuildingText: '',
|
|
337
|
+
closeText: ''
|
|
338
|
+
});
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### Enter The building
|
|
342
|
+
```js
|
|
343
|
+
map.enterBuilding(buildingId);
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
### Exit The building
|
|
347
|
+
```js
|
|
348
|
+
map.exitBuilding();
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
### Switch Level (current building)
|
|
352
|
+
```js
|
|
353
|
+
map.switchLevelToNumber(levelNo);
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### Switch Level (all building)
|
|
357
|
+
```js
|
|
358
|
+
map.switchLevelToId(levelNo);
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
### Show Location
|
|
362
|
+
```js
|
|
363
|
+
map.showLocation("K0_store_14");
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
### Highlight Location
|
|
367
|
+
```js
|
|
368
|
+
map.map.highlightLocation("K0_store_14");
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
### Hide Location (trigger locationClosed event)
|
|
372
|
+
```js
|
|
373
|
+
map.hideLocation();
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### Is multiple building?
|
|
377
|
+
```js
|
|
378
|
+
map.isMultiBuilding();
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
### Get levels
|
|
382
|
+
```js
|
|
383
|
+
map.getLevels();
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
### Get nodes and paths (for kiosks)
|
|
387
|
+
```js
|
|
388
|
+
map.getNodes();
|
|
389
|
+
map.getPaths();
|
|
390
|
+
```
|
|
232
391
|
|
|
233
|
-
### Calculate SP Navigation (v1)
|
|
392
|
+
### Calculate SP Navigation (v1, for kiosk - not supported multiple building)
|
|
234
393
|
This function can be used with kiosk data
|
|
235
394
|
```js
|
|
236
395
|
/*
|
|
@@ -250,14 +409,17 @@ const svgMapParameters = {
|
|
|
250
409
|
// p = pedestrian, d = disabled
|
|
251
410
|
const sp = map.calculateSP('K0_kiosk_01', 'K1_store_50', 'p');
|
|
252
411
|
|
|
412
|
+
// same function
|
|
413
|
+
// const sp = map.calculateSP_v1('K0_kiosk_01', 'K1_store_50', 'p');
|
|
414
|
+
|
|
253
415
|
if (sp.length) {
|
|
254
|
-
map.
|
|
416
|
+
map.startNavigation(sp, true, true, true);
|
|
255
417
|
} else {
|
|
256
418
|
// No suitable directions found
|
|
257
419
|
}
|
|
258
420
|
```
|
|
259
421
|
|
|
260
|
-
### Calculate SP Navigation (v2)
|
|
422
|
+
### Calculate SP Navigation (v2, for kiosk - not supported multiple building)
|
|
261
423
|
This function can be used with kiosk data
|
|
262
424
|
```js
|
|
263
425
|
/*
|
|
@@ -280,53 +442,77 @@ const sp = map.calculateSP_v2('KE1_kiosk_09', 'KE7_parkingspot_01', 'auto');
|
|
|
280
442
|
// sp.alternative -> alternative fastest route
|
|
281
443
|
|
|
282
444
|
if (sp.route) {
|
|
283
|
-
map.
|
|
445
|
+
map.startNavigation(sp.route, true, true, true);
|
|
284
446
|
}
|
|
285
447
|
|
|
286
448
|
// or
|
|
287
449
|
|
|
288
450
|
if (sp.alternative) {
|
|
289
|
-
map.
|
|
451
|
+
map.startNavigation(sp.route, true, true, true);
|
|
290
452
|
}
|
|
291
453
|
```
|
|
292
454
|
|
|
293
|
-
|
|
294
455
|
### Start Navigation
|
|
456
|
+
Decides whether to use showNavigation or showNavigationWithMultiple.
|
|
295
457
|
```js
|
|
296
|
-
|
|
297
|
-
//
|
|
298
|
-
map.
|
|
458
|
+
map.startNavigation(sp, autoMode = true, zoomEnabled = true, showPins = true)
|
|
459
|
+
// map.showNavigation(sp, autoMode = true, zoomEnabled = true, showPins = true)
|
|
460
|
+
// map.showNavigationWithMultiple(sp, autoMode = true, zoomEnabled = true, showPins = true)
|
|
461
|
+
|
|
299
462
|
```
|
|
300
463
|
|
|
464
|
+
### Can we switch to the previous step?
|
|
465
|
+
```js
|
|
466
|
+
map.hasPrevNavigate()
|
|
467
|
+
```
|
|
301
468
|
|
|
302
|
-
###
|
|
469
|
+
### Start navigation from the previous step
|
|
303
470
|
```js
|
|
304
|
-
|
|
305
|
-
map.closeNavigation(true);
|
|
471
|
+
map.prevNavigate(autoMode = false, zoomEnabled = true, showPins = true)
|
|
306
472
|
```
|
|
307
473
|
|
|
474
|
+
### Can we switch to the previous building? (for multiple building)
|
|
475
|
+
```js
|
|
476
|
+
map.hasPrevBuildingNavigate()
|
|
477
|
+
```
|
|
308
478
|
|
|
309
|
-
###
|
|
479
|
+
### Start navigation from the previous building (for multiple building)
|
|
310
480
|
```js
|
|
311
|
-
map.
|
|
481
|
+
map.prevBuildingNavigate(autoMode = false, zoomEnabled = true, showPins = true)
|
|
312
482
|
```
|
|
313
483
|
|
|
314
|
-
###
|
|
484
|
+
### Can we switch to the next step?
|
|
315
485
|
```js
|
|
316
|
-
map.
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
486
|
+
map.hasNextNavigate()
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
### Start navigation from the next step
|
|
490
|
+
```js
|
|
491
|
+
map.nextNavigate(autoMode = false, zoomEnabled = true, showPins = true)
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
### Can we switch to the next building? (for multiple building)
|
|
495
|
+
```js
|
|
496
|
+
map.hasNextBuildingNavigate()
|
|
322
497
|
```
|
|
323
498
|
|
|
324
|
-
###
|
|
499
|
+
### Start navigation from the next building (for multiple building)
|
|
325
500
|
```js
|
|
326
|
-
map.
|
|
501
|
+
map.nextBuildingNavigate(autoMode = false, zoomEnabled = true, showPins = true)
|
|
327
502
|
```
|
|
328
503
|
|
|
329
|
-
|
|
504
|
+
### Restart Navigation by started navigation params
|
|
505
|
+
```js
|
|
506
|
+
map.restartNavigation()
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
### Close Navigation
|
|
510
|
+
```js
|
|
511
|
+
map.closeNavigation()
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
## Custom Styles
|
|
330
516
|
```css
|
|
331
517
|
text {
|
|
332
518
|
fill: #fff;
|