@mapsindoors/react-native-maps-indoors-mapbox 2.8.1-rc.1 → 2.9.1

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.
Files changed (45) hide show
  1. package/README.md +118 -1
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/com/mapsindoorsrn/MapsIndoorsPackage.java +10 -0
  4. package/android/src/main/java/com/mapsindoorsrn/core/BaseMapCacheProviders.java +94 -0
  5. package/android/src/main/java/com/mapsindoorsrn/core/DirectionsRendererModule.java +140 -49
  6. package/android/src/main/java/com/mapsindoorsrn/core/DirectionsServiceModule.java +16 -7
  7. package/android/src/main/java/com/mapsindoorsrn/core/MPDisplayRuleModule.java +1 -1
  8. package/android/src/main/java/com/mapsindoorsrn/core/MapControlModule.java +115 -20
  9. package/android/src/main/java/com/mapsindoorsrn/core/MapsIndoorsModule.java +200 -11
  10. package/android/src/main/java/com/mapsindoorsrn/core/RnGson.java +110 -0
  11. package/android/src/main/java/com/mapsindoorsrn/core/UtilsModule.java +1 -1
  12. package/android/src/main/java/com/mapsindoorsrn/core/models/DirectionsRendererOptionsModel.java +498 -0
  13. package/index.ts +25 -0
  14. package/ios/.swift-format +79 -0
  15. package/ios/core/DirectionsRendererBridge.m +11 -0
  16. package/ios/core/DirectionsRendererModule.swift +352 -210
  17. package/ios/core/DirectionsRendererOptions.swift +352 -0
  18. package/ios/core/MapControlModule.swift +326 -244
  19. package/ios/core/MapsIndoorsBridge.m +14 -1
  20. package/ios/core/MapsIndoorsData.swift +1 -0
  21. package/ios/core/MapsIndoorsModule.swift +195 -33
  22. package/ios/core/Sources/MainThread/CallGeneration.swift +38 -0
  23. package/ios/core/Sources/MainThread/MainThread.swift +25 -0
  24. package/ios/core/UtilsModule.swift +57 -45
  25. package/package.json +5 -1
  26. package/react-native-maps-indoors-mapbox.podspec +6 -2
  27. package/specs/NativeDirectionsRendererModule.ts +3 -0
  28. package/specs/NativeMapsIndoorsModule.ts +6 -1
  29. package/src/core/EventNames.ts +3 -0
  30. package/src/core/MPCameraPosition.ts +1 -1
  31. package/src/core/MPDirectionsRenderer.ts +88 -3
  32. package/src/core/MPDirectionsRendererOptions.ts +287 -0
  33. package/src/core/MPError.ts +48 -1
  34. package/src/core/MPLanguageTag.ts +222 -0
  35. package/src/core/MPLegBoundaryIcons.ts +130 -0
  36. package/src/core/MPRouteAnimationType.ts +24 -0
  37. package/src/core/MPRouteArrowStyle.ts +28 -0
  38. package/src/core/MPRouteMarkerDisplayRule.ts +140 -0
  39. package/src/core/MPRouteStampType.ts +24 -0
  40. package/src/core/MPRouteStopIconConfig.ts +5 -3
  41. package/src/core/MPSolution.ts +33 -2
  42. package/src/core/MPStrokeStyle.ts +22 -0
  43. package/src/core/MapsIndoors.ts +155 -11
  44. package/src/core/OnBaseMapCacheProgressListener.ts +20 -0
  45. package/src/core/RouteStopIconConfig.ts +5 -1
@@ -1,10 +1,30 @@
1
1
  import { EmitterSubscription, NativeEventEmitter, NativeModules } from 'react-native';
2
- import { MPCameraViewFitMode, MPError, MPRoute, OnLegSelectedListener } from "../../index";
2
+ import { MPCameraViewFitMode, MPDirectionsRendererOptions, MPError, MPRoute, OnLegSelectedListener } from "../../index";
3
3
  import { EventNames } from './EventNames';
4
4
  import { RouteStopIconConfig } from './RouteStopIconConfig';
5
5
 
6
6
  const { DirectionsRenderer } = NativeModules;
7
7
 
8
+ /**
9
+ * Sent in place of a usage percentage when the app does not supply one, so that the SDK
10
+ * derives the figure from the route's own progress instead.
11
+ *
12
+ * Must stay outside the valid 0-100 range: {@link MPDirectionsRenderer.finishGuidance}
13
+ * clamps a supplied value into that range, which is what keeps this unreachable from the
14
+ * public API, and the native modules branch on it to choose which overload to call.
15
+ */
16
+ const NO_USAGE_PERCENTAGE = -1;
17
+
18
+ /**
19
+ * Encodes a stop icon for the native modules, which download http(s) URLs and otherwise drop the
20
+ * last character before decoding JSON. That character used to be the `/` React Native's URL
21
+ * polyfill appended to the JSON it was (mis)used to wrap.
22
+ */
23
+ function encodeStopIcon(icon: RouteStopIconConfig): string {
24
+ const image = icon.getImage().toString();
25
+ return /^https?:\/\//.test(image) ? image : image + '/';
26
+ }
27
+
8
28
  /**
9
29
  * Renders a {@link MPRoute} on the map.
10
30
  *
@@ -95,7 +115,7 @@ export default class MPDirectionsRenderer {
95
115
  var iconsAsString = new Map<number, string>();
96
116
  if (stopIcons !== null) {
97
117
  stopIcons.forEach((icon, index) => {
98
- iconsAsString.set(index, icon.getImage().toString());
118
+ iconsAsString.set(index, encodeStopIcon(icon));
99
119
  });
100
120
  }
101
121
  await DirectionsRenderer.setRoute(JSON.stringify(route), JSON.stringify(Object.fromEntries(iconsAsString.entries())), legIndex);
@@ -111,12 +131,16 @@ export default class MPDirectionsRenderer {
111
131
  */
112
132
  public async setDefaultRouteStopIcon(icon: RouteStopIconConfig): Promise<void> {
113
133
  this._defaultRouteStopIcon = icon;
114
- await DirectionsRenderer.setDefaultRouteStopIcon(icon.getImage().toString());
134
+ await DirectionsRenderer.setDefaultRouteStopIcon(encodeStopIcon(icon));
115
135
  }
116
136
 
117
137
  /**
118
138
  * Enable/Disable the polyline animation when displaying a route element on the map.
119
139
  *
140
+ * @deprecated Use {@link setOptions} with {@link MPDirectionsRendererOptionsParams.animationType},
141
+ * {@link MPDirectionsRendererOptionsParams.animationRepeating} and
142
+ * {@link MPDirectionsRendererOptionsParams.animationSpeed} instead.
143
+ *
120
144
  * @public
121
145
  * @async
122
146
  * @param {boolean} animated
@@ -133,6 +157,9 @@ export default class MPDirectionsRenderer {
133
157
  *
134
158
  * Colors are given as hex strings (e.g. "#3071D9").
135
159
  *
160
+ * @deprecated Use {@link setOptions} with {@link MPDirectionsRendererOptionsParams.animatedOverlayColor}
161
+ * (foreground) and {@link MPDirectionsRendererOptionsParams.strokeColor} (background) instead.
162
+ *
136
163
  * @public
137
164
  * @async
138
165
  * @param {string} foregroundColor the primary color (animated polyline)
@@ -143,6 +170,64 @@ export default class MPDirectionsRenderer {
143
170
  await DirectionsRenderer.setPolyLineColors(foregroundColor, backgroundColor);
144
171
  }
145
172
 
173
+ /**
174
+ * Set the styling and camera options of the rendered route.
175
+ *
176
+ * Applies immediately, restyling an already rendered route in place. Every option
177
+ * resolves on its own, in this order: the value set here, then the solution level
178
+ * default configured in the CMS, then the SDK's built-in default. Options left
179
+ * unset are therefore inherited rather than reset.
180
+ *
181
+ * @public
182
+ * @async
183
+ * @param {MPDirectionsRendererOptions} options
184
+ * @returns {Promise<void>}
185
+ */
186
+ public async setOptions(options: MPDirectionsRendererOptions): Promise<void> {
187
+ await DirectionsRenderer.setOptions(JSON.stringify(options));
188
+ }
189
+
190
+ /**
191
+ * Gets the currently effective styling and camera options of the rendered route.
192
+ *
193
+ * Each option is resolved as: the value set with {@link setOptions}, then the
194
+ * solution level default configured in the CMS, then the SDK's built-in default.
195
+ * An option reading back as undefined has no default in force for it yet.
196
+ *
197
+ * @public
198
+ * @async
199
+ * @returns {Promise<MPDirectionsRendererOptions>}
200
+ */
201
+ public async getOptions(): Promise<MPDirectionsRendererOptions> {
202
+ const options: string = await DirectionsRenderer.getOptions();
203
+ return MPDirectionsRendererOptions.create(JSON.parse(options));
204
+ }
205
+
206
+ /**
207
+ * Signals that guidance on the current route has finished, either because the user
208
+ * arrived or because they ended navigation.
209
+ *
210
+ * Has no effect when no route is set, or when guidance on the current route has
211
+ * already finished. {@link clear} finishes guidance implicitly, so there is no need
212
+ * to call both.
213
+ *
214
+ * @public
215
+ * @async
216
+ * @param {?number} [usagePercentage] How much of the route was travelled, from 0 to 100.
217
+ * Values outside that range are clamped. Omit it to let the SDK derive the figure from
218
+ * the route's own progress.
219
+ * @returns {Promise<void>}
220
+ */
221
+ public async finishGuidance(usagePercentage?: number): Promise<void> {
222
+ // A non-finite value cannot be clamped into range - NaN in particular survives Math.min/max,
223
+ // and every comparison against it is false, so it would slip past the natives' `< 0` sentinel
224
+ // check and reach the SDK as a usage figure. Treat it as "not supplied" instead.
225
+ const usage = usagePercentage != null && Number.isFinite(usagePercentage)
226
+ ? Math.max(0, Math.min(100, usagePercentage))
227
+ : NO_USAGE_PERCENTAGE;
228
+ await DirectionsRenderer.finishGuidance(usage);
229
+ }
230
+
146
231
  /**
147
232
  * Enable/Disable the route end/start label buttons from showing on the route. Default is true
148
233
  *
@@ -0,0 +1,287 @@
1
+ import { MPLegBoundaryIcons, MPRouteAnimationType, MPRouteArrowStyle, MPRouteMarkerDisplayRule, MPRouteStampType, MPStrokeStyle } from "../../index";
2
+
3
+ /**
4
+ * The styling and camera options for a route rendered by {@link MPDirectionsRenderer}.
5
+ *
6
+ * Applied with {@link MPDirectionsRenderer.setOptions}, which restyles an already
7
+ * rendered route in place.
8
+ *
9
+ * Every property is optional and resolves on its own, in this order: the value set
10
+ * here, then the solution level default configured in the CMS, then the SDK's built-in
11
+ * default. An omitted property is therefore inherited rather than reset, so only the
12
+ * properties to override need to be given. Applying a fresh set of options clears all
13
+ * previous overrides.
14
+ *
15
+ * @export
16
+ * @class MPDirectionsRendererOptions
17
+ * @typedef {MPDirectionsRendererOptions}
18
+ */
19
+ export default class MPDirectionsRendererOptions {
20
+
21
+ /**
22
+ * Creates an instance of MPDirectionsRendererOptions.
23
+ *
24
+ * @constructor
25
+ * @private
26
+ */
27
+ private constructor(
28
+ public readonly strokeColor?: string,
29
+ public readonly strokeOpacity?: number,
30
+ public readonly strokeWeight?: number,
31
+ public readonly strokeStyle?: MPStrokeStyle,
32
+ public readonly backgroundColorEnabled?: boolean,
33
+ public readonly backgroundColor?: string,
34
+ public readonly backgroundColorOpacity?: number,
35
+ public readonly backgroundColorWeight?: number,
36
+ public readonly animationType?: MPRouteAnimationType,
37
+ public readonly animationSpeed?: number,
38
+ public readonly animationMinDuration?: number,
39
+ public readonly animationRepeating?: boolean,
40
+ public readonly forceAnimation?: boolean,
41
+ public readonly animatedOverlayColor?: string,
42
+ public readonly animatedOverlayOpacity?: number,
43
+ public readonly animatedOverlayWeight?: number,
44
+ public readonly stampType?: MPRouteStampType,
45
+ public readonly stampImageUrl?: string,
46
+ public readonly stampSpacing?: number,
47
+ public readonly stampScale?: number,
48
+ public readonly arrowStyle?: MPRouteArrowStyle,
49
+ public readonly stampColor?: string,
50
+ public readonly startDisplayRule?: MPRouteMarkerDisplayRule,
51
+ public readonly endDisplayRule?: MPRouteMarkerDisplayRule,
52
+ public readonly legBoundaryIcons?: MPLegBoundaryIcons,
53
+ public readonly elevated?: boolean,
54
+ public readonly elevationHeight?: number,
55
+ public readonly fitBoundsMaxZoom?: number,
56
+ ) { }
57
+
58
+ /**
59
+ * Creator for MPDirectionsRendererOptions, also used to decode JSON from the MapsIndoors SDK.
60
+ *
61
+ * @public
62
+ * @static
63
+ * @param {MPDirectionsRendererOptionsParams} object
64
+ * @returns {MPDirectionsRendererOptions}
65
+ */
66
+ public static create(object: MPDirectionsRendererOptionsParams): MPDirectionsRendererOptions {
67
+ return new MPDirectionsRendererOptions(
68
+ object?.strokeColor,
69
+ object?.strokeOpacity,
70
+ object?.strokeWeight,
71
+ object?.strokeStyle,
72
+ object?.backgroundColorEnabled,
73
+ object?.backgroundColor,
74
+ object?.backgroundColorOpacity,
75
+ object?.backgroundColorWeight,
76
+ object?.animationType,
77
+ object?.animationSpeed,
78
+ object?.animationMinDuration,
79
+ object?.animationRepeating,
80
+ object?.forceAnimation,
81
+ object?.animatedOverlayColor,
82
+ object?.animatedOverlayOpacity,
83
+ object?.animatedOverlayWeight,
84
+ object?.stampType,
85
+ object?.stampImageUrl,
86
+ object?.stampSpacing,
87
+ object?.stampScale,
88
+ object?.arrowStyle,
89
+ object?.stampColor,
90
+ object?.startDisplayRule ? MPRouteMarkerDisplayRule.create(object.startDisplayRule) : undefined,
91
+ object?.endDisplayRule ? MPRouteMarkerDisplayRule.create(object.endDisplayRule) : undefined,
92
+ object?.legBoundaryIcons ? MPLegBoundaryIcons.create(object.legBoundaryIcons) : undefined,
93
+ object?.elevated,
94
+ object?.elevationHeight,
95
+ object?.fitBoundsMaxZoom,
96
+ );
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Parameter interface for {@link MPDirectionsRendererOptions}.
102
+ *
103
+ * All colors are given as hex strings in the form "#RRGGBB" (e.g. "#3071D9").
104
+ * Transparency is set with the matching opacity property rather than in the color itself.
105
+ *
106
+ * @export
107
+ * @interface MPDirectionsRendererOptionsParams
108
+ * @typedef {MPDirectionsRendererOptionsParams}
109
+ */
110
+ export interface MPDirectionsRendererOptionsParams {
111
+ /**
112
+ * The color of the route line.
113
+ *
114
+ * @type {?string}
115
+ */
116
+ strokeColor?: string,
117
+ /**
118
+ * The opacity of the route line, in the range 0.0 - 1.0.
119
+ *
120
+ * @type {?number}
121
+ */
122
+ strokeOpacity?: number,
123
+ /**
124
+ * The width of the route line, in pixels.
125
+ *
126
+ * @type {?number}
127
+ */
128
+ strokeWeight?: number,
129
+ /**
130
+ * How the route line is drawn.
131
+ *
132
+ * @type {?MPStrokeStyle}
133
+ */
134
+ strokeStyle?: MPStrokeStyle,
135
+ /**
136
+ * Whether the background halo is drawn beneath the route line.
137
+ *
138
+ * @type {?boolean}
139
+ */
140
+ backgroundColorEnabled?: boolean,
141
+ /**
142
+ * The color of the background halo drawn beneath the route line.
143
+ *
144
+ * @type {?string}
145
+ */
146
+ backgroundColor?: string,
147
+ /**
148
+ * The opacity of the background halo, in the range 0.0 - 1.0.
149
+ *
150
+ * @type {?number}
151
+ */
152
+ backgroundColorOpacity?: number,
153
+ /**
154
+ * The halo padding on each side of the route line, in pixels.
155
+ *
156
+ * @type {?number}
157
+ */
158
+ backgroundColorWeight?: number,
159
+ /**
160
+ * The animation applied to the overlay travelling along the route line.
161
+ *
162
+ * @type {?MPRouteAnimationType}
163
+ */
164
+ animationType?: MPRouteAnimationType,
165
+ /**
166
+ * The animation speed, in meters per second.
167
+ *
168
+ * @type {?number}
169
+ */
170
+ animationSpeed?: number,
171
+ /**
172
+ * The lower bound for the animation duration, in seconds, which keeps short
173
+ * routes from animating too fast.
174
+ *
175
+ * @type {?number}
176
+ */
177
+ animationMinDuration?: number,
178
+ /**
179
+ * Whether the animation repeats.
180
+ *
181
+ * @type {?boolean}
182
+ */
183
+ animationRepeating?: boolean,
184
+ /**
185
+ * Whether the animation plays even when the system's reduce motion setting is enabled.
186
+ *
187
+ * @type {?boolean}
188
+ */
189
+ forceAnimation?: boolean,
190
+ /**
191
+ * The color of the animated overlay. Defaults to {@link strokeColor}.
192
+ *
193
+ * @type {?string}
194
+ */
195
+ animatedOverlayColor?: string,
196
+ /**
197
+ * The opacity of the animated overlay, in the range 0.0 - 1.0.
198
+ *
199
+ * @type {?number}
200
+ */
201
+ animatedOverlayOpacity?: number,
202
+ /**
203
+ * The width of the animated overlay, in pixels.
204
+ *
205
+ * @type {?number}
206
+ */
207
+ animatedOverlayWeight?: number,
208
+ /**
209
+ * The repeating stamp drawn along the route line.
210
+ *
211
+ * @type {?MPRouteStampType}
212
+ */
213
+ stampType?: MPRouteStampType,
214
+ /**
215
+ * The URL of the icon repeated along the route line when {@link stampType}
216
+ * is {@link MPRouteStampType.custom}.
217
+ *
218
+ * @type {?string}
219
+ */
220
+ stampImageUrl?: string,
221
+ /**
222
+ * The distance between repeated stamps, in pixels.
223
+ *
224
+ * @type {?number}
225
+ */
226
+ stampSpacing?: number,
227
+ /**
228
+ * The scale multiplier applied to the stamp icon, where 1.0 is the intrinsic size.
229
+ *
230
+ * @type {?number}
231
+ */
232
+ stampScale?: number,
233
+ /**
234
+ * The arrow shape drawn when {@link stampType} is {@link MPRouteStampType.arrow}.
235
+ *
236
+ * @type {?MPRouteArrowStyle}
237
+ */
238
+ arrowStyle?: MPRouteArrowStyle,
239
+ /**
240
+ * The tint of the built-in arrow stamp. Ignored by a custom {@link stampImageUrl}.
241
+ *
242
+ * @type {?string}
243
+ */
244
+ stampColor?: string,
245
+ /**
246
+ * The styling of the route's origin marker.
247
+ *
248
+ * @type {?MPRouteMarkerDisplayRule}
249
+ */
250
+ startDisplayRule?: MPRouteMarkerDisplayRule,
251
+ /**
252
+ * The styling of the route's destination marker.
253
+ *
254
+ * @type {?MPRouteMarkerDisplayRule}
255
+ */
256
+ endDisplayRule?: MPRouteMarkerDisplayRule,
257
+ /**
258
+ * The icons drawn where the route crosses a connector, by connector type.
259
+ *
260
+ * @type {?MPLegBoundaryIcons}
261
+ */
262
+ legBoundaryIcons?: MPLegBoundaryIcons,
263
+ /**
264
+ * Whether the whole route is lifted off the base map for a 3D effect. The lift
265
+ * is only visible when the camera is tilted.
266
+ *
267
+ * Mapbox only, the Google Maps SDKs keep the route flat.
268
+ *
269
+ * @type {?boolean}
270
+ */
271
+ elevated?: boolean,
272
+ /**
273
+ * How far the route is lifted above the ground, in meters, when {@link elevated}
274
+ * is true.
275
+ *
276
+ * Mapbox only, the Google Maps SDKs keep the route flat.
277
+ *
278
+ * @type {?number}
279
+ */
280
+ elevationHeight?: number,
281
+ /**
282
+ * The upper bound for the zoom level used when fitting the camera to the route.
283
+ *
284
+ * @type {?number}
285
+ */
286
+ fitBoundsMaxZoom?: number,
287
+ }
@@ -45,6 +45,30 @@ export default class MPError {
45
45
  */
46
46
  static readonly invalidApiKey: number = 100;
47
47
 
48
+ /**
49
+ * Occurs if base-map tile caching is attempted on a map provider that cannot cache base-map
50
+ * tiles. The Mapbox provider supports it; the Google Maps provider does not.
51
+ *
52
+ * Canonical copy. The same value is spelled out in Android's `MIError.BASEMAP_CACHE_NOT_SUPPORTED`
53
+ * and as a literal in iOS's `doRejectBaseMapCache`; drift silently reports "not supported" as a
54
+ * generic failure.
55
+ *
56
+ * @static
57
+ * @readonly
58
+ * @type {number}
59
+ */
60
+ static readonly baseMapCachingNotSupported: number = 9000;
61
+
62
+ /**
63
+ * Occurs if base-map tile caching is attempted before a map provider's base-map cache has been
64
+ * registered with the SDK.
65
+ *
66
+ * @static
67
+ * @readonly
68
+ * @type {number}
69
+ */
70
+ static readonly baseMapCacheNotRegistered: number = 9001;
71
+
48
72
  /**
49
73
  * Creates an instance of MPError.
50
74
  *
@@ -81,8 +105,31 @@ export default class MPError {
81
105
  );
82
106
  }
83
107
 
108
+ /**
109
+ * Turn a rejection from a native module into an {@link MPError}.
110
+ *
111
+ * The native modules reject with a JSON-encoded MPError, but a rejection reaching here can
112
+ * also come from the bridge itself or from JavaScript, and then the message is plain text.
113
+ * Parsing that blindly threw a SyntaxError and threw away the real message, so a caller saw
114
+ * "JSON Parse error: Unexpected character: E" instead of what actually went wrong. Fall back
115
+ * to wrapping the message as an unknown error, which keeps it readable and keeps this method's
116
+ * contract - it returns an MPError, it does not throw a different one.
117
+ *
118
+ * @public
119
+ * @static
120
+ * @param {Error} error
121
+ * @returns {MPError}
122
+ */
84
123
  public static parse(error: Error): MPError {
85
- return MPError.create(JSON.parse(error.message))
124
+ try {
125
+ const parsed = JSON.parse(error?.message);
126
+ if (parsed !== null && typeof parsed === "object" && typeof parsed.code === "number") {
127
+ return MPError.create(parsed);
128
+ }
129
+ } catch {
130
+ // Not a native MPError payload; fall through to wrapping the raw message.
131
+ }
132
+ return new MPError(MPError.unknownError, error?.message ?? "Unknown error");
86
133
  }
87
134
  }
88
135