@situm/cordova 3.3.0 → 3.3.2
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/docs/JSDoc/MapView.html +57 -3
- package/docs/JSDoc/MapViewController.html +935 -0
- package/docs/JSDoc/Situm.html +1 -1
- package/docs/JSDoc/android_Interfaces.js.html +7 -7
- package/docs/JSDoc/android_situm.js.html +1 -1
- package/docs/JSDoc/global.html +7 -7
- package/docs/JSDoc/index.html +1 -1
- package/docs/JSDoc/map-view-controller.js.html +178 -108
- package/docs/JSDoc/map-view.js.html +91 -32
- package/docs/JSDoc/styles/custom.css +41 -9
- package/docs/static/styles/custom.css +41 -9
- package/package.json +1 -1
- package/plugin.xml +1 -1
- package/src/android/app/build.gradle +1 -1
- package/src/android/situm.gradle +1 -1
- package/src/ios/Podfile +1 -1
- package/www/map-view-controller.js +165 -109
- package/www/map-view.js +88 -34
- package/docs/JSDoc/MapViewControllerImpl.html +0 -755
|
@@ -1,38 +1,80 @@
|
|
|
1
|
-
const Situm = require(
|
|
1
|
+
const Situm = require('@situm/cordova.situm')
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
+
* Here's an example on how to use this controller class:
|
|
5
|
+
* <div id="codeSnippet">
|
|
6
|
+
* <pre id="textToCopy">
|
|
7
|
+
* <p style="font-weight: bold;position: absolute;top: 10px;left: 10px;text-decoration: underline">JAVASCRIPT</p>
|
|
8
|
+
* cordova.plugins.MapView.onLoad((controller: any) => {
|
|
9
|
+
* // Once the MapView was loaded you can start managing our map by:
|
|
10
|
+
*
|
|
11
|
+
* // 1. Sending actions like selecting or navigating to a POI in a building:
|
|
12
|
+
* // controller.selectPoi('YOUR_POI_IDENTIFIER');
|
|
13
|
+
* // controller.navigateToPoi('YOUR_POI_IDENTIFIER');
|
|
14
|
+
*
|
|
15
|
+
* // 2. Listen to events that take place inside our map like a POI being selected or deselected:
|
|
16
|
+
* controller.onPoiSelected((poiSelectedResult: any) => {
|
|
17
|
+
* console.log("EXAMPLE> onPoiSelected -> ", poiSelectedResult);
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* controller.onPoiDeselected((poiDeselectedResult: any) => {
|
|
21
|
+
* console.log("EXAMPLE> onPoiDeselected -> ", poiDeselectedResult);
|
|
22
|
+
* });
|
|
23
|
+
* });
|
|
24
|
+
* </pre>
|
|
25
|
+
*
|
|
26
|
+
* <button id="copySnippetButton">Copy</button>
|
|
27
|
+
* </div>
|
|
28
|
+
*
|
|
29
|
+
* <script>
|
|
30
|
+
document.getElementById("copySnippetButton").addEventListener("click", function() {
|
|
31
|
+
var textToCopy = document.getElementById("textToCopy");
|
|
32
|
+
|
|
33
|
+
var range = document.createRange();
|
|
34
|
+
range.selectNode(textToCopy);
|
|
35
|
+
window.getSelection().removeAllRanges();
|
|
36
|
+
window.getSelection().addRange(range);
|
|
37
|
+
|
|
38
|
+
document.execCommand("copy");
|
|
39
|
+
window.getSelection().removeAllRanges();
|
|
40
|
+
this.textContent = "Copied!";
|
|
41
|
+
});
|
|
42
|
+
</script>
|
|
43
|
+
*
|
|
44
|
+
*
|
|
4
45
|
* @namespace MapViewControllerImpl
|
|
46
|
+
* @name MapViewController
|
|
5
47
|
*/
|
|
6
48
|
class MapViewControllerImpl {
|
|
7
|
-
_onLoadCallback = undefined
|
|
8
|
-
_onPoiSelectedCallback = undefined
|
|
9
|
-
_onPoiDeselectedCallback = undefined
|
|
10
|
-
_buildings = undefined
|
|
11
|
-
_mapView = undefined
|
|
12
|
-
_isNavigating = false
|
|
49
|
+
_onLoadCallback = undefined
|
|
50
|
+
_onPoiSelectedCallback = undefined
|
|
51
|
+
_onPoiDeselectedCallback = undefined
|
|
52
|
+
_buildings = undefined
|
|
53
|
+
_mapView = undefined
|
|
54
|
+
_isNavigating = false
|
|
13
55
|
|
|
14
56
|
constructor() {
|
|
15
|
-
Situm.internalSetEventDelegate(this._handleSdkNativeEvents.bind(this))
|
|
57
|
+
Situm.internalSetEventDelegate(this._handleSdkNativeEvents.bind(this))
|
|
16
58
|
}
|
|
17
59
|
|
|
18
60
|
_prepare(mapView) {
|
|
19
|
-
this._mapView = mapView
|
|
61
|
+
this._mapView = mapView
|
|
20
62
|
}
|
|
21
63
|
|
|
22
64
|
_setOnLoadCallback(callback) {
|
|
23
|
-
this._onLoadCallback = callback
|
|
65
|
+
this._onLoadCallback = callback
|
|
24
66
|
}
|
|
25
67
|
|
|
26
68
|
_sendMessageToViewer(type, payload) {
|
|
27
69
|
let message = {
|
|
28
70
|
type: type,
|
|
29
71
|
payload: payload,
|
|
30
|
-
}
|
|
72
|
+
}
|
|
31
73
|
if (this._mapView && this._mapView.firstElementChild) {
|
|
32
74
|
this._mapView.firstElementChild.contentWindow.postMessage(
|
|
33
75
|
message,
|
|
34
76
|
this._mapView._getViewerDomain()
|
|
35
|
-
)
|
|
77
|
+
)
|
|
36
78
|
}
|
|
37
79
|
}
|
|
38
80
|
|
|
@@ -42,20 +84,20 @@ class MapViewControllerImpl {
|
|
|
42
84
|
|
|
43
85
|
_handleSdkNativeEvents(eventName, payload) {
|
|
44
86
|
switch (eventName) {
|
|
45
|
-
case
|
|
87
|
+
case 'onLocationUpdate':
|
|
46
88
|
// TODO: iOS is sending messages here not related to Location. Check
|
|
47
89
|
// some fields to avoid assuming that we receive an object of type Location.
|
|
48
90
|
if (payload.buildingIdentifier && payload.position) {
|
|
49
|
-
this._handleOnLocationUpdate(payload)
|
|
91
|
+
this._handleOnLocationUpdate(payload)
|
|
50
92
|
} else if (payload.statusName) {
|
|
51
|
-
this._handleOnLocationStatus(payload)
|
|
93
|
+
this._handleOnLocationStatus(payload)
|
|
52
94
|
}
|
|
53
|
-
break
|
|
95
|
+
break
|
|
54
96
|
}
|
|
55
97
|
}
|
|
56
98
|
|
|
57
99
|
_handleOnLocationUpdate(payload) {
|
|
58
|
-
this._sendMessageToViewer(
|
|
100
|
+
this._sendMessageToViewer('location.update', payload)
|
|
59
101
|
if (this._isNavigating) {
|
|
60
102
|
Situm.updateNavigationWithLocation(
|
|
61
103
|
[payload],
|
|
@@ -63,16 +105,16 @@ class MapViewControllerImpl {
|
|
|
63
105
|
// Do nothing.
|
|
64
106
|
},
|
|
65
107
|
() => {
|
|
66
|
-
console.error(
|
|
108
|
+
console.error('Error at updateNavigationWithLocation')
|
|
67
109
|
}
|
|
68
|
-
)
|
|
110
|
+
)
|
|
69
111
|
}
|
|
70
112
|
}
|
|
71
113
|
|
|
72
114
|
_handleOnLocationStatus(payload) {
|
|
73
|
-
this._sendMessageToViewer(
|
|
115
|
+
this._sendMessageToViewer('location.update_status', {
|
|
74
116
|
status: payload.statusName,
|
|
75
|
-
})
|
|
117
|
+
})
|
|
76
118
|
}
|
|
77
119
|
|
|
78
120
|
// ==================================================
|
|
@@ -81,46 +123,46 @@ class MapViewControllerImpl {
|
|
|
81
123
|
|
|
82
124
|
_handleMapViewMessages(m) {
|
|
83
125
|
switch (m.type) {
|
|
84
|
-
case
|
|
126
|
+
case 'app.map_is_ready':
|
|
85
127
|
if (
|
|
86
128
|
this._onLoadCallback &&
|
|
87
|
-
typeof this._onLoadCallback ===
|
|
129
|
+
typeof this._onLoadCallback === 'function'
|
|
88
130
|
) {
|
|
89
|
-
this._onLoadCallback(this)
|
|
90
|
-
console.debug(
|
|
131
|
+
this._onLoadCallback(this)
|
|
132
|
+
console.debug('Map is ready!')
|
|
91
133
|
}
|
|
92
|
-
break
|
|
93
|
-
case
|
|
94
|
-
console.debug(`poi (${m.payload.identifier}) was selected`)
|
|
134
|
+
break
|
|
135
|
+
case 'cartography.poi_selected':
|
|
136
|
+
console.debug(`poi (${m.payload.identifier}) was selected`)
|
|
95
137
|
const poiSelectedResult = {
|
|
96
138
|
poi: {
|
|
97
139
|
identifier: m.payload.identifier,
|
|
98
140
|
buildingIdentifier: m.payload.buildingIdentifier,
|
|
99
141
|
},
|
|
100
|
-
}
|
|
101
|
-
this._onPoiSelectedCallback(poiSelectedResult)
|
|
102
|
-
break
|
|
103
|
-
case
|
|
142
|
+
}
|
|
143
|
+
this._onPoiSelectedCallback(poiSelectedResult)
|
|
144
|
+
break
|
|
145
|
+
case 'cartography.poi_deselected':
|
|
104
146
|
const poiDeselectedResult = {
|
|
105
147
|
poi: {
|
|
106
148
|
identifier: m.payload.identifier,
|
|
107
149
|
buildingIdentifier: m.payload.buildingIdentifier,
|
|
108
150
|
},
|
|
109
|
-
}
|
|
110
|
-
this._onPoiDeselectedCallback(poiDeselectedResult)
|
|
111
|
-
break
|
|
112
|
-
case
|
|
113
|
-
this._onDirectionsRequested(m.payload)
|
|
114
|
-
break
|
|
115
|
-
case
|
|
116
|
-
this._onNavigationRequested(m.payload)
|
|
117
|
-
break
|
|
118
|
-
case
|
|
119
|
-
this._onNavigationCancel()
|
|
120
|
-
break
|
|
151
|
+
}
|
|
152
|
+
this._onPoiDeselectedCallback(poiDeselectedResult)
|
|
153
|
+
break
|
|
154
|
+
case 'directions.requested':
|
|
155
|
+
this._onDirectionsRequested(m.payload)
|
|
156
|
+
break
|
|
157
|
+
case 'navigation.requested':
|
|
158
|
+
this._onNavigationRequested(m.payload)
|
|
159
|
+
break
|
|
160
|
+
case 'navigation.stopped':
|
|
161
|
+
this._onNavigationCancel()
|
|
162
|
+
break
|
|
121
163
|
default:
|
|
122
|
-
console.debug(
|
|
123
|
-
break
|
|
164
|
+
console.debug('Got unmanaged message: ', m)
|
|
165
|
+
break
|
|
124
166
|
}
|
|
125
167
|
}
|
|
126
168
|
|
|
@@ -129,35 +171,35 @@ class MapViewControllerImpl {
|
|
|
129
171
|
if (this._buildings) {
|
|
130
172
|
let building = this._buildings.find(
|
|
131
173
|
(b) => b.buildingIdentifier == buildingId
|
|
132
|
-
)
|
|
133
|
-
callback(building)
|
|
174
|
+
)
|
|
175
|
+
callback(building)
|
|
134
176
|
} else {
|
|
135
177
|
// Fetch buildings and calculate route.
|
|
136
178
|
cordova.plugins.Situm.fetchBuildings(
|
|
137
179
|
(res) => {
|
|
138
|
-
this._buildings = res
|
|
180
|
+
this._buildings = res
|
|
139
181
|
let building = this._buildings.find(
|
|
140
182
|
(b) => b.buildingIdentifier == buildingId
|
|
141
|
-
)
|
|
142
|
-
callback(building)
|
|
183
|
+
)
|
|
184
|
+
callback(building)
|
|
143
185
|
},
|
|
144
186
|
(err) => {
|
|
145
|
-
callback(undefined)
|
|
187
|
+
callback(undefined)
|
|
146
188
|
}
|
|
147
|
-
)
|
|
189
|
+
)
|
|
148
190
|
}
|
|
149
191
|
}
|
|
150
192
|
|
|
151
193
|
// DIRECTIONS:
|
|
152
194
|
|
|
153
195
|
_onDirectionsRequested(payload) {
|
|
154
|
-
let directionsRequest = payload.directionsRequest
|
|
196
|
+
let directionsRequest = payload.directionsRequest
|
|
155
197
|
let mapViewerData = {
|
|
156
198
|
identifier: payload.identifier,
|
|
157
199
|
originIdentifier: payload.originIdentifier,
|
|
158
200
|
destinationIdentifier: payload.destinationIdentifier,
|
|
159
201
|
type: directionsRequest.accessibilityMode,
|
|
160
|
-
}
|
|
202
|
+
}
|
|
161
203
|
this._ensureBuilding(payload.buildingIdentifier, (building) => {
|
|
162
204
|
if (building) {
|
|
163
205
|
Situm.requestDirections(
|
|
@@ -168,38 +210,38 @@ class MapViewControllerImpl {
|
|
|
168
210
|
directionsRequest,
|
|
169
211
|
],
|
|
170
212
|
(route) => {
|
|
171
|
-
this._sendMessageToViewer(
|
|
213
|
+
this._sendMessageToViewer('directions.update', {
|
|
172
214
|
...route,
|
|
173
215
|
...mapViewerData,
|
|
174
|
-
})
|
|
216
|
+
})
|
|
175
217
|
},
|
|
176
218
|
(error) => {
|
|
177
|
-
this._sendMessageToViewer(
|
|
219
|
+
this._sendMessageToViewer('directions.update', {
|
|
178
220
|
error: -1,
|
|
179
221
|
identifier: mapViewerData.identifier,
|
|
180
|
-
})
|
|
222
|
+
})
|
|
181
223
|
}
|
|
182
|
-
)
|
|
224
|
+
)
|
|
183
225
|
} else {
|
|
184
|
-
this._sendMessageToViewer(
|
|
226
|
+
this._sendMessageToViewer('directions.update', {
|
|
185
227
|
error: -1,
|
|
186
228
|
identifier: payload.identifier,
|
|
187
|
-
})
|
|
229
|
+
})
|
|
188
230
|
}
|
|
189
|
-
})
|
|
231
|
+
})
|
|
190
232
|
}
|
|
191
233
|
|
|
192
234
|
// NAVIGATION
|
|
193
235
|
|
|
194
236
|
_onNavigationRequested(payload) {
|
|
195
|
-
let directionsRequest = payload.directionsRequest
|
|
237
|
+
let directionsRequest = payload.directionsRequest
|
|
196
238
|
let mapViewerData = {
|
|
197
239
|
identifier: payload.identifier,
|
|
198
240
|
originIdentifier: payload.originIdentifier,
|
|
199
241
|
destinationIdentifier: payload.destinationIdentifier,
|
|
200
242
|
type: directionsRequest.accessibilityMode,
|
|
201
|
-
}
|
|
202
|
-
let navigationRequest = payload.navigationRequest
|
|
243
|
+
}
|
|
244
|
+
let navigationRequest = payload.navigationRequest
|
|
203
245
|
this._ensureBuilding(payload.buildingIdentifier, (building) => {
|
|
204
246
|
// Request directions again to update the calculated route on the native side.
|
|
205
247
|
Situm.requestDirections(
|
|
@@ -210,59 +252,59 @@ class MapViewControllerImpl {
|
|
|
210
252
|
directionsRequest,
|
|
211
253
|
],
|
|
212
254
|
(route) => {
|
|
213
|
-
this._isNavigating = true
|
|
214
|
-
this._sendMessageToViewer(
|
|
255
|
+
this._isNavigating = true
|
|
256
|
+
this._sendMessageToViewer('navigation.start', {
|
|
215
257
|
...route,
|
|
216
258
|
...mapViewerData,
|
|
217
|
-
})
|
|
259
|
+
})
|
|
218
260
|
Situm.requestNavigationUpdates(
|
|
219
261
|
[navigationRequest],
|
|
220
262
|
(progress) => {
|
|
221
263
|
// Navigation is working, handle different progress types:
|
|
222
|
-
if (progress.type ==
|
|
223
|
-
progress.type =
|
|
224
|
-
this._sendMessageToViewer(
|
|
225
|
-
} else if (progress.type ==
|
|
226
|
-
this._sendMessageToViewer(
|
|
227
|
-
type:
|
|
228
|
-
})
|
|
229
|
-
this._isNavigating = false
|
|
230
|
-
} else if (progress.type ==
|
|
231
|
-
this._sendMessageToViewer(
|
|
232
|
-
type:
|
|
233
|
-
})
|
|
264
|
+
if (progress.type == 'progress') {
|
|
265
|
+
progress.type = 'PROGRESS' // The map-viewer waits for an upper case "type".
|
|
266
|
+
this._sendMessageToViewer('navigation.update', progress)
|
|
267
|
+
} else if (progress.type == 'destinationReached') {
|
|
268
|
+
this._sendMessageToViewer('navigation.update', {
|
|
269
|
+
type: 'DESTINATION_REACHED',
|
|
270
|
+
})
|
|
271
|
+
this._isNavigating = false
|
|
272
|
+
} else if (progress.type == 'userOutsideRoute') {
|
|
273
|
+
this._sendMessageToViewer('navigation.update', {
|
|
274
|
+
type: 'OUT_OF_ROUTE',
|
|
275
|
+
})
|
|
234
276
|
}
|
|
235
277
|
},
|
|
236
278
|
(error) => {
|
|
237
|
-
this._sendMessageToViewer(
|
|
279
|
+
this._sendMessageToViewer('directions.update', {
|
|
238
280
|
error: -1,
|
|
239
281
|
identifier: mapViewerData.identifier,
|
|
240
|
-
})
|
|
241
|
-
this._isNavigating = false
|
|
282
|
+
})
|
|
283
|
+
this._isNavigating = false
|
|
242
284
|
}
|
|
243
|
-
)
|
|
285
|
+
)
|
|
244
286
|
},
|
|
245
287
|
(error) => {
|
|
246
|
-
this._sendMessageToViewer(
|
|
288
|
+
this._sendMessageToViewer('directions.update', {
|
|
247
289
|
error: -1,
|
|
248
290
|
identifier: mapViewerData.identifier,
|
|
249
|
-
})
|
|
250
|
-
this._isNavigating = false
|
|
291
|
+
})
|
|
292
|
+
this._isNavigating = false
|
|
251
293
|
}
|
|
252
|
-
)
|
|
253
|
-
})
|
|
294
|
+
)
|
|
295
|
+
})
|
|
254
296
|
}
|
|
255
297
|
|
|
256
298
|
_onNavigationCancel() {
|
|
257
|
-
this._isNavigating = false
|
|
299
|
+
this._isNavigating = false
|
|
258
300
|
Situm.removeNavigationUpdates(
|
|
259
301
|
() => {
|
|
260
302
|
// Do nothing.
|
|
261
303
|
},
|
|
262
304
|
() => {
|
|
263
|
-
console.error(
|
|
305
|
+
console.error('Error removing navigation updates.')
|
|
264
306
|
}
|
|
265
|
-
)
|
|
307
|
+
)
|
|
266
308
|
}
|
|
267
309
|
|
|
268
310
|
// ==================================================
|
|
@@ -271,13 +313,16 @@ class MapViewControllerImpl {
|
|
|
271
313
|
|
|
272
314
|
/**
|
|
273
315
|
* Allows you to select a {@link POI} programmatically in your venue. This will cause the {@link MapView} to center the view on that POI and show its information.
|
|
274
|
-
*
|
|
316
|
+
*
|
|
275
317
|
* @param {number} identifier The unique identifier of the resource.
|
|
318
|
+
* @memberof MapViewController
|
|
319
|
+
* @name selectPoi
|
|
320
|
+
* @method
|
|
276
321
|
* */
|
|
277
322
|
selectPoi(identifier) {
|
|
278
|
-
this._sendMessageToViewer(
|
|
323
|
+
this._sendMessageToViewer('cartography.select_poi', {
|
|
279
324
|
identifier: identifier,
|
|
280
|
-
})
|
|
325
|
+
})
|
|
281
326
|
}
|
|
282
327
|
|
|
283
328
|
/**
|
|
@@ -290,25 +335,30 @@ class MapViewControllerImpl {
|
|
|
290
335
|
*
|
|
291
336
|
* accessibilityMode defaults to CHOOSE_SHORTEST.
|
|
292
337
|
*
|
|
293
|
-
* @param {number} identifier The identifier of the
|
|
338
|
+
* @param {number} identifier The identifier of the POI.
|
|
294
339
|
* @param {'CHOOSE_SHORTEST' | 'ONLY_ACCESSIBLE' | 'ONLY_NOT_ACCESSIBLE_FLOOR_CHANGES' | undefined} accessibilityMode Choose the route type to calculate.
|
|
340
|
+
* @memberof MapViewController
|
|
341
|
+
* @name navigateToPoi
|
|
342
|
+
* @method
|
|
295
343
|
* */
|
|
296
344
|
navigateToPoi(identifier, accessibilityMode) {
|
|
297
|
-
this._sendMessageToViewer(
|
|
345
|
+
this._sendMessageToViewer('navigation.start', {
|
|
298
346
|
navigationTo: Number.parseInt(identifier),
|
|
299
347
|
type: accessibilityMode,
|
|
300
|
-
})
|
|
348
|
+
})
|
|
301
349
|
}
|
|
302
350
|
|
|
303
351
|
/**
|
|
304
|
-
* Allows you to change the initial language that
|
|
305
|
-
* Checkout the
|
|
306
|
-
*
|
|
307
|
-
*
|
|
352
|
+
* Allows you to change the initial language that <map-view> uses to display its UI.
|
|
353
|
+
* Checkout the <a href="https://situm.com/docs/13-internationalization/">Situm docs</a> to see the list of supported languages.
|
|
354
|
+
*
|
|
308
355
|
* @param {string} language an ISO 639-1 code.
|
|
356
|
+
* @memberof MapViewController
|
|
357
|
+
* @name setLanguage
|
|
358
|
+
* @method
|
|
309
359
|
*/
|
|
310
|
-
setLanguage(language){
|
|
311
|
-
this._sendMessageToViewer(
|
|
360
|
+
setLanguage(language) {
|
|
361
|
+
this._sendMessageToViewer('ui.set_language', language)
|
|
312
362
|
}
|
|
313
363
|
|
|
314
364
|
// ==================================================
|
|
@@ -318,19 +368,25 @@ class MapViewControllerImpl {
|
|
|
318
368
|
/**
|
|
319
369
|
* Informs you, through the function you pass as callback ({@link cb}), that a {@link POI} was selected in your building.
|
|
320
370
|
* @param {Function} cb A callback that returns a {@link PoiSelectedResult} by its parameters.
|
|
371
|
+
* @memberof MapViewController
|
|
372
|
+
* @name onPoiSelected
|
|
373
|
+
* @method
|
|
321
374
|
* */
|
|
322
375
|
onPoiSelected(cb) {
|
|
323
|
-
this._onPoiSelectedCallback = cb
|
|
376
|
+
this._onPoiSelectedCallback = cb
|
|
324
377
|
}
|
|
325
378
|
|
|
326
379
|
/**
|
|
327
380
|
* Informs you, through the function you pass as callback ({@link cb}), that a {@link POI} was deselected in your building.
|
|
328
381
|
* @param {Function} cb A callback that returns a {@link PoiDeselectedResult} by its parameters.
|
|
382
|
+
* @memberof MapViewController
|
|
383
|
+
* @name onPoiDeselected
|
|
384
|
+
* @method
|
|
329
385
|
* */
|
|
330
386
|
onPoiDeselected(cb) {
|
|
331
|
-
this._onPoiDeselectedCallback = cb
|
|
387
|
+
this._onPoiDeselectedCallback = cb
|
|
332
388
|
}
|
|
333
389
|
}
|
|
334
390
|
|
|
335
|
-
let MapViewController = new MapViewControllerImpl()
|
|
336
|
-
module.exports = MapViewController
|
|
391
|
+
let MapViewController = new MapViewControllerImpl()
|
|
392
|
+
module.exports = MapViewController
|
package/www/map-view.js
CHANGED
|
@@ -1,16 +1,70 @@
|
|
|
1
|
-
const MapViewController = require(
|
|
1
|
+
const MapViewController = require('./map-view-controller')
|
|
2
2
|
/**
|
|
3
|
+
* <h4>CODE SNIPPET</h4>
|
|
4
|
+
*
|
|
5
|
+
* Here's an example on how to implement this in your html view:
|
|
6
|
+
* <div id="codeSnippet">
|
|
7
|
+
* <pre id="textToCopy">
|
|
8
|
+
* <p style="font-weight: bold;position: absolute;top: 10px;left: 10px;text-decoration: underline">HTML</p>
|
|
9
|
+
* <map-view
|
|
10
|
+
* situm-api-key="YOUR_SITUM_API_KEY"
|
|
11
|
+
* building-identifier="YOUR_BUILDING_IDENTIFIER"
|
|
12
|
+
* remote-identifier="YOUR_REMOTE_IDENTIFIER"
|
|
13
|
+
* />
|
|
14
|
+
* </pre>
|
|
15
|
+
*
|
|
16
|
+
* <button id="copySnippetButton">Copy</button>
|
|
17
|
+
* </div>
|
|
18
|
+
*
|
|
19
|
+
* <script>
|
|
20
|
+
document.getElementById("copySnippetButton").addEventListener("click", function() {
|
|
21
|
+
var textToCopy = document.getElementById("textToCopy");
|
|
22
|
+
|
|
23
|
+
var range = document.createRange();
|
|
24
|
+
range.selectNode(textToCopy);
|
|
25
|
+
window.getSelection().removeAllRanges();
|
|
26
|
+
window.getSelection().addRange(range);
|
|
27
|
+
|
|
28
|
+
document.execCommand("copy");
|
|
29
|
+
window.getSelection().removeAllRanges();
|
|
30
|
+
this.textContent = "Copied!";
|
|
31
|
+
});
|
|
32
|
+
</script>
|
|
33
|
+
*
|
|
34
|
+
* <h4>ATTRIBUTES</h4>
|
|
35
|
+
* <dl>
|
|
36
|
+
* <dt>situm-api-key</dt>
|
|
37
|
+
* <dd>Your API Key to authenticate yourself in our plugin.
|
|
38
|
+
* You can manage out your Situm API Key in <a href="https://dashboard.situm.com/accounts/profile"> https://dashboard.situm.com/accounts/profile</a>.</dd>
|
|
39
|
+
*
|
|
40
|
+
* <dt>building-identifier</dt>
|
|
41
|
+
* <dd>The identifier of the building you want to display on the map.
|
|
42
|
+
* You can manage this identifier with this guide <a href="https://situm.com/docs/sdk-cartography/#building-details"> https://situm.com/docs/sdk-cartography/#building-details</a>.</dd>
|
|
43
|
+
*
|
|
44
|
+
* <dt>remote-identifier</dt>
|
|
45
|
+
* <dd>An identifier that allows you to remotely configure all map settings.</dd>
|
|
46
|
+
*
|
|
47
|
+
* <dt>language</dt>
|
|
48
|
+
* <dd>Choose the language that map-view will use to display its UI by specifying an ISO 639-1 code.
|
|
49
|
+
* You can also change the language by calling {@link MapViewController.setLanguage()}.
|
|
50
|
+
* Checkout the <a href="https://situm.com/docs/13-internationalization/">Situm docs</a> to see the list of supported languages.</dd>
|
|
51
|
+
*
|
|
52
|
+
* <dt>viewer-domain</dt>
|
|
53
|
+
* <dd>A parameter that allows you to specify which domain will be displayed inside our webview.
|
|
54
|
+
* Default is <a href="https://map-viewer.situm.com">https://map-viewer.situm.com</a></dd>
|
|
55
|
+
* </dl>
|
|
56
|
+
*
|
|
3
57
|
* @namespace MapView
|
|
4
58
|
*/
|
|
5
59
|
class MapView extends HTMLElement {
|
|
6
|
-
_viewerDomain
|
|
60
|
+
_viewerDomain
|
|
7
61
|
|
|
8
62
|
constructor() {
|
|
9
|
-
super()
|
|
63
|
+
super()
|
|
10
64
|
}
|
|
11
65
|
|
|
12
66
|
connectedCallback() {
|
|
13
|
-
MapViewController._prepare(this)
|
|
67
|
+
MapViewController._prepare(this)
|
|
14
68
|
this.innerHTML = `
|
|
15
69
|
<iframe
|
|
16
70
|
id="map-view-iframe"
|
|
@@ -19,74 +73,74 @@ class MapView extends HTMLElement {
|
|
|
19
73
|
height="100%"
|
|
20
74
|
style="border: none; box-shadow: none;"
|
|
21
75
|
/>
|
|
22
|
-
|
|
23
|
-
window.addEventListener(
|
|
76
|
+
`
|
|
77
|
+
window.addEventListener('message', this._messageReceivedCallback)
|
|
24
78
|
}
|
|
25
79
|
|
|
26
80
|
_getViewerDomain() {
|
|
27
|
-
return this._viewerDomain
|
|
81
|
+
return this._viewerDomain
|
|
28
82
|
}
|
|
29
83
|
|
|
30
84
|
_getViewerURL() {
|
|
31
85
|
let viewerDomain = this._formatValidDomain(
|
|
32
|
-
this.getAttribute(
|
|
33
|
-
)
|
|
34
|
-
let situmApiKey = this.getAttribute(
|
|
35
|
-
let buildingIdentifier = this.getAttribute(
|
|
36
|
-
let language = this.getAttribute(
|
|
86
|
+
this.getAttribute('viewer-domain')
|
|
87
|
+
)
|
|
88
|
+
let situmApiKey = this.getAttribute('situm-api-key') ?? ''
|
|
89
|
+
let buildingIdentifier = this.getAttribute('building-identifier') ?? ''
|
|
90
|
+
let language = this.getAttribute('language') ?? ''
|
|
37
91
|
|
|
38
|
-
let situmApiKeyQP = situmApiKey.length > 0 ? `apikey=${situmApiKey}` :
|
|
92
|
+
let situmApiKeyQP = situmApiKey.length > 0 ? `apikey=${situmApiKey}` : ''
|
|
39
93
|
let buildingIdentifierQP =
|
|
40
|
-
buildingIdentifier.length > 0 ? `&buildingid=${buildingIdentifier}` :
|
|
41
|
-
let languageQP = language.length > 0 ? `&lng=${language}` :
|
|
94
|
+
buildingIdentifier.length > 0 ? `&buildingid=${buildingIdentifier}` : ''
|
|
95
|
+
let languageQP = language.length > 0 ? `&lng=${language}` : ''
|
|
42
96
|
|
|
43
|
-
let query = `${situmApiKeyQP}${buildingIdentifierQP}${languageQP}&mode=embed
|
|
97
|
+
let query = `${situmApiKeyQP}${buildingIdentifierQP}${languageQP}&mode=embed`
|
|
44
98
|
|
|
45
|
-
let remoteIdentifier = this.getAttribute(
|
|
99
|
+
let remoteIdentifier = this.getAttribute('remote-identifier')
|
|
46
100
|
if (remoteIdentifier) {
|
|
47
|
-
return `${viewerDomain}/id/${remoteIdentifier}?${query}
|
|
101
|
+
return `${viewerDomain}/id/${remoteIdentifier}?${query}`
|
|
48
102
|
}
|
|
49
|
-
return `${viewerDomain}/?${query}
|
|
103
|
+
return `${viewerDomain}/?${query}`
|
|
50
104
|
}
|
|
51
105
|
|
|
52
106
|
_formatValidDomain(domain) {
|
|
53
|
-
let result = domain
|
|
107
|
+
let result = domain
|
|
54
108
|
if (result == null) {
|
|
55
|
-
return
|
|
109
|
+
return 'https://map-viewer.situm.com'
|
|
56
110
|
}
|
|
57
|
-
if (!result.startsWith(
|
|
58
|
-
result = `https://${result}
|
|
111
|
+
if (!result.startsWith('https://') && !result.startsWith('http://')) {
|
|
112
|
+
result = `https://${result}`
|
|
59
113
|
}
|
|
60
|
-
if (result.endsWith(
|
|
61
|
-
result = result.substring(0, result.length - 1)
|
|
114
|
+
if (result.endsWith('/')) {
|
|
115
|
+
result = result.substring(0, result.length - 1)
|
|
62
116
|
}
|
|
63
|
-
this._viewerDomain = result
|
|
64
|
-
return result
|
|
117
|
+
this._viewerDomain = result
|
|
118
|
+
return result
|
|
65
119
|
}
|
|
66
120
|
|
|
67
121
|
_messageReceivedCallback(m) {
|
|
68
122
|
try {
|
|
69
|
-
const msg = JSON.parse(m.data)
|
|
123
|
+
const msg = JSON.parse(m.data)
|
|
70
124
|
if (msg && msg.type) {
|
|
71
|
-
MapViewController._handleMapViewMessages(msg)
|
|
125
|
+
MapViewController._handleMapViewMessages(msg)
|
|
72
126
|
}
|
|
73
127
|
} catch (error) {
|
|
74
|
-
console.warn(
|
|
128
|
+
console.warn('Got unparseable message:', m)
|
|
75
129
|
}
|
|
76
130
|
}
|
|
77
131
|
|
|
78
132
|
/**
|
|
79
133
|
* MapView was loaded.
|
|
80
|
-
* The {@link
|
|
134
|
+
* The {@link MapViewController} will be sent by the callback.
|
|
81
135
|
* @param {Function} cb The callback that gives back the controller of this visual component.
|
|
82
136
|
*/
|
|
83
137
|
static onLoad(cb) {
|
|
84
138
|
// For now, setting the on-load callback from the integrator is done using this (static) bridge.
|
|
85
139
|
// Probably this could be improved.
|
|
86
|
-
MapViewController._setOnLoadCallback(cb)
|
|
140
|
+
MapViewController._setOnLoadCallback(cb)
|
|
87
141
|
}
|
|
88
142
|
}
|
|
89
143
|
|
|
90
|
-
customElements.define(
|
|
144
|
+
customElements.define('map-view', MapView)
|
|
91
145
|
|
|
92
|
-
module.exports = MapView
|
|
146
|
+
module.exports = MapView
|