@mapsindoors/react-native-maps-indoors-mapbox 2.9.1 → 2.10.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.
@@ -8,9 +8,28 @@ import {
8
8
  import MPBuildingCollection from './MPBuildingCollection';
9
9
  import MPVenueCollection from './MPVenueCollection';
10
10
  import { EventNames } from './EventNames';
11
+ import { forgetNativeRoutes } from './RouteHandles';
11
12
  import { OnBaseMapCacheProgressListener } from './OnBaseMapCacheProgressListener';
12
13
 
13
14
  const { MapsIndoorsModule } = NativeModules;
15
+
16
+ /**
17
+ * The published version of the map package this file is bundled into, read from its own
18
+ * package.json rather than kept as a constant so it cannot drift from the released version.
19
+ *
20
+ * It is sent on {@link MapsIndoors.load} so the native side can name this wrapper as the component
21
+ * behind the MapsIndoors Insights session. The SDK snapshots the component when the session starts,
22
+ * inside the native load, so the version has to travel on the load call itself.
23
+ */
24
+ const sdkVersion: string = (() => {
25
+ try {
26
+ // Resolved relative to this file inside the installed package: <package root>/package.json.
27
+ return require('../../package.json').version ?? 'unknown';
28
+ } catch (e) {
29
+ return 'unknown';
30
+ }
31
+ })();
32
+
14
33
  /**
15
34
  * Main class for accessing data in the MapsIndoors SDK.
16
35
  *
@@ -38,7 +57,9 @@ export default class MapsIndoors {
38
57
  * @returns {Promise<void>} If the load fails for any reason, it will reject with a {@link MPError}.
39
58
  */
40
59
  public static async load(apiKey: String, venues: String[] = null): Promise<void> {
41
- return MapsIndoorsModule.loadMapsIndoors(apiKey, venues).catch((err: Error) =>
60
+ // Native forgets its kept routes on load; keep the ids in step.
61
+ forgetNativeRoutes();
62
+ return MapsIndoorsModule.loadMapsIndoors(apiKey, venues, sdkVersion).catch((err: Error) =>
42
63
  Promise.reject(MPError.parse(err))
43
64
  );
44
65
  }
@@ -267,6 +288,12 @@ export default class MapsIndoors {
267
288
  /**
268
289
  * Run a query on all available locations with a query and filter.
269
290
  *
291
+ * Selecting one of the returned locations afterwards is reported to MapsIndoors Insights as a
292
+ * search-driven selection (`location_searched`) alongside the plain selection event, but only when
293
+ * the {@link query} carries search text: a call without it, such as a filter-only lookup, marks
294
+ * nothing and also clears the marks left by the previous text search. A location the app found by
295
+ * searching its own data outside this call is never reported as search-driven.
296
+ *
270
297
  * @public
271
298
  * @static
272
299
  * @async
@@ -372,14 +399,19 @@ export default class MapsIndoors {
372
399
  if (positonProvider) {
373
400
  const positionUpdateListener = (position: MPPositionResultInterface) => {
374
401
  if (Platform.OS === 'ios') {
402
+ // The coordinate is [lng, lat] only. floorIndex is optional, and iOS decodes the
403
+ // coordinate as numbers, so an undefined floor here becomes null in the JSON and
404
+ // every update is rejected (MS-3929). A missing floorIndex key defaults to 0 natively.
375
405
  let obj = {
376
- coordinate: [position.point.longitude, position.point.latitude, position.floorIndex],
406
+ coordinate: [position.point.longitude, position.point.latitude],
377
407
  floorIndex: position.floorIndex,
378
408
  bearing: position.bearing,
379
409
  accuracy: position.accuracy,
380
410
  providerName: position.positionProvider
381
411
  }
382
- MapsIndoorsModule.onPositionUpdate(JSON.stringify(obj));
412
+ // Nothing awaits this, so a rejected update would otherwise vanish without a trace.
413
+ MapsIndoorsModule.onPositionUpdate(JSON.stringify(obj))
414
+ .catch((err: any) => console.warn('MapsIndoors: position update rejected', err?.message ?? err));
383
415
  }else {
384
416
  MapsIndoorsModule.onPositionUpdate(JSON.stringify(position));
385
417
  }
@@ -435,6 +467,7 @@ export default class MapsIndoors {
435
467
  * @returns {Promise<void>}
436
468
  */
437
469
  public static async destroy(): Promise<void> {
470
+ forgetNativeRoutes();
438
471
  return MapsIndoorsModule.destroy().then(() => { });
439
472
  }
440
473
 
@@ -0,0 +1,76 @@
1
+ import MPRoute from './MPRoute';
2
+
3
+ /**
4
+ * Links each {@link MPRoute} that {@link MPDirectionsService.getRoute} returns to the native route it
5
+ * was encoded from, so {@link MPDirectionsRenderer.setRoute} can render that native instance instead
6
+ * of decoding a copy (SPEX-2782).
7
+ *
8
+ * Only the native instance knows the route's resolved endpoints, which the SDK reports with the
9
+ * directions Insights events. Neither SDK serialises them, so every decoded copy reports none.
10
+ * Rendering one native instance repeatedly is safe: its endpoints are resolved once and read on every
11
+ * event, never consumed.
12
+ *
13
+ * Keyed by the route's JSON rather than by object, so a route that went through JSON on the app's
14
+ * side, such as a state store or navigation params, still finds its native route. An edited route has
15
+ * different JSON and finds none, so it reports no endpoints rather than ones it may no longer have.
16
+ */
17
+
18
+ /** Matches the native stores, which forget the least recently used route past this many. */
19
+ const CAPACITY = 10;
20
+
21
+ /** Native route ids by route JSON, least recently used first. */
22
+ const ids = new Map<string, string>();
23
+
24
+ let warned = false;
25
+
26
+ /** Records the native route behind a route that {@link MPDirectionsService} just created. */
27
+ export function attachNativeRoute(route: MPRoute, id: string | undefined): void {
28
+ if (!id) {
29
+ return;
30
+ }
31
+ const json = JSON.stringify(route);
32
+ ids.delete(json);
33
+ ids.set(json, id);
34
+ if (ids.size > CAPACITY) {
35
+ ids.delete(ids.keys().next().value!);
36
+ }
37
+ }
38
+
39
+ /**
40
+ * The id of the native route to render in place of `json`, or null to decode `json`.
41
+ *
42
+ * @param json The route as JSON, which the caller sends across the bridge anyway.
43
+ */
44
+ export function nativeRouteId(json: string): string | null {
45
+ const id = ids.get(json);
46
+ if (id === undefined) {
47
+ warnOnce();
48
+ return null;
49
+ }
50
+ ids.delete(json);
51
+ ids.set(json, id);
52
+ return id;
53
+ }
54
+
55
+ /**
56
+ * Forgets every route, as the native stores do when MapsIndoors loads or is destroyed: the routes
57
+ * belong to the solution that was loaded when they were requested.
58
+ */
59
+ export function forgetNativeRoutes(): void {
60
+ ids.clear();
61
+ }
62
+
63
+ /**
64
+ * The fallback is legitimate for a route the app built, but it is also how these endpoints went
65
+ * missing unnoticed before, so development builds say so once.
66
+ */
67
+ function warnOnce(): void {
68
+ if (warned || !(globalThis as { __DEV__?: boolean }).__DEV__) {
69
+ return;
70
+ }
71
+ warned = true;
72
+ console.warn(
73
+ 'MapsIndoors: setRoute was given a route MPDirectionsService.getRoute did not return, or one changed ' +
74
+ 'since. It renders, but directions analytics will not attribute its origin and destination.'
75
+ );
76
+ }