@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,4 +1,4 @@
1
- import { NativeModules, Platform } from 'react-native';
1
+ import { EmitterSubscription, NativeEventEmitter, NativeModules, Platform } from 'react-native';
2
2
  import {
3
3
  MPMapStyle,
4
4
  MPLocation, MPSolution, MPVenue, MPQuery, MPFilter,
@@ -7,6 +7,8 @@ import {
7
7
  } from "../../index";
8
8
  import MPBuildingCollection from './MPBuildingCollection';
9
9
  import MPVenueCollection from './MPVenueCollection';
10
+ import { EventNames } from './EventNames';
11
+ import { OnBaseMapCacheProgressListener } from './OnBaseMapCacheProgressListener';
10
12
 
11
13
  const { MapsIndoorsModule } = NativeModules;
12
14
  /**
@@ -117,7 +119,7 @@ export default class MapsIndoors {
117
119
  */
118
120
  public static async getLocations(): Promise<MPLocation[]> {
119
121
  return MapsIndoorsModule.getLocations()
120
- .catch((err: Error) => {Promise.reject(MPError.parse(err))})
122
+ .catch((err: Error) => Promise.reject(MPError.parse(err)))
121
123
  .then((locationsString: string) => {
122
124
  const locations: MPLocation[] = JSON.parse(locationsString).map((location: any) => MPLocation.create(location));
123
125
  return Promise.resolve(locations);
@@ -175,7 +177,8 @@ export default class MapsIndoors {
175
177
  * @returns {Promise<string>}
176
178
  */
177
179
  public static async getDefaultLanguage(): Promise<string> {
178
- return MapsIndoorsModule.getDefaultLanguage();
180
+ return MapsIndoorsModule.getDefaultLanguage()
181
+ .catch((err: Error) => Promise.reject(MPError.parse(err)));
179
182
  }
180
183
 
181
184
  /**
@@ -187,6 +190,9 @@ export default class MapsIndoors {
187
190
  * @returns {Promise<string>}
188
191
  */
189
192
  public static async getLanguage(): Promise<string> {
193
+ // No MPError mapping on purpose: neither native has a reject path here. iOS resolves a
194
+ // non-optional String and Android a @NonNull one, both with their own fallback chain, so a
195
+ // catch would be dead code.
190
196
  return MapsIndoorsModule.getLanguage();
191
197
  }
192
198
 
@@ -250,10 +256,12 @@ export default class MapsIndoors {
250
256
  * @returns {Promise<MPSolution>}
251
257
  */
252
258
  public static async getSolution(): Promise<MPSolution> {
253
- return MapsIndoorsModule.getSolution().then((solutionString: string) => {
254
- const solution: MPSolution = MPSolution.create(JSON.parse(solutionString));
255
- return Promise.resolve(solution);
256
- });
259
+ return MapsIndoorsModule.getSolution()
260
+ .catch((err: Error) => Promise.reject(MPError.parse(err)))
261
+ .then((solutionString: string) => {
262
+ const solution: MPSolution = MPSolution.create(JSON.parse(solutionString));
263
+ return Promise.resolve(solution);
264
+ });
257
265
  }
258
266
 
259
267
  /**
@@ -469,18 +477,48 @@ export default class MapsIndoors {
469
477
  /**
470
478
  * Sets the SDK's internal language.
471
479
  *
472
- * By default, the SDK language can be:
480
+ * The tag should be one the solution advertises - see {@link getAvailableLanguages} - and is
481
+ * matched loosely: casing is ignored, and legacy region-only Chinese tags resolve to their
482
+ * script, so `zh-CN` selects `zh-Hans` and `zh-TW` selects `zh-Hant`. Use
483
+ * {@link MPSolution.hasLanguage} to check a tag before calling, or
484
+ * {@link MPSolution.resolveLanguage} to turn a device locale into the exact tag the solution
485
+ * publishes.
486
+ *
487
+ * Until this is called, the SDK language is:
473
488
  *
474
- * * the solution's default language ({@link MPSolutionInfo#getDefaultLanguage()}).
475
- * * the current device language, if the MapsIndoors data isn't available (ie: first app run without network access).
489
+ * * the solution's default language - see {@link getDefaultLanguage}.
490
+ * * the current device language, if the MapsIndoors data isn't available (ie: first app run
491
+ * without network access).
492
+ *
493
+ * The returned boolean does not mean the same thing on both platforms, and an app should not
494
+ * branch on it without reading this:
495
+ *
496
+ * * On **Android** it is `false` when the tag does not resolve against the solution's
497
+ * available languages, and also when the SDK has no solution yet or is mid-
498
+ * {@link synchronizeContent}. In that second case the change is *queued* and applied once
499
+ * the SDK is ready, so `false` is not "it will never take effect".
500
+ * * On **iOS** it reports only that the tag was accepted; there is no check against the
501
+ * solution's available languages, so in the default configuration it is `true` for any
502
+ * non-empty tag. An unsupported language is reconciled later, on the next solution fetch,
503
+ * which reverts the SDK to the solution's default.
504
+ *
505
+ * A `false` here is therefore a reliable "this did not take effect" signal on Android only. To
506
+ * confirm the language actually changed on either platform, read it back with
507
+ * {@link getLanguage}.
508
+ *
509
+ * An empty or whitespace-only tag resolves `false` without reaching the native SDK, matching
510
+ * Android's own precondition. iOS would otherwise accept it and store an empty language.
476
511
  *
477
512
  * @public
478
513
  * @static
479
514
  * @async
480
- * @param {string} language
515
+ * @param {string} language A BCP-47 language tag, for example `en`, `zh-Hans` or `zh-CN`.
481
516
  * @returns {Promise<boolean>}
482
517
  */
483
518
  public static async setLanguage(language: string): Promise<boolean> {
519
+ if (!language?.trim()) {
520
+ return false;
521
+ }
484
522
  return MapsIndoorsModule.setLanguage(language);
485
523
  }
486
524
 
@@ -568,4 +606,110 @@ export default class MapsIndoors {
568
606
  public static async cacheData(apiKey: String): Promise<boolean> {
569
607
  return MapsIndoorsModule.cacheData(apiKey);
570
608
  }
609
+
610
+ /**
611
+ * Checks whether the map provider in use can cache base-map tiles at all.
612
+ *
613
+ * Base-map tiles are the outdoor map rendered underneath MapsIndoors, and they live in the map
614
+ * provider's own storage - separate from the MapsIndoors content cached by {@link cacheData}.
615
+ * Only the Mapbox provider can cache them; on the Google Maps provider this returns false and
616
+ * every other base-map caching call rejects with {@link MPError.baseMapCachingNotSupported}.
617
+ *
618
+ * Check this before offering offline base maps in the UI, so an unsupported provider fails fast
619
+ * instead of once per venue.
620
+ *
621
+ * @public
622
+ * @static
623
+ * @async
624
+ * @returns {Promise<boolean>} True if base-map tiles can be cached.
625
+ */
626
+ public static async isBaseMapCachingSupported(): Promise<boolean> {
627
+ return MapsIndoorsModule.isBaseMapCachingSupported();
628
+ }
629
+
630
+ /**
631
+ * Enables or disables base-map tile caching for the solution matching the given {@link apiKey}.
632
+ *
633
+ * The flag only marks the solution, it downloads nothing - call
634
+ * {@link synchronizeBaseMapTiles} for that. Turning it off does not remove already-cached
635
+ * tiles either; those are reclaimed when the solution's cache is removed.
636
+ *
637
+ * The flag is persisted, so it survives an app restart and only has to be set once.
638
+ *
639
+ * It is a property of the solution, not of the map provider, so it is accepted and stored even
640
+ * where {@link isBaseMapCachingSupported} is false - on Google Maps this resolves successfully
641
+ * and sets a flag nothing can act on, and only {@link synchronizeBaseMapTiles} reports
642
+ * {@link MPError.baseMapCachingNotSupported}. Check {@link isBaseMapCachingSupported} first if
643
+ * you need to know before then. Rejecting here instead would make the same call behave
644
+ * differently per map provider, which is worse for code meant to run against either.
645
+ *
646
+ * @public
647
+ * @static
648
+ * @async
649
+ * @param {boolean} enabled True to cache base-map tiles for this solution.
650
+ * @param {string} apiKey The key to the MapsIndoors solution.
651
+ * @returns {Promise<void>} If the solution is not managed, or the call fails for any other
652
+ * reason, it will reject with a {@link MPError}.
653
+ */
654
+ public static async setBaseMapTilesEnabled(enabled: boolean, apiKey: string): Promise<void> {
655
+ return MapsIndoorsModule.setBaseMapTilesEnabled(enabled, apiKey)
656
+ .then(() => { })
657
+ .catch((err: Error) => Promise.reject(MPError.parse(err)));
658
+ }
659
+
660
+ /**
661
+ * Downloads and caches base-map tiles so the map can render without a network connection.
662
+ *
663
+ * Covers every solution that base-map tile caching has been enabled for with
664
+ * {@link setBaseMapTilesEnabled}, unless {@link apiKeys} narrows it to a subset. This is a
665
+ * long-running network download that can take minutes - pass {@link onProgress} to follow it.
666
+ *
667
+ * This runs independently of {@link synchronizeContent} and {@link cacheData}, which cache the
668
+ * MapsIndoors content itself. Both are needed for a fully offline map.
669
+ *
670
+ * On iOS, a {@link MapView} has to have been mounted at least once first: the iOS SDK registers
671
+ * its base-map cache when it builds the map provider, and until then this rejects with
672
+ * {@link MPError.baseMapCachingNotSupported} even on Mapbox. Android has no such ordering
673
+ * requirement.
674
+ *
675
+ * Run one call at a time. Progress arrives on a single channel carrying only the fraction, with
676
+ * nothing identifying the call, so two overlapping calls interleave their progress - including
677
+ * into a caller that passed no {@link onProgress} of its own. The default already covers every
678
+ * enabled solution in one call, so there is rarely a reason to fan out.
679
+ *
680
+ * @public
681
+ * @static
682
+ * @async
683
+ * @param {OnBaseMapCacheProgressListener} [onProgress] Optional listener called with the
684
+ * fraction completed, from 0.0 to 1.0. Not every map provider reports progress.
685
+ * @param {string[]} [apiKeys] An optional list of solution API keys to narrow the operation to.
686
+ * Defaults to every solution with base-map tile caching enabled. An empty array narrows it to
687
+ * nothing and caches nothing, which is deliberately not the same as omitting the argument - a
688
+ * filter that matched no solutions should not turn into a download of all of them.
689
+ * @returns {Promise<void>} Rejects with a {@link MPError} if the map provider cannot cache
690
+ * base-map tiles ({@link MPError.baseMapCachingNotSupported}) or a download fails.
691
+ */
692
+ public static async synchronizeBaseMapTiles(onProgress?: OnBaseMapCacheProgressListener, apiKeys?: string[]): Promise<void> {
693
+ let subscription: EmitterSubscription | undefined;
694
+ if (onProgress) {
695
+ // Subscribed before the call rather than in the module's constructor: the native side only
696
+ // emits while a download is running, and an always-live subscription would keep the JS
697
+ // callback alive for the lifetime of the app.
698
+ subscription = new NativeEventEmitter(MapsIndoorsModule)
699
+ .addListener(EventNames.onBaseMapCacheProgress, (event: { progress: number }) => onProgress(event.progress));
700
+ }
701
+
702
+ // try/finally rather than .finally() on the chain: the native method is invoked before the
703
+ // chain exists, so a synchronous throw there - a JS package newer than the native one, whose
704
+ // module has no such method - would otherwise leave the subscription holding onProgress for
705
+ // the lifetime of the app. Only a rejection is parsed as an MPError; a synchronous throw is
706
+ // not ours to reinterpret, so it propagates as it is.
707
+ try {
708
+ return await MapsIndoorsModule.synchronizeBaseMapTiles(apiKeys ? apiKeys : null)
709
+ .then(() => { })
710
+ .catch((err: Error) => Promise.reject(MPError.parse(err)));
711
+ } finally {
712
+ subscription?.remove();
713
+ }
714
+ }
571
715
  }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Listener that is invoked while base-map tiles are being cached for offline use.
3
+ *
4
+ * Caching base-map tiles is a long-running network download that can take minutes, so progress is
5
+ * reported as it goes. Progress is not guaranteed to reach 1.0 before
6
+ * {@link MapsIndoors.synchronizeBaseMapTiles} resolves, and it is not guaranteed to be reported at
7
+ * all - a map provider that cannot determine progress only reports completion.
8
+ *
9
+ * @export
10
+ * @interface OnBaseMapCacheProgressListener
11
+ * @typedef {OnBaseMapCacheProgressListener}
12
+ */
13
+ export interface OnBaseMapCacheProgressListener {
14
+ /**
15
+ * When the caching operation has progressed.
16
+ *
17
+ * @param {number} progress The fraction of the operation that has completed, from 0.0 to 1.0.
18
+ */
19
+ (progress: number): void;
20
+ }
@@ -6,5 +6,9 @@
6
6
  * @typedef {RouteStopIconConfig}
7
7
  */
8
8
  export interface RouteStopIconConfig {
9
- getImage(): URL;
9
+ /**
10
+ * The icon image. An http(s) URL is downloaded by the native SDK; anything else is passed on as
11
+ * an encoded MPRouteStopIconConfig.
12
+ */
13
+ getImage(): URL | string;
10
14
  }