@mapsindoors/react-native-maps-indoors-mapbox 2.4.0 → 2.4.2

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.4.0/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.4.2/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.7.0'
96
- implementation 'com.mapspeople.mapsindoors:mapbox-v11:4.11.0'
96
+ implementation 'com.mapspeople.mapsindoors:mapbox-v11:4.11.3'
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'
@@ -69,6 +69,39 @@ public class MapsIndoorsViewManager extends ViewGroupManager<MapView> {
69
69
  return MapBuilder.of("create", COMMAND_CREATE);
70
70
  }
71
71
 
72
+ @Override
73
+ public void receiveCommand(@NonNull MapView root, int commandId, @Nullable ReadableArray args) {
74
+ super.receiveCommand(root, commandId, args);
75
+ if (commandId == COMMAND_CREATE) {
76
+ int reactNativeViewId = args.getInt(0);
77
+
78
+ createMapFragment(root, reactNativeViewId);
79
+
80
+ if (!args.isNull(1)) {
81
+ MPCameraPosition cameraPosition = gson.fromJson(args.getString(1), MPCameraPosition.class);
82
+ CameraState cameraState = view.getMapboxMap().getCameraState();
83
+ view.getMapboxMap().setCamera(new CameraOptions.Builder()
84
+ .center(Point.fromLngLat(cameraPosition.target.getLng(), cameraPosition.target.getLat()))
85
+ .zoom(cameraPosition.zoom != null ? Double.valueOf(cameraPosition.zoom) : cameraState.getZoom())
86
+ .pitch(cameraPosition.tilt != null ? Double.valueOf(cameraPosition.tilt) : cameraState.getPitch())
87
+ .bearing(cameraPosition.bearing != null ? Double.valueOf(cameraPosition.bearing) : cameraState.getBearing())
88
+ .build());
89
+ }
90
+
91
+ if (!args.isNull(2)) {
92
+ if (args.getBoolean(2)) {
93
+ CompassUtils.getCompass(view).setEnabled(true);
94
+ }else {
95
+ CompassUtils.getCompass(view).setEnabled(false);
96
+ }
97
+ }
98
+
99
+ if (!args.isNull(3)) {
100
+ view.getMapboxMap().loadStyle(args.getString(3));
101
+ }
102
+ }
103
+ }
104
+
72
105
  @Override
73
106
  public void receiveCommand(@NonNull MapView root, String commandId, @Nullable ReadableArray args) {
74
107
  super.receiveCommand(root, commandId, args);
@@ -39,11 +39,6 @@
39
39
  RCT_EXTERN_METHOD(setOnLegSelectedListener: (RCTPromiseResolveBlock) resolve
40
40
  rejecter:(RCTPromiseRejectBlock) reject)
41
41
 
42
- RCT_EXTERN_METHOD(setPolyLineColors: (NSString *) foregroundString
43
- backgroundString:(NSString *): backgroundString
44
- resolver:(RCTPromiseResolveBlock) resolve
45
- rejecter:(RCTPromiseRejectBlock) reject)
46
-
47
42
  RCT_EXTERN_METHOD(setRoute: (NSString *) routeString
48
43
  stopIcons:(NSString *) stopIcons
49
44
  legIndex: (nonnull NSNumber *) legIndex
@@ -13,7 +13,7 @@ import MapsIndoorsCodable
13
13
  public class DirectionsServiceModule: NSObject {
14
14
 
15
15
  var directionsVariables = [String: DirectionsVariables]()
16
-
16
+
17
17
  @objc static func requiresMainQueueSetup() -> Bool { return false }
18
18
 
19
19
  @objc func create(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
@@ -1,8 +1,9 @@
1
1
  #import <React/RCTBridgeModule.h>
2
2
 
3
3
  @interface RCT_EXTERN_MODULE(DisplayRule, NSObject)
4
- RCT_EXTERN_METHOD(requiresMainQueueSetup)
5
4
  // End of head
5
+
6
+ RCT_EXTERN_METHOD(requiresMainQueueSetup)
6
7
 
7
8
  // GetterBridge isVisible->visible
8
9
  RCT_EXTERN_METHOD(isVisible: (NSString *) displayRuleId
@@ -165,7 +166,7 @@ RCT_EXTERN_METHOD(requiresMainQueueSetup)
165
166
 
166
167
  // SetterBridge setLabelMaxWidth->labelMaxWidth
167
168
  RCT_EXTERN_METHOD(setLabelMaxWidth: (NSString *) displayRuleId
168
- value:(NSInteger) value
169
+ value:(NSUInteger) value
169
170
  resolver:(RCTPromiseResolveBlock) resolve
170
171
  rejecter:(RCTPromiseRejectBlock) reject)
171
172
 
@@ -21,7 +21,7 @@ private func doReject(_ reject: RCTPromiseRejectBlock, displayRuleId: String,
21
21
  @objc(DisplayRule)
22
22
  public class MPDisplayRuleModule: NSObject {
23
23
 
24
- @objc static func requiresMainQueueSetup() -> Bool { return false }
24
+ @objc public static func requiresMainQueueSetup() -> Bool {return false}
25
25
 
26
26
  private func getIconPlacement(iconPlacement: NSNumber) -> MPIconPlacement {
27
27
  switch(iconPlacement.intValue) {
@@ -505,7 +505,12 @@ public class MPDisplayRuleModule: NSObject {
505
505
  return doReject(reject, displayRuleId: displayRuleId)
506
506
  }
507
507
 
508
- return resolve(displayRule.labelMaxWidth)
508
+ let maxWidth = displayRule.labelMaxWidth
509
+ if maxWidth == UInt.max {
510
+ return resolve(-1)
511
+ }else {
512
+ return resolve(displayRule.labelMaxWidth)
513
+ }
509
514
  }
510
515
 
511
516
  // Setter setLabelMaxWidth->labelMaxWidth
@@ -2,6 +2,7 @@
2
2
  #import <React/RCTEventEmitter.h>
3
3
 
4
4
  @interface RCT_EXTERN_MODULE(MapControlModule, RCTEventEmitter)
5
+
5
6
  RCT_EXTERN_METHOD(requiresMainQueueSetup)
6
7
 
7
8
  RCT_EXTERN_METHOD(supportedEvents)
@@ -7,7 +7,8 @@ import React
7
7
 
8
8
  @objc(MapControlModule)
9
9
  public class MapControlModule: RCTEventEmitter {
10
- @objc override public static func requiresMainQueueSetup() -> Bool {return false}
10
+
11
+ @objc public override static func requiresMainQueueSetup() -> Bool { return false }
11
12
 
12
13
  enum HexParsingError: Error {
13
14
  case invalidHexString(String)
@@ -170,8 +171,7 @@ public class MapControlModule: RCTEventEmitter {
170
171
  case "MPVenue":
171
172
  entity = try fromJSON(entityJSON, type: MPVenueCodable.self)
172
173
  case "MPFloor":
173
- // TODO: Not implemented, currently MPFloor is not an MPEntity
174
- return doReject(reject, message: "goTo: Not currently implemented for \(entityType) on iOS")
174
+ entity = try fromJSON(entityJSON, type: MPFloorCodable.self)
175
175
  default:
176
176
  return doReject(reject, message: "goTo: Unknown entity type \(entityType)")
177
177
  }
@@ -395,10 +395,12 @@ public class MapControlModule: RCTEventEmitter {
395
395
  }
396
396
 
397
397
  @objc public func hideFloorSelector(_ hide: Bool,
398
- resolver resolve: RCTPromiseResolveBlock,
398
+ resolver resolve: @escaping RCTPromiseResolveBlock,
399
399
  rejecter reject: RCTPromiseRejectBlock) {
400
- MapsIndoorsData.sharedInstance.mapView?.getMapControl()?.hideFloorSelector = hide
401
- return resolve(nil)
400
+ DispatchQueue.main.async {
401
+ MapsIndoorsData.sharedInstance.mapView?.getMapControl()?.hideFloorSelector = hide
402
+ return resolve(nil)
403
+ }
402
404
  }
403
405
 
404
406
  @objc public func animateCamera(_ updateJSON: String,
@@ -1,11 +1,8 @@
1
1
  #import <React/RCTBridgeModule.h>
2
2
 
3
3
  @interface RCT_EXTERN_MODULE(MapsIndoorsModule, NSObject)
4
- RCT_EXTERN_METHOD(requiresMainQueueSetup)
5
4
 
6
- RCT_EXTERN_METHOD(addEvent:(NSString *)name
7
- location:(NSString *)location
8
- date:(nonnull NSNumber *)date)
5
+ RCT_EXTERN_METHOD(requiresMainQueueSetup)
9
6
 
10
7
  RCT_EXTERN_METHOD(loadMapsIndoors:(NSString *)apiKey
11
8
  optionalStrings:(NSArray<NSString *> _Nullable)optionalStrings
@@ -62,6 +62,8 @@ class MapControlDelegate: MPMapControlDelegate, LiveDataDelegate, MPFloorSelecto
62
62
  var respondToDidTapInfoWindow: Bool = false
63
63
 
64
64
  var respondToCameraEvents: Bool = false
65
+
66
+ var zoom: Float = 0.0
65
67
 
66
68
  init(eventEmitter: RCTEventEmitter) {
67
69
  self.eventEmitter = eventEmitter
@@ -72,12 +74,26 @@ class MapControlDelegate: MPMapControlDelegate, LiveDataDelegate, MPFloorSelecto
72
74
  eventEmitter.sendEvent(withName: event.rawValue, body: body)
73
75
  }
74
76
 
77
+ func isCloseToWholeNumber(_ number: Float, tolerance: Float = 0.02) -> Bool {
78
+ let rounded = round(number)
79
+ return abs(number - rounded) < tolerance
80
+ }
81
+
75
82
  // MPMapControlDelegate:
76
83
 
77
84
  func didChangeCameraPosition() -> Bool {
78
85
  if (respondToCameraEvents) {
79
86
  sendEvent(event: .cameraEvent, body: ["event": 5])
80
87
  }
88
+
89
+ if let mapControl = MapsIndoorsData.sharedInstance.mapView?.getMapControl() {
90
+ let z = mapControl.mapsIndoorsZoom
91
+ if z != zoom && (z.isLess(than: zoom-0.02) || zoom.isLess(than: z-0.02) || self.isCloseToWholeNumber(z, tolerance: 0.02)) {
92
+ zoom = z
93
+ MapsIndoorsData.sharedInstance.floorSelector?.onZoomChanged(zoom: zoom)
94
+ }
95
+ }
96
+
81
97
  return false;
82
98
  }
83
99
 
@@ -184,7 +200,7 @@ class FloorSelector: UIView, MPCustomFloorSelector {
184
200
  // TODO: the rest are not implemented since they are not available from the MPCustomFloorSelector protocol, and are not implemented in flutter
185
201
  // case setSelectedFloor
186
202
  case setSelectedFloorByFloorIndex
187
- // case zoomLevelChanged
203
+ case zoomLevelChanged
188
204
  }
189
205
 
190
206
  lazy var allEvents: [String] = {
@@ -192,7 +208,11 @@ class FloorSelector: UIView, MPCustomFloorSelector {
192
208
  return allEventNames
193
209
  }()
194
210
 
195
- var building: MapsIndoors.MPBuilding?
211
+ var building: MapsIndoors.MPBuilding? {
212
+ didSet {
213
+ if (oldValue?.buildingId != building?.buildingId) { onShow() }
214
+ }
215
+ }
196
216
  var latestBuilding: MapsIndoors.MPBuilding?
197
217
  var delegate: MapsIndoors.MPFloorSelectorDelegate?
198
218
 
@@ -204,51 +224,65 @@ class FloorSelector: UIView, MPCustomFloorSelector {
204
224
  var listenerDelegate: MapControlDelegate
205
225
 
206
226
  init(delegate: MPFloorSelectorDelegate) {
207
- listenerDelegate = MapsIndoorsData.sharedInstance.mapControlListenerDelegate!
227
+ self.listenerDelegate = MapsIndoorsData.sharedInstance.mapControlListenerDelegate!
208
228
 
209
229
  super.init(frame: CGRect())
210
230
  self.delegate = delegate
211
231
  }
212
232
 
213
233
  required init?(coder: NSCoder) {
214
- listenerDelegate = MapsIndoorsData.sharedInstance.mapControlListenerDelegate!
234
+ self.listenerDelegate = MapsIndoorsData.sharedInstance.mapControlListenerDelegate!
215
235
 
216
236
  super.init(frame: CGRect())
217
237
  }
218
238
 
219
239
  func onFloorSelectionChanged(newFloor: NSNumber) {
220
- let floorIndex = newFloor.intValue
221
- listenerDelegate.floorSelector(method: .setSelectedFloorByFloorIndex, args: ["floorIndex": newFloor])
240
+ DispatchQueue.main.async {
241
+ let floorIndex = newFloor.intValue
242
+ self.listenerDelegate.floorSelector(method: .setSelectedFloorByFloorIndex, args: ["floorIndex": newFloor])
243
+ }
222
244
  }
223
245
 
224
246
  func onShow() {
225
- if (!hide && building === latestBuilding) {
226
- return
227
- }
228
- if let building {
229
- listenerDelegate.floorSelector(method: .setList, args: [
230
- "list": toJSON(building.floors?.values.sorted(by: { (floor1, floor2) -> Bool in
231
- return floor1.floorIndex!.intValue < floor2.floorIndex!.intValue
232
- }).map{MPFloorCodable(withFloor: $0)})
233
- ])
247
+ DispatchQueue.main.async {
248
+ if (!self.hide && self.building == nil && self.building === self.latestBuilding) {
249
+ return
250
+ }
251
+ if let building = self.building {
252
+ self.listenerDelegate.floorSelector(method: .setList, args: [
253
+ "list": toJSON(building.floors?.values.sorted(by: { (floor1, floor2) -> Bool in
254
+ return floor1.floorIndex!.intValue < floor2.floorIndex!.intValue
255
+ }).map{MPFloorCodable(withFloor: $0)})
256
+ ])
257
+ }
258
+
259
+ self.listenerDelegate.floorSelector(method: .show, args: ["show": true, "animated": true])
260
+ self.latestBuilding = self.building
261
+ self.hide = false
234
262
  }
235
-
236
- listenerDelegate.floorSelector(method: .show, args: ["show": true, "animated": true])
237
- latestBuilding = building
238
- hide = false
239
263
  }
240
264
 
241
265
  func onHide() {
242
- if (hide) {
243
- return
266
+ DispatchQueue.main.async {
267
+ if (self.hide) {
268
+ return
269
+ }
270
+ self.listenerDelegate.floorSelector(method: .show, args: ["show": false, "animated": true])
271
+ self.latestBuilding = nil
272
+ self.hide = true
244
273
  }
245
- listenerDelegate.floorSelector(method: .show, args: ["show": false, "animated": true])
246
- latestBuilding = nil
247
- hide = true
248
274
  }
249
275
 
250
276
  func onUserPositionFloorChange(floorIndex: Int) {
251
- listenerDelegate.floorSelector(method: .setUserPositionFloor, args: ["floor": floorIndex])
277
+ DispatchQueue.main.async {
278
+ self.listenerDelegate.floorSelector(method: .setUserPositionFloor, args: ["floor": floorIndex])
279
+ }
280
+ }
281
+
282
+ func onZoomChanged(zoom: Float) {
283
+ DispatchQueue.main.async {
284
+ self.listenerDelegate.floorSelector(method: .zoomLevelChanged, args: ["zoom": Double(zoom)])
285
+ }
252
286
  }
253
287
 
254
288
  }
@@ -7,7 +7,8 @@ import React
7
7
 
8
8
  @objc(MapsIndoorsModule)
9
9
  public class MapsIndoorsModule: NSObject {
10
- @objc static func requiresMainQueueSetup() -> Bool { return false }
10
+
11
+ @objc public static func requiresMainQueueSetup() -> Bool {return false}
11
12
 
12
13
  @objc public func test() {
13
14
  print("%@.test()", String(describing: self));
@@ -14,12 +14,14 @@ public class ReactPositionProvider: MPPositionProvider {
14
14
  }
15
15
 
16
16
  public func setLatestPosition(positionResult: MPPositionResult) {
17
- if (latestPosition?.floorIndex != positionResult.floorIndex) {
18
- let floorSelector = mapsIndoorsData.floorSelector
19
- floorSelector?.onUserPositionFloorChange(floorIndex: positionResult.floorIndex)
20
- }
17
+ DispatchQueue.main.async {
18
+ if (self.latestPosition?.floorIndex != positionResult.floorIndex) {
19
+ let floorSelector = self.mapsIndoorsData.floorSelector
20
+ floorSelector?.onUserPositionFloorChange(floorIndex: positionResult.floorIndex)
21
+ }
21
22
 
22
- delegate?.onPositionUpdate(position: positionResult)
23
- latestPosition = positionResult
23
+ self.delegate?.onPositionUpdate(position: positionResult)
24
+ self.latestPosition = positionResult
25
+ }
24
26
  }
25
27
  }
@@ -8,7 +8,6 @@
8
8
  #import <React/RCTBridgeModule.h>
9
9
 
10
10
  @interface RCT_EXTERN_MODULE(UtilsModule, NSObject)
11
-
12
11
  RCT_EXTERN_METHOD(requiresMainQueueSetup)
13
12
 
14
13
  RCT_EXTERN_METHOD(venueHasGraph: (NSString *) venueId
@@ -11,8 +11,9 @@ import MapsIndoorsCore
11
11
 
12
12
  @objc(UtilsModule)
13
13
  public class UtilsModule: NSObject {
14
- @objc static func requiresMainQueueSetup() -> Bool { return false }
15
-
14
+
15
+ @objc public static func requiresMainQueueSetup() -> Bool {return false}
16
+
16
17
  @objc public func venueHasGraph(_ venueId: String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
17
18
  Task {
18
19
  guard let venue = await MPMapsIndoors.shared.venueWith(id: venueId) else {
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.4.0",
4
+ "version": "2.4.2",
5
5
  "description": "React Native MapsIndoors component with mapbox",
6
6
  "react-native": "index.ts",
7
7
  "files": [
@@ -24,6 +24,6 @@ Pod::Spec.new do |s|
24
24
  s.requires_arc = true
25
25
 
26
26
  s.dependency "React"
27
- s.dependency "MapsIndoorsMapbox11", "4.9.3"
28
- s.dependency "MapsIndoorsCodable", "4.9.3"
27
+ s.dependency "MapsIndoorsMapbox11", "4.9.7"
28
+ s.dependency "MapsIndoorsCodable", "4.9.7"
29
29
  end
@@ -61,7 +61,7 @@ export default class MPFloor extends MPEntity {
61
61
  public static create(object: MPFloorParams): MPFloor {
62
62
  var multiPolygon;
63
63
  if (Platform.OS === 'ios') {
64
- multiPolygon = MPMultiPolygon.create({coordinates: object?.geometry, bbox: [].concat(object?.entityBounds?.southwest, object?.entityBounds?.northeast)});
64
+ multiPolygon = MPMultiPolygon.create({coordinates: object?.geometry?.coordinates, bbox: [].concat(object?.entityBounds?.southwest, object?.entityBounds?.northeast)});
65
65
  }else {
66
66
  multiPolygon = MPMultiPolygon.create(object?.geometry);
67
67
  }
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react'
2
2
  import { useEffect, useRef } from 'react';
3
- import { Platform, UIManager, findNodeHandle, requireNativeComponent } from "react-native";
3
+ import { Platform, UIManager, ViewProps, findNodeHandle, requireNativeComponent } from "react-native";
4
4
  import MPCameraPosition from './MPCameraPosition';
5
5
 
6
6
  const createFragment = (viewId: number | null, camera?: MPCameraPosition, showCompass?: boolean, mapboxMapStyle?: String) => {
@@ -16,7 +16,7 @@ const createFragment = (viewId: number | null, camera?: MPCameraPosition, showCo
16
16
  );
17
17
  }
18
18
 
19
- const MapView = ({ style, camera, showCompass, mapboxMapStyle }: { style: any, camera?: MPCameraPosition, showCompass?: boolean, mapboxMapStyle?: string}) => {
19
+ const MapView = ({ style, camera, showCompass, mapboxMapStyle }: { style: any, camera?: MPCameraPosition, showCompass?: boolean, mapboxMapStyle?: string, [key: string]: any }) => {
20
20
  const ref = useRef(null);
21
21
 
22
22
  useEffect(() => {
@@ -25,11 +25,8 @@ const MapView = ({ style, camera, showCompass, mapboxMapStyle }: { style: any, c
25
25
  }, []);
26
26
 
27
27
  return (<MapsIndoorsViewManager
28
- style={style}
29
- ref={ref}
30
- camera={camera}
31
- showCompass={showCompass}
32
- mapboxMapStyle={mapboxMapStyle} />);
28
+ {...{ style, camera, showCompass, mapboxMapStyle }}
29
+ ref={ref}/>);
33
30
  }
34
31
 
35
32
  const MapsIndoorsViewManager = requireNativeComponent('MapsIndoorsView');