@mapsindoors/react-native-maps-indoors-mapbox 2.8.0 → 2.9.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.
Files changed (45) hide show
  1. package/README.md +84 -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 +162 -1
  17. package/ios/core/DirectionsRendererOptions.swift +352 -0
  18. package/ios/core/MapsIndoorsBridge.m +14 -1
  19. package/ios/core/MapsIndoorsData.swift +1 -0
  20. package/ios/core/MapsIndoorsModule.swift +180 -21
  21. package/ios/core/UtilsModule.swift +57 -45
  22. package/package.json +1 -1
  23. package/react-native-maps-indoors-mapbox.podspec +2 -2
  24. package/specs/NativeDirectionsRendererModule.ts +3 -0
  25. package/specs/NativeMapsIndoorsModule.ts +6 -1
  26. package/src/core/EventNames.ts +3 -0
  27. package/src/core/MPDirectionsRenderer.ts +76 -1
  28. package/src/core/MPDirectionsRendererOptions.ts +287 -0
  29. package/src/core/MPError.ts +48 -1
  30. package/src/core/MPLanguageTag.ts +222 -0
  31. package/src/core/MPLegBoundaryIcons.ts +130 -0
  32. package/src/core/MPRouteAnimationType.ts +24 -0
  33. package/src/core/MPRouteArrowStyle.ts +28 -0
  34. package/src/core/MPRouteMarkerDisplayRule.ts +140 -0
  35. package/src/core/MPRouteStampType.ts +24 -0
  36. package/src/core/MPSolution.ts +33 -2
  37. package/src/core/MPStrokeStyle.ts +22 -0
  38. package/src/core/MapsIndoors.ts +155 -11
  39. package/src/core/OnBaseMapCacheProgressListener.ts +20 -0
  40. package/src/core/__tests__/MPBounds.test.ts +109 -0
  41. package/src/core/__tests__/MPFilter.test.ts +76 -0
  42. package/src/core/__tests__/MPLanguageTag.test.ts +168 -0
  43. package/src/core/__tests__/MPPoint.test.ts +82 -0
  44. package/src/core/__tests__/MPSolution.test.ts +107 -0
  45. package/src/core/__tests__/MapsIndoors.language.test.ts +180 -0
@@ -5,8 +5,26 @@ import MapsIndoorsCore
5
5
  import React
6
6
 
7
7
  @objc(MapsIndoorsModule)
8
- public class MapsIndoorsModule: NSObject {
9
- @objc public static func requiresMainQueueSetup() -> Bool { return false }
8
+ public class MapsIndoorsModule: RCTEventEmitter {
9
+ @objc public override static func requiresMainQueueSetup() -> Bool { return false }
10
+
11
+ /// Base override for RCTEventEmitter.
12
+ ///
13
+ /// - Returns: all supported events
14
+ @objc open override func supportedEvents() -> [String] {
15
+ return MapsIndoorsData.sharedInstance.allEvents
16
+ }
17
+
18
+ /// Whether JavaScript currently has a listener attached to this emitter.
19
+ ///
20
+ /// Base-map cache progress is only emitted while this is true: `synchronizeBaseMapTiles` is
21
+ /// callable without a progress listener, and RCTEventEmitter logs a warning for every event sent
22
+ /// with nothing listening.
23
+ private var hasListeners = false
24
+
25
+ public override func startObserving() { hasListeners = true }
26
+
27
+ public override func stopObserving() { hasListeners = false }
10
28
 
11
29
  @objc public func test() {
12
30
  print("%@.test()", String(describing: self))
@@ -14,6 +32,9 @@ public class MapsIndoorsModule: NSObject {
14
32
 
15
33
  private var positionProvider: ReactPositionProvider?
16
34
 
35
+ /// Keeps the `cacheData` delegate alive while a dataset sync runs - see the note in `cacheData`.
36
+ private var datasetDelegate: DatasetDelegate?
37
+
17
38
  @objc(loadMapsIndoors:optionalStrings:resolver:rejecter:)
18
39
  func loadMapsIndoors(apiKey: String, optionalStrings: [String]?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
19
40
  Task {
@@ -93,7 +114,7 @@ public class MapsIndoorsModule: NSObject {
93
114
  let languages = solution.availableLanguages
94
115
  return resolve(languages)
95
116
  } else {
96
- reject("1", "getAvailableLanguages: solution is not available. Try loading first", nil)
117
+ return doReject(reject, message: "getAvailableLanguages: solution is not available. Try loading first")
97
118
  }
98
119
  }
99
120
 
@@ -102,7 +123,7 @@ public class MapsIndoorsModule: NSObject {
102
123
  let defaultLanguage = solution.defaultLanguage
103
124
  return resolve(defaultLanguage)
104
125
  } else {
105
- reject("1", "getDefaultLanguage: solution is not available. Try loading first", nil)
126
+ return doReject(reject, message: "getDefaultLanguage: solution is not available. Try loading first")
106
127
  }
107
128
  }
108
129
 
@@ -146,7 +167,7 @@ public class MapsIndoorsModule: NSObject {
146
167
  if let solution = MPMapsIndoors.shared.solution {
147
168
  return resolve(toJSON(MPSolutionCodable(withSolution: solution)))
148
169
  } else {
149
- return reject("1", "getSolution: solution is not available. Try loading first", nil)
170
+ return doReject(reject, message: "getSolution: solution is not available. Try loading first")
150
171
  }
151
172
  }
152
173
 
@@ -249,7 +270,7 @@ public class MapsIndoorsModule: NSObject {
249
270
  @objc public func getDefaultVenue(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
250
271
  Task {
251
272
  guard let defaultVenue = await MPMapsIndoors.shared.venues().first else {
252
- return reject("1", "no venues exist. Make sure MapsIndoors is ready", nil)
273
+ return doReject(reject, message: "getDefaultVenue: no venues exist. Make sure MapsIndoors is ready")
253
274
  }
254
275
  return resolve(toJSON(MPVenueCodable(withVenue: defaultVenue)))
255
276
  }
@@ -258,7 +279,7 @@ public class MapsIndoorsModule: NSObject {
258
279
  @objc public func checkOfflineDataAvailability(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
259
280
  Task {
260
281
  guard let key = MPMapsIndoors.shared.apiKey else {
261
- return reject("1", "isApiKeyValid: API key not set", nil)
282
+ return doReject(reject, message: "checkOfflineDataAvailability: API key not set")
262
283
  }
263
284
 
264
285
  return resolve(await MPMapsIndoors.shared.isOfflineDataAvailable(apiKey: key))
@@ -277,9 +298,17 @@ public class MapsIndoorsModule: NSObject {
277
298
  return resolve(MapsIndoorsData.sharedInstance.isInitialized)
278
299
  }
279
300
 
301
+ /// Sets the SDK language and reports whether the write was accepted.
302
+ ///
303
+ /// `MILanguage.setLanguage` and the `MPMapsIndoors.shared.language` setter it replaces here
304
+ /// reach the same storage: the setter routes through `MapsIndoorsLegacy.setLanguage` to
305
+ /// `MILanguage.language`, which is the same provider property `setLanguage` assigns after
306
+ /// normalizing the tag. Same UserDefaults write, same `MILanguage` change notification, same
307
+ /// `languageChanged` log event - the only new thing is the return value, which a property
308
+ /// setter had no way to surface. JavaScript has always declared `Promise<boolean>` here and
309
+ /// always received `null`.
280
310
  @objc public func setLanguage(_ language: String, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
281
- MPMapsIndoors.shared.language = language
282
- return resolve(nil)
311
+ return resolve(MILanguage.setLanguage(language))
283
312
  }
284
313
 
285
314
  @objc public func synchronizeContent(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
@@ -328,30 +357,160 @@ public class MapsIndoorsModule: NSObject {
328
357
  if dataSet == nil {
329
358
  dataSet = datasetCacheManager.addDataSet(apiKey, cachingScope: .full)
330
359
  }
331
- if dataSet == nil {
360
+ guard let dataSet else {
332
361
  return resolve(false)
333
362
  }
334
363
 
335
- datasetCacheManager.delegate = DatasetDelegate(promise: resolve, dataset: dataSet!.cacheItem)
364
+ // Rejected rather than queued or run alongside. The manager's delegate is a single slot, so a
365
+ // second call overwrote it, deallocated the first delegate - the slot is `weak` - and stranded
366
+ // the first promise forever: the same silent hang this delegate exists to fix, narrowed from
367
+ // always to on overlap. Holding the slot until the running call settles also keeps that call's
368
+ // completion from nilling a later call's delegate.
369
+ guard datasetDelegate == nil else {
370
+ return doReject(reject, message: "A cacheData call is already running; wait for it to finish before starting another")
371
+ }
372
+
373
+ // Held by the module for the length of the sync. MPDataSetCacheManager.delegate is `weak`, so a
374
+ // delegate constructed inline in this statement is deallocated before the download it is waiting
375
+ // on can finish - the callback never arrives and the promise never settles, leaving the caller
376
+ // waiting forever with no error (SPEX-2481).
377
+ let delegate = DatasetDelegate(dataset: dataSet.cacheItem) { [weak self] success in
378
+ self?.datasetDelegate = nil
379
+ resolve(success)
380
+ }
381
+ datasetDelegate = delegate
382
+ datasetCacheManager.delegate = delegate
383
+
384
+ datasetCacheManager.synchronizeCacheItems([dataSet.cacheItem])
385
+ }
386
+
387
+ @objc(isBaseMapCachingSupported:rejecter:)
388
+ func isBaseMapCachingSupported(resolve: RCTPromiseResolveBlock, reject _: RCTPromiseRejectBlock) {
389
+ // Answered from which provider this package is built against, not from the SDK: the provider
390
+ // seam that knows is SPI, and the SDK only registers an implementation once a map provider has
391
+ // been constructed - so asking it would report false before the first map view exists, which is
392
+ // exactly when an app wants to decide whether to offer offline base maps at all.
393
+ //
394
+ // The module is MapsIndoorsMapbox; the *pod* is MapsIndoorsMapbox11. canImport takes the module
395
+ // name, and naming the pod here silently compiles to the unsupported branch on every build -
396
+ // which is what a `#if` gets you when it is wrong. MapsIndoorsViewManager.swift in the Mapbox
397
+ // package imports this same name.
398
+ #if canImport(MapsIndoorsMapbox)
399
+ return resolve(true)
400
+ #else
401
+ return resolve(false)
402
+ #endif
403
+ }
404
+
405
+ @objc(setBaseMapTilesEnabled:apiKey:resolver:rejecter:)
406
+ func setBaseMapTilesEnabled(enabled: Bool, apiKey: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
407
+ let datasetCacheManager = MPMapsIndoors.shared.datasetCacheManager
408
+
409
+ if let dataSet = datasetCacheManager.dataSetWithId(apiKey) {
410
+ datasetCacheManager.setBaseMapTilesEnabled(enabled, cacheItem: dataSet.cacheItem)
411
+ } else if datasetCacheManager.addDataSet(apiKey, cachingScope: .full, baseMapTilesEnabled: enabled) == nil {
412
+ // Managed from here on with the same `.full` scope cacheData uses: there is nothing to flag
413
+ // otherwise, and base-map caching needs the dataset's venues to know what to cache around.
414
+ return doReject(reject, message: "Unable to manage dataset '\(apiKey)'")
415
+ }
336
416
 
337
- datasetCacheManager.synchronizeCacheItems([dataSet!.cacheItem])
417
+ return resolve(nil)
418
+ }
419
+
420
+ @objc(synchronizeBaseMapTiles:resolver:rejecter:)
421
+ func synchronizeBaseMapTiles(apiKeys: [String]?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
422
+ let datasetCacheManager = MPMapsIndoors.shared.datasetCacheManager
423
+ var dataSets = [MPDataSetCache]()
424
+
425
+ if let apiKeys {
426
+ for apiKey in apiKeys {
427
+ guard let dataSet = datasetCacheManager.dataSetWithId(apiKey) else {
428
+ // Rejected rather than skipped: an explicit list is an explicit instruction, and
429
+ // silently caching nothing for a key the caller named is the harder failure to spot.
430
+ return doReject(reject, message: "No dataset is managed for '\(apiKey)', so base-map tiles cannot be cached for it")
431
+ }
432
+
433
+ dataSets.append(dataSet)
434
+ }
435
+ }
436
+
437
+ let progress: @Sendable (Double) -> Void = { [weak self] fraction in
438
+ guard let self, self.hasListeners else { return }
439
+ self.sendEvent(withName: MapsIndoorsData.Event.onBaseMapCacheProgress.rawValue, body: ["progress": fraction])
440
+ }
441
+
442
+ Task {
443
+ do {
444
+ if apiKeys == nil {
445
+ try await datasetCacheManager.synchronizeBaseMapTiles(progress: progress)
446
+ } else {
447
+ try await datasetCacheManager.synchronizeBaseMapTiles(dataSets, progress: progress)
448
+ }
449
+ return resolve(nil)
450
+ } catch let e {
451
+ return doRejectBaseMapCache(reject, error: e)
452
+ }
453
+ }
338
454
  }
339
455
  }
340
456
 
457
+ /// Rejects a base-map caching call, preserving the one error code the React Native API documents.
458
+ ///
459
+ /// 9000 is the third copy of that value: Android's `MIError.BASEMAP_CACHE_NOT_SUPPORTED`, this
460
+ /// literal, and core's `MPError.baseMapCachingNotSupported` in TypeScript. Nothing links them, so a
461
+ /// change to one has to be made to all three.
462
+ ///
463
+ /// The shared `doReject` reports everything as `unknownError`, which would leave JavaScript unable to
464
+ /// tell "this map provider cannot cache base-map tiles" - the expected outcome on a Google Maps build,
465
+ /// and the one an app should handle - apart from a download that failed. The code matches the Android
466
+ /// SDK's `MIError.BASEMAP_CACHE_NOT_SUPPORTED`, so one check in JavaScript works on both platforms.
467
+ private func doRejectBaseMapCache(_ reject: RCTPromiseRejectBlock, error: Error) {
468
+ guard let mpError = error as? MPError, mpError == .baseMapCachingNotSupported else {
469
+ return doReject(reject, error: error)
470
+ }
471
+
472
+ struct BaseMapCacheError: Codable {
473
+ let code: Int
474
+ let message: String
475
+ }
476
+
477
+ let err = BaseMapCacheError(code: 9000, message: String(describing: mpError))
478
+
479
+ return reject("NativeError", toJSON(err), error)
480
+ }
481
+
341
482
  class DatasetDelegate: NSObject, MPDataSetCacheManagerDelegate {
342
- var promise: RCTPromiseResolveBlock
343
- var dataset: MPDataSetCacheItem
483
+ private let dataset: MPDataSetCacheItem
484
+ private let completion: (Bool) -> Void
485
+ private var hasCompleted = false
344
486
 
345
- init(promise: @escaping RCTPromiseResolveBlock, dataset: MPDataSetCacheItem) {
346
- self.promise = promise
487
+ init(dataset: MPDataSetCacheItem, completion: @escaping (Bool) -> Void) {
347
488
  self.dataset = dataset
489
+ self.completion = completion
348
490
  }
349
491
 
350
492
  func dataSetManager(_ dataSetManager: MPDataSetCacheManager, didFinishSynchronizingItem item: MPDataSetCacheItem) {
351
- if item.cachingItemId == dataset.cachingItemId {
352
- return promise(true)
353
- } else {
354
- return promise(false)
355
- }
493
+ // Only this dataset settles the promise. Any other item finishing first used to resolve it
494
+ // `false` and then let this one resolve it a second time.
495
+ guard item.cachingItemId == dataset.cachingItemId else { return }
496
+
497
+ settle(success: item.syncResult == nil)
498
+ }
499
+
500
+ func dataSetManagerDidFinishSynchronizing(_ dataSetManager: MPDataSetCacheManager) {
501
+ // Backstop. didFinishSynchronizingItem is the precise signal, but nothing guarantees it fires
502
+ // for this item, and this whole class exists because a promise hung silently when its callback
503
+ // never arrived. The manager-level completion settles anything still outstanding, so that
504
+ // failure mode cannot recur in a different shape.
505
+ settle(success: dataset.syncResult == nil)
506
+ }
507
+
508
+ private func settle(success: Bool) {
509
+ guard !hasCompleted else { return }
510
+
511
+ hasCompleted = true
512
+ // The manager reports a failed sync on the item rather than through a separate callback, so
513
+ // without this a failure would resolve `true` exactly like a success.
514
+ completion(success)
356
515
  }
357
516
  }
@@ -47,40 +47,56 @@ public class UtilsModule: NSObject {
47
47
  return resolve(MPGeometryUtils.distance(from: MPGeoPoint(coordinate: it.coordinate), to: MPGeoPoint(coordinate: other.coordinate)))
48
48
  }
49
49
 
50
+
51
+ /// Decodes a GeoJSON geometry string into something queryable.
52
+ ///
53
+ /// `JSONDecoder().decode(MPGeometry.self, ...)` always produces a *base* `MPGeometry` - Swift's
54
+ /// decoder is not polymorphic - so `geo is MPPolygonGeometry` and `geo as? MPPolygonGeometry`
55
+ /// were always false here, and the SDK's `mp_polygon` / `mp_multiPolygon` accessors are an
56
+ /// internal NSObject category holding associated objects that nothing sets on a freshly decoded
57
+ /// value, so they were always nil. Every geometry helper in this file therefore fell through to
58
+ /// its default branch: `geometryIsInside` always answered false, `geometryArea` always 0, and
59
+ /// `polygonDistanceToClosestEdge` resolved nil.
60
+ ///
61
+ /// Decoding the concrete type by its GeoJSON `type` discriminator fixes all three, and mirrors
62
+ /// how the Android module dispatches on `geometry.getType()`.
63
+ private func decodeQueryableGeometry(_ geometry: String) -> (any MPGeometryQueryProtocol)? {
64
+ let data = Data(geometry.utf8)
65
+
66
+ guard let base = try? JSONDecoder().decode(MPGeometry.self, from: data) else {
67
+ return nil
68
+ }
69
+
70
+ switch base.type {
71
+ case "Polygon":
72
+ return try? JSONDecoder().decode(MPPolygonGeometry.self, from: data)
73
+ case "MultiPolygon":
74
+ return try? JSONDecoder().decode(MPMultiPolygonGeometry.self, from: data)
75
+ default:
76
+ return nil
77
+ }
78
+ }
79
+
50
80
  @objc public func geometryIsInside(_ point: String, geometry: String, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
51
81
  guard let it = try? JSONDecoder().decode(MPPoint.self, from: Data(point.utf8)) as MPPoint else {
52
82
  return reject("Utils error", "Venue not found for current Solution", MPError.unknownError)
53
83
  }
54
84
 
55
- guard let geo = try? JSONDecoder().decode(MPGeometry.self, from: Data(geometry.utf8)) as MPGeometry else {
56
- return reject("Utils error", "Venue not found for current Solution", MPError.unknownError)
85
+ guard let geo = decodeQueryableGeometry(geometry) else {
86
+ // Not a polygon or multi-polygon: nothing can be inside it.
87
+ return resolve(false)
57
88
  }
58
89
 
59
- if geo is MPPolygonGeometry {
60
- let poly = geo.mp_polygon
61
- return resolve(poly?.containsCoordinate(it.coordinate))
62
- } else if geo is MPMultiPolygonGeometry {
63
- let multiPoly = geo.mp_multiPolygon
64
- resolve(multiPoly?.containsCoordinate(it.coordinate))
65
- } else {
66
- resolve(false)
67
- }
90
+ return resolve(geo.containsCoordinate(it.coordinate))
68
91
  }
69
92
 
70
93
  @objc public func geometryArea(_ geometry: String, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
71
- guard let geo = try? JSONDecoder().decode(MPGeometry.self, from: Data(geometry.utf8)) as MPGeometry else {
72
- return reject("Utils error", "Venue not found for current Solution", MPError.unknownError)
73
- }
74
-
75
- if geo is MPPolygonGeometry {
76
- let poly = geo.mp_polygon
77
- return resolve(poly?.area)
78
- } else if geo is MPMultiPolygonGeometry {
79
- let multiPoly = geo.mp_multiPolygon
80
- return resolve(multiPoly?.area)
81
- } else {
94
+ guard let geo = decodeQueryableGeometry(geometry) else {
95
+ // A point or line has no area.
82
96
  return resolve(0)
83
97
  }
98
+
99
+ return resolve(geo.area)
84
100
  }
85
101
 
86
102
  @objc public func polygonDistanceToClosestEdge(_ point: String, geometry: String, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
@@ -88,29 +104,25 @@ public class UtilsModule: NSObject {
88
104
  return reject("Utils error", "Venue not found for current Solution", MPError.unknownError)
89
105
  }
90
106
 
91
- guard let geo = try? JSONDecoder().decode(MPGeometry.self, from: Data(geometry.utf8)) as MPGeometry else {
92
- return reject("Utils error", "Venue not found for current Solution", MPError.unknownError)
93
- }
94
-
95
- if geo is MPPolygonGeometry {
96
- guard let outerRing = (geo.mp_polygon.coordinates.first?.map { CLLocationCoordinate2D(latitude: $0.latitude, longitude: $0.longitude) }) else {
97
- return reject("Utils error", "Venue not found for current Solution", MPError.unknownError)
98
- }
99
-
100
- var shortestDistance = Double.greatestFiniteMagnitude
101
- for i in 1..<outerRing.count {
102
- let p1 = outerRing[i - 1]
103
- let p2 = outerRing[i]
104
-
105
- let distanceToLine = MPGeometryUtils.distancePointToLine(point: it.coordinate, lineStart: p1, lineEnd: p2)
106
- if distanceToLine < shortestDistance {
107
- shortestDistance = distanceToLine
108
- }
109
- }
110
-
111
- return resolve(shortestDistance)
112
- }
113
- return resolve(nil)
107
+ // Handles both Polygon and MultiPolygon, and lets the SDK do the maths. The hand-rolled
108
+ // loop this replaces walked only the outer ring - ignoring holes - and indexed
109
+ // `1..<outerRing.count`, which traps on an empty ring and yields
110
+ // Double.greatestFiniteMagnitude for a single-coordinate ring.
111
+ //
112
+ // Like the Android module, this returns the *squared* distance.
113
+ guard let geo = decodeQueryableGeometry(geometry) else {
114
+ return reject(
115
+ "Utils error",
116
+ "Geometry is neither a Polygon nor a MultiPolygon, so it has no edges",
117
+ MPError.unknownError
118
+ )
119
+ }
120
+
121
+ // Both overloads behave identically here; use the MPPoint one, as the Android module does.
122
+ // Note the SDK answers -1 for some geometry/point combinations even once the geometry
123
+ // decodes correctly - that is an SDK-level question, not something this module can fix. What
124
+ // matters here is that a number is resolved at all, honouring Promise<number>.
125
+ return resolve(geo.squaredDistanceToClosestEdge(it))
114
126
  }
115
127
 
116
128
  @objc public func parseMapClientUrl(_ venueId: String, locationId: String, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mapsindoors/react-native-maps-indoors-mapbox",
3
3
  "title": "React Native MapsIndoors Mapbox",
4
- "version": "2.8.0",
4
+ "version": "2.9.0",
5
5
  "description": "React Native MapsIndoors component with mapbox",
6
6
  "react-native": "index.ts",
7
7
  "files": [
@@ -33,6 +33,6 @@ Pod::Spec.new do |s|
33
33
  # embeds the resulting dynamic frameworks into the app bundle, so the app builds and links but
34
34
  # dies at launch with `Library not loaded: @rpath/MapsIndoorsCore.framework/MapsIndoorsCore`.
35
35
  # See SPEX-2429 before reintroducing SPM here.
36
- s.dependency "MapsIndoorsMapbox11", "4.19.1"
37
- s.dependency "MapsIndoorsCodable", "4.19.1"
36
+ s.dependency "MapsIndoorsMapbox11", "4.20.0"
37
+ s.dependency "MapsIndoorsCodable", "4.20.0"
38
38
  end
@@ -16,6 +16,9 @@ export interface Spec extends TurboModule {
16
16
  setRoute(routeString: string, stopIcons: string, legIndex: number): Promise<null>;
17
17
  setAnimatedPolyline(animated: boolean, repeated: boolean, duration: number): Promise<null>;
18
18
  setPolyLineColors(foregroundString: string, backgroundString: string): Promise<null>;
19
+ setOptions(optionsString: string): Promise<null>;
20
+ getOptions(): Promise<string>;
21
+ finishGuidance(usagePercentage: number): Promise<null>;
19
22
  showRouteLegButtons(value: boolean): Promise<null>;
20
23
  setDefaultRouteStopIcon(iconString: string): Promise<null>;
21
24
  }
@@ -2,6 +2,8 @@ import type {TurboModule} from 'react-native';
2
2
  import {TurboModuleRegistry} from 'react-native';
3
3
 
4
4
  export interface Spec extends TurboModule {
5
+ addListener(eventName: string): void;
6
+ removeListeners(count: number): void;
5
7
  loadMapsIndoors(apiKey: string, optionalStrings: Array<string> | null): Promise<null>;
6
8
  getDefaultVenue(): Promise<string | null>;
7
9
  getVenues(): Promise<string>;
@@ -16,7 +18,7 @@ export interface Spec extends TurboModule {
16
18
  getLocationById(id: string): Promise<string | null>;
17
19
  getLocationsByExternalIds(ids: Array<string>): Promise<string>;
18
20
  getMapStyles(): Promise<string>;
19
- getSolution(): Promise<string | null>;
21
+ getSolution(): Promise<string>;
20
22
  getLocationsAsync(query: string, filter: string): Promise<string>;
21
23
  locationDisplayRuleExists(locationId: string): Promise<boolean>;
22
24
  displayRuleNameExists(name: string): Promise<boolean>;
@@ -38,6 +40,9 @@ export interface Spec extends TurboModule {
38
40
  removeVenuesToSync(venues: Array<string>): Promise<null>;
39
41
  getSyncedVenues(): Promise<Array<string> | null>;
40
42
  cacheData(apiKey: string): Promise<boolean>;
43
+ isBaseMapCachingSupported(): Promise<boolean>;
44
+ setBaseMapTilesEnabled(enabled: boolean, apiKey: string): Promise<null>;
45
+ synchronizeBaseMapTiles(apiKeys: Array<string> | null): Promise<null>;
41
46
  }
42
47
 
43
48
  export default TurboModuleRegistry.getEnforcing<Spec>('MapsIndoorsModule');
@@ -18,4 +18,7 @@ export enum EventNames {
18
18
  onLiveLocationUpdate = "onLiveLocationUpdate",
19
19
  floorSelector = "floorSelector",
20
20
  onLegSelected = "onLegSelected",
21
+ // Canonical copy. Also spelled out in iOS's MapsIndoorsData.Event and as a literal in the
22
+ // Android bridge; drift silently delivers no progress.
23
+ onBaseMapCacheProgress = "onBaseMapCacheProgress",
21
24
  }
@@ -1,10 +1,20 @@
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
+
8
18
  /**
9
19
  * Renders a {@link MPRoute} on the map.
10
20
  *
@@ -117,6 +127,10 @@ export default class MPDirectionsRenderer {
117
127
  /**
118
128
  * Enable/Disable the polyline animation when displaying a route element on the map.
119
129
  *
130
+ * @deprecated Use {@link setOptions} with {@link MPDirectionsRendererOptionsParams.animationType},
131
+ * {@link MPDirectionsRendererOptionsParams.animationRepeating} and
132
+ * {@link MPDirectionsRendererOptionsParams.animationSpeed} instead.
133
+ *
120
134
  * @public
121
135
  * @async
122
136
  * @param {boolean} animated
@@ -133,6 +147,9 @@ export default class MPDirectionsRenderer {
133
147
  *
134
148
  * Colors are given as hex strings (e.g. "#3071D9").
135
149
  *
150
+ * @deprecated Use {@link setOptions} with {@link MPDirectionsRendererOptionsParams.animatedOverlayColor}
151
+ * (foreground) and {@link MPDirectionsRendererOptionsParams.strokeColor} (background) instead.
152
+ *
136
153
  * @public
137
154
  * @async
138
155
  * @param {string} foregroundColor the primary color (animated polyline)
@@ -143,6 +160,64 @@ export default class MPDirectionsRenderer {
143
160
  await DirectionsRenderer.setPolyLineColors(foregroundColor, backgroundColor);
144
161
  }
145
162
 
163
+ /**
164
+ * Set the styling and camera options of the rendered route.
165
+ *
166
+ * Applies immediately, restyling an already rendered route in place. Every option
167
+ * resolves on its own, in this order: the value set here, then the solution level
168
+ * default configured in the CMS, then the SDK's built-in default. Options left
169
+ * unset are therefore inherited rather than reset.
170
+ *
171
+ * @public
172
+ * @async
173
+ * @param {MPDirectionsRendererOptions} options
174
+ * @returns {Promise<void>}
175
+ */
176
+ public async setOptions(options: MPDirectionsRendererOptions): Promise<void> {
177
+ await DirectionsRenderer.setOptions(JSON.stringify(options));
178
+ }
179
+
180
+ /**
181
+ * Gets the currently effective styling and camera options of the rendered route.
182
+ *
183
+ * Each option is resolved as: the value set with {@link setOptions}, then the
184
+ * solution level default configured in the CMS, then the SDK's built-in default.
185
+ * An option reading back as undefined has no default in force for it yet.
186
+ *
187
+ * @public
188
+ * @async
189
+ * @returns {Promise<MPDirectionsRendererOptions>}
190
+ */
191
+ public async getOptions(): Promise<MPDirectionsRendererOptions> {
192
+ const options: string = await DirectionsRenderer.getOptions();
193
+ return MPDirectionsRendererOptions.create(JSON.parse(options));
194
+ }
195
+
196
+ /**
197
+ * Signals that guidance on the current route has finished, either because the user
198
+ * arrived or because they ended navigation.
199
+ *
200
+ * Has no effect when no route is set, or when guidance on the current route has
201
+ * already finished. {@link clear} finishes guidance implicitly, so there is no need
202
+ * to call both.
203
+ *
204
+ * @public
205
+ * @async
206
+ * @param {?number} [usagePercentage] How much of the route was travelled, from 0 to 100.
207
+ * Values outside that range are clamped. Omit it to let the SDK derive the figure from
208
+ * the route's own progress.
209
+ * @returns {Promise<void>}
210
+ */
211
+ public async finishGuidance(usagePercentage?: number): Promise<void> {
212
+ // A non-finite value cannot be clamped into range - NaN in particular survives Math.min/max,
213
+ // and every comparison against it is false, so it would slip past the natives' `< 0` sentinel
214
+ // check and reach the SDK as a usage figure. Treat it as "not supplied" instead.
215
+ const usage = usagePercentage != null && Number.isFinite(usagePercentage)
216
+ ? Math.max(0, Math.min(100, usagePercentage))
217
+ : NO_USAGE_PERCENTAGE;
218
+ await DirectionsRenderer.finishGuidance(usage);
219
+ }
220
+
146
221
  /**
147
222
  * Enable/Disable the route end/start label buttons from showing on the route. Default is true
148
223
  *