@situm/cordova 3.0.1 → 3.1.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/CHANGELOG_UNRELEASED.md +5 -26
- package/docs/JSDoc/MapView.html +2 -2
- package/docs/JSDoc/MapViewControllerImpl.html +458 -2
- package/docs/JSDoc/Situm.html +1 -1
- package/docs/JSDoc/android_Interfaces.js.html +38 -2
- package/docs/JSDoc/android_situm.js.html +1 -1
- package/docs/JSDoc/global.html +289 -1
- package/docs/JSDoc/index.html +1 -1
- package/docs/JSDoc/map-view-controller.js.html +128 -29
- package/docs/JSDoc/map-view.js.html +1 -2
- package/docs/JSDoc/styles/custom.css +4 -0
- package/docs/static/styles/custom.css +4 -0
- package/package.json +1 -1
- package/plugin.xml +1 -1
- package/www/android/Interfaces.js +37 -1
- package/www/map-view-controller.js +129 -28
- package/www/map-view.js +1 -2
|
@@ -5,6 +5,8 @@ const Situm = require("@situm/cordova.situm");
|
|
|
5
5
|
*/
|
|
6
6
|
class MapViewControllerImpl {
|
|
7
7
|
_onLoadCallback = undefined;
|
|
8
|
+
_onPoiSelectedCallback = undefined;
|
|
9
|
+
_onPoiDeselectedCallback = undefined;
|
|
8
10
|
_buildings = undefined;
|
|
9
11
|
_mapView = undefined;
|
|
10
12
|
_isNavigating = false;
|
|
@@ -26,22 +28,22 @@ class MapViewControllerImpl {
|
|
|
26
28
|
type: type,
|
|
27
29
|
payload: payload,
|
|
28
30
|
};
|
|
29
|
-
if (this._mapView && this._mapView.firstElementChild){
|
|
31
|
+
if (this._mapView && this._mapView.firstElementChild) {
|
|
30
32
|
this._mapView.firstElementChild.contentWindow.postMessage(
|
|
31
33
|
message,
|
|
32
34
|
this._mapView._getViewerDomain()
|
|
33
|
-
)
|
|
34
|
-
}
|
|
35
|
+
);
|
|
36
|
+
}
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
// ==================================================
|
|
38
|
-
// SDK MESSAGES:
|
|
40
|
+
// SDK MESSAGES:
|
|
39
41
|
// ==================================================
|
|
40
42
|
|
|
41
43
|
_handleSdkNativeEvents(eventName, payload) {
|
|
42
44
|
switch (eventName) {
|
|
43
45
|
case "onLocationUpdate":
|
|
44
|
-
// TODO: iOS is sending messages here not related to Location. Check
|
|
46
|
+
// TODO: iOS is sending messages here not related to Location. Check
|
|
45
47
|
// some fields to avoid assuming that we receive an object of type Location.
|
|
46
48
|
if (payload.buildingIdentifier && payload.position) {
|
|
47
49
|
this._handleOnLocationUpdate(payload);
|
|
@@ -61,30 +63,51 @@ class MapViewControllerImpl {
|
|
|
61
63
|
// Do nothing.
|
|
62
64
|
},
|
|
63
65
|
() => {
|
|
64
|
-
console.error("Error at updateNavigationWithLocation")
|
|
66
|
+
console.error("Error at updateNavigationWithLocation");
|
|
65
67
|
}
|
|
66
68
|
);
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
_handleOnLocationStatus(payload) {
|
|
71
|
-
this._sendMessageToViewer("location.update_status", {
|
|
73
|
+
this._sendMessageToViewer("location.update_status", {
|
|
74
|
+
status: payload.statusName,
|
|
75
|
+
});
|
|
72
76
|
}
|
|
73
77
|
|
|
74
78
|
// ==================================================
|
|
75
|
-
// MAP-VIEWER MESSAGES:
|
|
79
|
+
// MAP-VIEWER MESSAGES:
|
|
76
80
|
// ==================================================
|
|
77
81
|
|
|
78
82
|
_handleMapViewMessages(m) {
|
|
79
83
|
switch (m.type) {
|
|
80
84
|
case "app.map_is_ready":
|
|
81
|
-
if (
|
|
85
|
+
if (
|
|
86
|
+
this._onLoadCallback &&
|
|
87
|
+
typeof this._onLoadCallback === "function"
|
|
88
|
+
) {
|
|
82
89
|
this._onLoadCallback(this);
|
|
83
|
-
console.debug(
|
|
90
|
+
console.debug("Map is ready!");
|
|
84
91
|
}
|
|
85
92
|
break;
|
|
86
93
|
case "cartography.poi_selected":
|
|
87
94
|
console.debug(`poi (${m.payload.identifier}) was selected`);
|
|
95
|
+
const poiSelectedResult = {
|
|
96
|
+
poi: {
|
|
97
|
+
identifier: m.payload.identifier,
|
|
98
|
+
buildingIdentifier: m.payload.buildingIdentifier,
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
this._onPoiSelectedCallback(poiSelectedResult);
|
|
102
|
+
break;
|
|
103
|
+
case "cartography.poi_deselected":
|
|
104
|
+
const poiDeselectedResult = {
|
|
105
|
+
poi: {
|
|
106
|
+
identifier: m.payload.identifier,
|
|
107
|
+
buildingIdentifier: m.payload.buildingIdentifier,
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
this._onPoiDeselectedCallback(poiDeselectedResult);
|
|
88
111
|
break;
|
|
89
112
|
case "directions.requested":
|
|
90
113
|
this._onDirectionsRequested(m.payload);
|
|
@@ -104,14 +127,18 @@ class MapViewControllerImpl {
|
|
|
104
127
|
// Fetch the given building and return it or undefined if not found.
|
|
105
128
|
_ensureBuilding(buildingId, callback) {
|
|
106
129
|
if (this._buildings) {
|
|
107
|
-
let building = this._buildings.find(
|
|
130
|
+
let building = this._buildings.find(
|
|
131
|
+
(b) => b.buildingIdentifier == buildingId
|
|
132
|
+
);
|
|
108
133
|
callback(building);
|
|
109
134
|
} else {
|
|
110
135
|
// Fetch buildings and calculate route.
|
|
111
136
|
cordova.plugins.Situm.fetchBuildings(
|
|
112
137
|
(res) => {
|
|
113
138
|
this._buildings = res;
|
|
114
|
-
let building = this._buildings.find(
|
|
139
|
+
let building = this._buildings.find(
|
|
140
|
+
(b) => b.buildingIdentifier == buildingId
|
|
141
|
+
);
|
|
115
142
|
callback(building);
|
|
116
143
|
},
|
|
117
144
|
(err) => {
|
|
@@ -130,20 +157,34 @@ class MapViewControllerImpl {
|
|
|
130
157
|
originIdentifier: payload.originIdentifier,
|
|
131
158
|
destinationIdentifier: payload.destinationIdentifier,
|
|
132
159
|
type: directionsRequest.accessibilityMode,
|
|
133
|
-
}
|
|
160
|
+
};
|
|
134
161
|
this._ensureBuilding(payload.buildingIdentifier, (building) => {
|
|
135
|
-
if (building){
|
|
162
|
+
if (building) {
|
|
136
163
|
Situm.requestDirections(
|
|
137
|
-
[
|
|
164
|
+
[
|
|
165
|
+
building,
|
|
166
|
+
directionsRequest.from,
|
|
167
|
+
directionsRequest.to,
|
|
168
|
+
directionsRequest,
|
|
169
|
+
],
|
|
138
170
|
(route) => {
|
|
139
|
-
this._sendMessageToViewer("directions.update", {
|
|
171
|
+
this._sendMessageToViewer("directions.update", {
|
|
172
|
+
...route,
|
|
173
|
+
...mapViewerData,
|
|
174
|
+
});
|
|
140
175
|
},
|
|
141
176
|
(error) => {
|
|
142
|
-
this._sendMessageToViewer("directions.update", {
|
|
177
|
+
this._sendMessageToViewer("directions.update", {
|
|
178
|
+
error: -1,
|
|
179
|
+
identifier: mapViewerData.identifier,
|
|
180
|
+
});
|
|
143
181
|
}
|
|
144
182
|
);
|
|
145
183
|
} else {
|
|
146
|
-
this._sendMessageToViewer("directions.update", {
|
|
184
|
+
this._sendMessageToViewer("directions.update", {
|
|
185
|
+
error: -1,
|
|
186
|
+
identifier: payload.identifier,
|
|
187
|
+
});
|
|
147
188
|
}
|
|
148
189
|
});
|
|
149
190
|
}
|
|
@@ -157,36 +198,55 @@ class MapViewControllerImpl {
|
|
|
157
198
|
originIdentifier: payload.originIdentifier,
|
|
158
199
|
destinationIdentifier: payload.destinationIdentifier,
|
|
159
200
|
type: directionsRequest.accessibilityMode,
|
|
160
|
-
}
|
|
201
|
+
};
|
|
161
202
|
let navigationRequest = payload.navigationRequest;
|
|
162
203
|
this._ensureBuilding(payload.buildingIdentifier, (building) => {
|
|
163
204
|
// Request directions again to update the calculated route on the native side.
|
|
164
205
|
Situm.requestDirections(
|
|
165
|
-
[
|
|
206
|
+
[
|
|
207
|
+
building,
|
|
208
|
+
directionsRequest.from,
|
|
209
|
+
directionsRequest.to,
|
|
210
|
+
directionsRequest,
|
|
211
|
+
],
|
|
166
212
|
(route) => {
|
|
167
213
|
this._isNavigating = true;
|
|
168
|
-
this._sendMessageToViewer("navigation.start", {
|
|
214
|
+
this._sendMessageToViewer("navigation.start", {
|
|
215
|
+
...route,
|
|
216
|
+
...mapViewerData,
|
|
217
|
+
});
|
|
169
218
|
Situm.requestNavigationUpdates(
|
|
170
219
|
[navigationRequest],
|
|
171
220
|
(progress) => {
|
|
172
221
|
// Navigation is working, handle different progress types:
|
|
173
222
|
if (progress.type == "progress") {
|
|
174
|
-
progress.type =
|
|
223
|
+
progress.type = "PROGRESS"; // The map-viewer waits for an upper case "type".
|
|
175
224
|
this._sendMessageToViewer("navigation.update", progress);
|
|
176
225
|
} else if (progress.type == "destinationReached") {
|
|
177
|
-
this._sendMessageToViewer("navigation.update", {
|
|
226
|
+
this._sendMessageToViewer("navigation.update", {
|
|
227
|
+
type: "DESTINATION_REACHED",
|
|
228
|
+
});
|
|
178
229
|
this._isNavigating = false;
|
|
179
230
|
} else if (progress.type == "userOutsideRoute") {
|
|
180
|
-
this._sendMessageToViewer("navigation.update", {
|
|
231
|
+
this._sendMessageToViewer("navigation.update", {
|
|
232
|
+
type: "OUT_OF_ROUTE",
|
|
233
|
+
});
|
|
181
234
|
}
|
|
182
235
|
},
|
|
183
236
|
(error) => {
|
|
184
|
-
this._sendMessageToViewer("directions.update", {
|
|
237
|
+
this._sendMessageToViewer("directions.update", {
|
|
238
|
+
error: -1,
|
|
239
|
+
identifier: mapViewerData.identifier,
|
|
240
|
+
});
|
|
185
241
|
this._isNavigating = false;
|
|
186
|
-
}
|
|
242
|
+
}
|
|
243
|
+
);
|
|
187
244
|
},
|
|
188
245
|
(error) => {
|
|
189
|
-
this._sendMessageToViewer("directions.update", {
|
|
246
|
+
this._sendMessageToViewer("directions.update", {
|
|
247
|
+
error: -1,
|
|
248
|
+
identifier: mapViewerData.identifier,
|
|
249
|
+
});
|
|
190
250
|
this._isNavigating = false;
|
|
191
251
|
}
|
|
192
252
|
);
|
|
@@ -214,9 +274,50 @@ class MapViewControllerImpl {
|
|
|
214
274
|
* @param {number} identifier The unique identifier of the resource.
|
|
215
275
|
* */
|
|
216
276
|
selectPoi(identifier) {
|
|
217
|
-
this._sendMessageToViewer("cartography.select_poi", {
|
|
277
|
+
this._sendMessageToViewer("cartography.select_poi", {
|
|
278
|
+
identifier: identifier,
|
|
279
|
+
});
|
|
218
280
|
}
|
|
219
281
|
|
|
282
|
+
/**
|
|
283
|
+
* Navigate to a {@link POI} of a building.
|
|
284
|
+
*
|
|
285
|
+
* The types of {@link accessibilityMode} you can use are:
|
|
286
|
+
* - 'CHOOSE_SHORTEST' : Calculates the shortest route to the destination {@link POI}.
|
|
287
|
+
* - 'ONLY_ACCESSIBLE' : Calculates the shortest route to the destination {@link POI} but avoiding stairs and prioritizing accessible floor changes such as lifts.
|
|
288
|
+
* - 'ONLY_NOT_ACCESSIBLE_FLOOR_CHANGES' : Calculates the shortest route to the destination {@link POI} but avoiding lifts and prioritizing non-accessible floor changes such as stairs.
|
|
289
|
+
*
|
|
290
|
+
* accessibilityMode defaults to CHOOSE_SHORTEST.
|
|
291
|
+
*
|
|
292
|
+
* @param {number} identifier The identifier of the poi.
|
|
293
|
+
* @param {'CHOOSE_SHORTEST' | 'ONLY_ACCESSIBLE' | 'ONLY_NOT_ACCESSIBLE_FLOOR_CHANGES' | undefined} accessibilityMode Choose the route type to calculate.
|
|
294
|
+
* */
|
|
295
|
+
navigateToPoi(identifier, accessibilityMode) {
|
|
296
|
+
this._sendMessageToViewer("navigation.start", {
|
|
297
|
+
navigationTo: identifier,
|
|
298
|
+
type: accessibilityMode,
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// ==================================================
|
|
303
|
+
// EVENTS
|
|
304
|
+
// ==================================================
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* A {@link POI} was selected in your building.
|
|
308
|
+
* @param {Function} cb A callback that returns a {@link PoiSelectedResult} by its parameters.
|
|
309
|
+
* */
|
|
310
|
+
onPoiSelected(cb) {
|
|
311
|
+
this._onPoiSelectedCallback = cb;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* A {@link POI} was deselected in your building.
|
|
316
|
+
* @param {Function} cb A callback that returns a {@link PoiDeselectedResult} by its parameters.
|
|
317
|
+
* */
|
|
318
|
+
onPoiDeselected(cb) {
|
|
319
|
+
this._onPoiDeselectedCallback = cb;
|
|
320
|
+
}
|
|
220
321
|
}
|
|
221
322
|
|
|
222
323
|
let MapViewController = new MapViewControllerImpl();
|
package/www/map-view.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const MapViewController = require('./map-view-controller');
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* @namespace MapView
|
|
5
4
|
*/
|
|
@@ -67,7 +66,7 @@ class MapView extends HTMLElement {
|
|
|
67
66
|
MapViewController._handleMapViewMessages(msg);
|
|
68
67
|
}
|
|
69
68
|
} catch (error) {
|
|
70
|
-
console.warn(
|
|
69
|
+
console.warn('Got unparseable message:', m);
|
|
71
70
|
}
|
|
72
71
|
}
|
|
73
72
|
|