@mapsindoors/react-native-maps-indoors-mapbox 2.0.4 → 2.0.6

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Documentation
4
4
 
5
- Visit [our reference document site](https://app.mapsindoors.com/mapsindoors/reference/react-native/mapbox/2.0.4/index.html) to get an overview of what the MapsIndoors SDK offers.
5
+ Visit [our reference document site](https://app.mapsindoors.com/mapsindoors/reference/react-native/mapbox/2.0.6/index.html) to get an overview of what the MapsIndoors SDK offers.
6
6
 
7
7
  ## Getting started
8
8
 
@@ -93,7 +93,7 @@ dependencies {
93
93
  }
94
94
 
95
95
  implementation 'com.mapbox.maps:android:11.4.0'
96
- implementation 'com.mapspeople.mapsindoors:mapbox-v11:4.8.7'
96
+ implementation 'com.mapspeople.mapsindoors:mapbox-v11:4.8.8'
97
97
  implementation 'com.facebook.react:react-native:+' // From node_modules
98
98
  implementation 'androidx.core:core-ktx:1.3.2'
99
99
  implementation 'com.github.bumptech.glide:glide:4.16.0'
@@ -211,7 +211,7 @@ public class DirectionsRendererModule extends ReactContextBaseJavaModule impleme
211
211
  }
212
212
 
213
213
  @ReactMethod
214
- public void setRoute(String routeString, String icons, final Promise promise) {
214
+ public void setRoute(String routeString, String icons, int legIndex, final Promise promise) {
215
215
  if (mRenderer != null) {
216
216
  Context ctx = mCtx.getApplicationContext();
217
217
  MPRoute route = new Gson().fromJson(routeString, MPRoute.class);
@@ -238,7 +238,17 @@ public class DirectionsRendererModule extends ReactContextBaseJavaModule impleme
238
238
  iconConfigs.put(mapEntry.getKey(), iconConfig.toMPRouteStopIconConfig(ctx));
239
239
  }
240
240
  }
241
+
241
242
  mRenderer.setRoute(route, iconConfigs);
243
+ if (legIndex != 0) {
244
+ try {
245
+ mRenderer.selectLegIndex(legIndex);
246
+ } catch (IllegalStateException e) {
247
+ promise.reject(e.getMessage(), new Gson().toJson(MPError.fromMIError(new MIError(MIErrorEnum.ROUTING_UNKNOWN_ERROR, e.getMessage()))));
248
+ return;
249
+ }
250
+ }
251
+
242
252
  promise.resolve(null);
243
253
  });
244
254
  }else {
@@ -60,6 +60,7 @@ class MapBoxView: RCMapView {
60
60
 
61
61
  update = CameraOptions(cameraState: camera)
62
62
  update.center = point.coordinate
63
+
63
64
  case "fromBounds":
64
65
  guard let bounds = cameraUpdate.bounds else {
65
66
  throw CameraUpdateError.missingField("fromBounds", "bounds")
@@ -70,16 +71,19 @@ class MapBoxView: RCMapView {
70
71
 
71
72
  update = CameraOptions(cameraState: camera)
72
73
  update.center = camerabounds.bounds?.center
74
+
73
75
  case "zoomBy":
74
76
  let camera = mapboxView.mapboxMap.cameraState
75
77
 
76
78
  update = CameraOptions(cameraState: camera)
77
79
  update.zoom = CGFloat(cameraUpdate.zoom!)
80
+
78
81
  case "zoomTo":
79
82
  let camera = mapboxView.mapboxMap.cameraState
80
83
 
81
84
  update = CameraOptions(cameraState: camera)
82
85
  update.zoom = CGFloat(cameraUpdate.zoom!)
86
+
83
87
  case "fromCameraPosition":
84
88
  guard let position = cameraUpdate.position else {
85
89
  throw CameraUpdateError.missingField("fromCameraPosition", "position")
@@ -90,6 +94,8 @@ class MapBoxView: RCMapView {
90
94
  update.center = position.target.coordinate
91
95
  update.bearing = CLLocationDirection(position.bearing)
92
96
  update.zoom = CGFloat(position.zoom)
97
+ update.pitch = CGFloat(position.tilt)
98
+
93
99
  default:
94
100
  throw CameraUpdateError.unknownMode(cameraUpdate.mode)
95
101
  }
@@ -9,7 +9,7 @@ import MapsIndoors
9
9
 
10
10
  public struct CameraPosition: Codable {
11
11
  let zoom: Float
12
- let tilt: Float // TODO: this is called viewingAngle in MPCameraPosition(Codable)
12
+ let tilt: Float
13
13
  let bearing: Float
14
14
  let target: MPPoint
15
15
  }
@@ -46,6 +46,7 @@
46
46
 
47
47
  RCT_EXTERN_METHOD(setRoute: (NSString *) routeString
48
48
  stopIcons:(NSString *) stopIcons
49
+ legIndex: (nonnull NSNumber *) legIndex
49
50
  resolver:(RCTPromiseResolveBlock) resolve
50
51
  rejecter:(RCTPromiseRejectBlock) reject)
51
52
 
@@ -285,7 +285,7 @@ public class DirectionsRendererModule: RCTEventEmitter {
285
285
  return resolve(nil)
286
286
  }
287
287
 
288
- @objc public func setRoute(_ routeString: String, stopIcons: String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
288
+ @objc public func setRoute(_ routeString: String, stopIcons: String, legIndex: NSNumber, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
289
289
  if (MapsIndoorsData.sharedInstance.directionsRenderer == nil) {
290
290
  MapsIndoorsData.sharedInstance.directionsRenderer = MapsIndoorsData.sharedInstance.mapView?.getMapControl()?.newDirectionsRenderer()
291
291
  }
@@ -303,6 +303,14 @@ public class DirectionsRendererModule: RCTEventEmitter {
303
303
  return doReject(reject, message: "Route could not be parsed")
304
304
  }
305
305
 
306
+ guard legIndex.intValue >= 0 else {
307
+ return doReject(reject, message: "Tried to select negative route leg index \(legIndex.intValue)")
308
+ }
309
+
310
+ guard legIndex.intValue < (route.legs.count) else {
311
+ return doReject(reject, message: "Tried to select route leg index \(legIndex.intValue) outside of range 0..\((route.legs.count)-1)")
312
+ }
313
+
306
314
  Task {
307
315
  var stopIconss: [Int: String]? = nil
308
316
  stopIconss = try? JSONDecoder().decode([Int: String].self, from: Data(stopIcons.utf8))
@@ -326,7 +334,7 @@ public class DirectionsRendererModule: RCTEventEmitter {
326
334
 
327
335
  DispatchQueue.main.sync {
328
336
  directionsRenderer.route = route
329
- directionsRenderer.routeLegIndex = 0
337
+ directionsRenderer.routeLegIndex = legIndex.intValue
330
338
  directionsRenderer.render(stopIcons: icons)
331
339
  }
332
340
 
@@ -94,7 +94,7 @@ public class DirectionsServiceModule: NSObject {
94
94
  query.stopsPoints = stops
95
95
 
96
96
  if(!directionsVars.excludeWayTypes.isEmpty) {
97
- query.avoidWayTypes = directionsVars.excludeWayTypes
97
+ query.excludeWayTypes = directionsVars.excludeWayTypes
98
98
  }
99
99
 
100
100
  if (directionsVars.date != nil) {
@@ -20,7 +20,6 @@ private func doReject(_ reject: RCTPromiseRejectBlock, displayRuleId: String,
20
20
 
21
21
  @objc(DisplayRule)
22
22
  public class MPDisplayRuleModule: NSObject {
23
- private var refreshTimerWorkItem: DispatchWorkItem?
24
23
 
25
24
  @objc static func requiresMainQueueSetup() -> Bool { return false }
26
25
 
@@ -89,31 +88,16 @@ public class MPDisplayRuleModule: NSObject {
89
88
 
90
89
  private func getRule(name: String) -> MPDisplayRule? {
91
90
  if let typeRule = getTypeRule(typeName: name) {
92
- setRefreshTimer()
93
91
  return MPMapsIndoors.shared.displayRuleFor(displayRuleType: typeRule)
94
92
  } else if let namedRule = MPMapsIndoors.shared.displayRuleFor(type: name.lowercased()){
95
- setRefreshTimer()
96
93
  return namedRule
97
94
  } else if let loc = MPMapsIndoors.shared.locationWith(locationId: name) {
98
- setRefreshTimer()
99
95
  return MPMapsIndoors.shared.displayRuleFor(location: loc)!
100
96
  } else {
101
97
  return nil
102
98
  }
103
99
  }
104
100
 
105
- func setRefreshTimer() {
106
- refreshTimerWorkItem?.cancel()
107
-
108
- refreshTimerWorkItem = DispatchWorkItem {
109
- MapsIndoorsData.sharedInstance.mapView?.getMapControl()?.refresh()
110
- }
111
-
112
- if let refreshTimerWorkItem {
113
- DispatchQueue.global().asyncAfter(deadline: .now() + 0.5, execute: refreshTimerWorkItem)
114
- }
115
- }
116
-
117
101
  func hexStringFromColor(color: UIColor) -> String {
118
102
  // TODO: copy paste from Flutter
119
103
  let components = color.cgColor.components
@@ -41,9 +41,9 @@ public class MapControlModule: RCTEventEmitter {
41
41
  return doReject(reject, message: "Mapview not available")
42
42
  }
43
43
 
44
+ MapsIndoorsData.sharedInstance.directionsRenderer?.clear()
45
+ MapsIndoorsData.sharedInstance.directionsRenderer = nil
44
46
  if mapView.getMapControl() != nil {
45
- MapsIndoorsData.sharedInstance.directionsRenderer?.clear()
46
- MapsIndoorsData.sharedInstance.directionsRenderer = nil
47
47
  return resolve(nil)
48
48
  }
49
49
 
@@ -551,7 +551,8 @@ public class MapControlModule: RCTEventEmitter {
551
551
  }
552
552
 
553
553
  do {
554
- floorSelector.onFloorSelectionChanged(newFloor: try fromJSON(newFloorJson))
554
+ let floor: MPFloorCodable = try fromJSON(newFloorJson)
555
+ floorSelector.onFloorSelectionChanged(newFloor: floor.floorIndex ?? 0)
555
556
  return resolve(nil)
556
557
  } catch let e {
557
558
  return doReject(reject, error: e)
@@ -69,6 +69,13 @@ class MapControlDelegate: MPMapControlDelegate, LiveDataDelegate, MPFloorSelecto
69
69
  }
70
70
 
71
71
  // MPMapControlDelegate:
72
+
73
+ func didChangeCameraPosition() -> Bool {
74
+ if (respondToCameraEvents) {
75
+ sendEvent(event: .cameraEvent, body: ["event": 5])
76
+ }
77
+ return true;
78
+ }
72
79
 
73
80
  func cameraIdle() -> Bool {
74
81
  if (respondToCameraEvents) {
@@ -104,6 +111,8 @@ class MapControlDelegate: MPMapControlDelegate, LiveDataDelegate, MPFloorSelecto
104
111
  if (respondToDidChangeFloorIndex) {
105
112
  sendEvent(event: .onFloorUpdate, body: ["floorIndex": floorIndex])
106
113
  }
114
+
115
+ MapsIndoorsData.sharedInstance.floorSelector?.onFloorSelectionChanged(newFloor: NSNumber(value: floorIndex))
107
116
  return false
108
117
  }
109
118
 
@@ -118,6 +127,7 @@ class MapControlDelegate: MPMapControlDelegate, LiveDataDelegate, MPFloorSelecto
118
127
  if (respondToDidChangeBuilding) {
119
128
  sendEvent(event: .onBuildingFoundAtCameraTarget, body: ["building": selectedBuilding.map{ toJSON(MPBuildingCodable(withBuilding:($0))) }])
120
129
  }
130
+ MapsIndoorsData.sharedInstance.floorSelector?.building = selectedBuilding
121
131
  return false
122
132
  }
123
133
 
@@ -150,10 +160,11 @@ class MapControlDelegate: MPMapControlDelegate, LiveDataDelegate, MPFloorSelecto
150
160
 
151
161
  func onFloorIndexChanged(_ floorIndex: NSNumber) {
152
162
  sendEvent(event: .onFloorUpdate, body: ["floorIndex": floorIndex])
163
+ MapsIndoorsData.sharedInstance.floorSelector?.onFloorSelectionChanged(newFloor: floorIndex)
153
164
  }
154
165
 
155
166
  func floorSelector(method: FloorSelector.Event, args: [String: Any]) {
156
- let body = try! ["method": method].merging(args, uniquingKeysWith: { _,_ in throw MPError.unknownError })
167
+ let body = try! ["method": method.rawValue].merging(args, uniquingKeysWith: { _,_ in throw MPError.unknownError })
157
168
 
158
169
  sendEvent(event: .floorSelector, body: body)
159
170
  }
@@ -168,13 +179,21 @@ class FloorSelector: UIView, MPCustomFloorSelector {
168
179
  case setUserPositionFloor
169
180
  // TODO: the rest are not implemented since they are not available from the MPCustomFloorSelector protocol, and are not implemented in flutter
170
181
  // case setSelectedFloor
171
- // case setSelectedFloorByFloorIndex
182
+ case setSelectedFloorByFloorIndex
172
183
  // case zoomLevelChanged
173
184
  }
185
+
186
+ lazy var allEvents: [String] = {
187
+ var allEventNames: [String] = Event.allCases.map{$0.rawValue}
188
+ return allEventNames
189
+ }()
174
190
 
175
191
  var building: MapsIndoors.MPBuilding?
192
+ var latestBuilding: MapsIndoors.MPBuilding?
176
193
  var delegate: MapsIndoors.MPFloorSelectorDelegate?
177
194
 
195
+ var hide: Bool = false
196
+
178
197
  var floorIndex: NSNumber?
179
198
 
180
199
  var autoFloorChange = true
@@ -193,22 +212,35 @@ class FloorSelector: UIView, MPCustomFloorSelector {
193
212
  super.init(frame: CGRect())
194
213
  }
195
214
 
196
- func onFloorSelectionChanged(newFloor: MPFloorCodable) {
197
- let floorIndex = newFloor.floorIndex?.intValue ?? 0
198
- MapsIndoorsData.sharedInstance.mapView?.getMapControl()?.select(floorIndex: floorIndex)
215
+ func onFloorSelectionChanged(newFloor: NSNumber) {
216
+ let floorIndex = newFloor.intValue
217
+ listenerDelegate.floorSelector(method: .setSelectedFloorByFloorIndex, args: ["floorIndex": newFloor])
199
218
  }
200
219
 
201
220
  func onShow() {
221
+ if (!hide && building === latestBuilding) {
222
+ return
223
+ }
202
224
  if let building {
203
225
  listenerDelegate.floorSelector(method: .setList, args: [
204
- "list": toJSON(building.floors?.values.map{MPFloorCodable(withFloor: $0)})
226
+ "list": toJSON(building.floors?.values.sorted(by: { (floor1, floor2) -> Bool in
227
+ return floor1.floorIndex!.intValue < floor2.floorIndex!.intValue
228
+ }).map{MPFloorCodable(withFloor: $0)})
205
229
  ])
206
230
  }
207
231
 
208
232
  listenerDelegate.floorSelector(method: .show, args: ["show": true, "animated": true])
233
+ latestBuilding = building
234
+ hide = false
209
235
  }
236
+
210
237
  func onHide() {
238
+ if (hide) {
239
+ return
240
+ }
211
241
  listenerDelegate.floorSelector(method: .show, args: ["show": false, "animated": true])
242
+ latestBuilding = nil
243
+ hide = true
212
244
  }
213
245
 
214
246
  func onUserPositionFloorChange(floorIndex: Int) {
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.0.4",
4
+ "version": "2.0.6",
5
5
  "description": "React Native MapsIndoors component with mapbox",
6
6
  "react-native": "index.ts",
7
7
  "files": [
@@ -24,7 +24,7 @@ Pod::Spec.new do |s|
24
24
  s.requires_arc = true
25
25
 
26
26
  s.dependency "React"
27
- s.dependency "MapsIndoorsMapbox11", "4.5.11"
28
- s.dependency "MapsIndoorsCodable", "4.5.11"
27
+ s.dependency "MapsIndoorsMapbox11", "4.5.13"
28
+ s.dependency "MapsIndoorsCodable", "4.5.13"
29
29
  end
30
30
 
@@ -88,16 +88,17 @@ export default class MPDirectionsRenderer {
88
88
  * @async
89
89
  * @param {?MPRoute} [route]
90
90
  * @param {RouteStopIconConfig[]} [stopIcons]
91
+ * @param {?number} [legIndex] Overwrites the starting leg index, when rendering the route
91
92
  * @returns {Promise<void>}
92
93
  */
93
- public async setRoute(route: MPRoute, stopIcons: Map<number, RouteStopIconConfig> = null): Promise<void> {
94
+ public async setRoute(route: MPRoute, stopIcons: Map<number, RouteStopIconConfig> = null, legIndex: number = 0): Promise<void> {
94
95
  var iconsAsString = new Map<number, string>();
95
96
  if (stopIcons !== null) {
96
97
  stopIcons.forEach((icon, index) => {
97
98
  iconsAsString.set(index, icon.getImage().toString());
98
99
  });
99
100
  }
100
- await DirectionsRenderer.setRoute(JSON.stringify(route), JSON.stringify(Object.fromEntries(iconsAsString.entries())));
101
+ await DirectionsRenderer.setRoute(JSON.stringify(route), JSON.stringify(Object.fromEntries(iconsAsString.entries())), legIndex);
101
102
  }
102
103
 
103
104
  /**
@@ -90,7 +90,7 @@ export default class MPPropertyData extends MPEntityInfo {
90
90
  object?.activeFrom,
91
91
  object?.activeTo,
92
92
  object?.contact,
93
- object?.imageUrl,
93
+ object?.imageURL,
94
94
  object?.locationType,
95
95
  object?.bookable,
96
96
  MPPoint.create(object?.anchor),
@@ -196,7 +196,7 @@ export interface MPPropertyDataParams {
196
196
  *
197
197
  * @type {?string}
198
198
  */
199
- imageUrl?: string,
199
+ imageURL?: string,
200
200
  /**
201
201
  * Internal - Documentation will follow.
202
202
  *