@mapsindoors/react-native-maps-indoors-mapbox 2.1.1 → 2.2.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.
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.1.1/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.2.0/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.8.11'
96
+ implementation 'com.mapspeople.mapsindoors:mapbox-v11:4.9.0'
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'
@@ -11,6 +11,9 @@ import com.mapbox.maps.CameraState;
11
11
  import com.mapbox.maps.CoordinateBounds;
12
12
  import com.mapbox.maps.EdgeInsets;
13
13
  import com.mapbox.maps.MapView;
14
+ import com.mapbox.maps.plugin.animation.CameraAnimationsPlugin;
15
+ import com.mapbox.maps.plugin.animation.CameraAnimationsUtils;
16
+ import com.mapbox.maps.plugin.animation.MapAnimationOptions;
14
17
  import com.mapsindoors.core.MPIMapConfig;
15
18
  import com.mapsindoors.core.MPPoint;
16
19
  import com.mapsindoors.core.OnResultReadyListener;
@@ -34,7 +37,8 @@ public class MapboxMapView implements RCMapView {
34
37
  @Override
35
38
  public void animateCamera(MPCameraUpdate cameraUpdate, Integer duration, OnResultReadyListener onFinished) {
36
39
  CameraOptions cameraOptions = toCameraOptions(cameraUpdate);
37
- mMapView.getMapboxMap().setCamera(cameraOptions);
40
+ CameraAnimationsPlugin plugin = CameraAnimationsUtils.getCamera(mMapView);
41
+ plugin.easeTo(cameraOptions, new MapAnimationOptions.Builder().duration(duration).build(), null);
38
42
  onFinished.onResultReady(null);
39
43
  }
40
44
 
@@ -1,7 +1,5 @@
1
1
  package com.mapsindoorsrn.core;
2
2
 
3
- import android.util.Log;
4
-
5
3
  import androidx.annotation.NonNull;
6
4
 
7
5
  import com.facebook.react.bridge.Promise;
@@ -12,6 +10,7 @@ import com.google.gson.Gson;
12
10
  import com.mapsindoors.core.MPBadgePosition;
13
11
  import com.mapsindoors.core.MPDisplayRule;
14
12
  import com.mapsindoors.core.MPIconPlacement;
13
+ import com.mapsindoors.core.MPLabelPosition;
15
14
  import com.mapsindoors.core.MPIconSize;
16
15
  import com.mapsindoors.core.MPLabelGraphic;
17
16
  import com.mapsindoors.core.MPLabelType;
@@ -1164,13 +1163,55 @@ public class MPDisplayRuleModule extends ReactContextBaseJavaModule {
1164
1163
  }
1165
1164
  }
1166
1165
 
1166
+ @ReactMethod
1167
+ public void getLabelStylePosition(String displayRuleId, final Promise promise) {
1168
+ MPDisplayRule displayRule = getRule(displayRuleId);
1169
+ if (displayRule != null) {
1170
+ promise.resolve(displayRule.getLabelStylePosition() != null ? displayRule.getLabelStylePosition().ordinal() : null);
1171
+ } else {
1172
+ reject(promise, displayRuleId);
1173
+ }
1174
+ }
1175
+
1176
+ @ReactMethod
1177
+ public void setLabelStylePosition(String displayRuleId, Integer position, final Promise promise) {
1178
+ MPDisplayRule displayRule = getRule(displayRuleId);
1179
+ if (displayRule != null) {
1180
+ if (position == -1) {
1181
+ displayRule.setLabelStylePosition(null);
1182
+ }else {
1183
+ MPLabelPosition labelPosition;
1184
+ switch (position) {
1185
+ case 0:
1186
+ labelPosition = MPLabelPosition.TOP;
1187
+ break;
1188
+ case 1:
1189
+ labelPosition = MPLabelPosition.BOTTOM;
1190
+ break;
1191
+ case 2:
1192
+ labelPosition = MPLabelPosition.LEFT;
1193
+ break;
1194
+ case 3:
1195
+ labelPosition = MPLabelPosition.RIGHT;
1196
+ break;
1197
+ default:
1198
+ labelPosition = MPLabelPosition.BOTTOM;
1199
+ break;
1200
+ }
1201
+ displayRule.setLabelStylePosition(labelPosition);
1202
+ }
1203
+ promise.resolve(null);
1204
+ } else {
1205
+ reject(promise, displayRuleId);
1206
+ }
1207
+ }
1208
+
1167
1209
  @ReactMethod
1168
1210
  public void setLabelStyleGraphic(String displayRuleId, String graphic, final Promise promise) {
1169
1211
  MPDisplayRule displayRule = getRule(displayRuleId);
1170
1212
  if (displayRule != null) {
1171
1213
  MPLabelGraphic labelGraphic = gson.fromJson(graphic, MPLabelGraphic.class);
1172
1214
  displayRule.setLabelStyleGraphic(labelGraphic);
1173
- Log.i("timtest", "i did a thing");
1174
1215
  promise.resolve(null);
1175
1216
  } else {
1176
1217
  reject(promise, displayRuleId);
@@ -105,7 +105,7 @@ class MapBoxView: RCMapView {
105
105
  let camera = mapboxView.mapboxMap.cameraState
106
106
 
107
107
  update = CameraOptions(cameraState: camera)
108
- update.zoom = CGFloat(cameraUpdate.zoom!)
108
+ update.zoom = camera.zoom + CGFloat(cameraUpdate.zoom!)
109
109
 
110
110
  case "zoomTo":
111
111
  let camera = mapboxView.mapboxMap.cameraState
@@ -139,7 +139,7 @@ class MapBoxView: RCMapView {
139
139
 
140
140
  DispatchQueue.main.async { [self] in
141
141
  if (duration != 0) {
142
- mapboxView.mapboxMap.setCamera(to: cameraOption)
142
+ mapboxView.camera.ease(to: cameraOption, duration: TimeInterval(duration/1000))
143
143
  } else {
144
144
  mapboxView.mapboxMap.setCamera(to: cameraOption)
145
145
  }
@@ -526,6 +526,15 @@ RCT_EXTERN_METHOD(requiresMainQueueSetup)
526
526
  resolver:(RCTPromiseResolveBlock) resolve
527
527
  rejecter:(RCTPromiseRejectBlock) reject)
528
528
 
529
+ RCT_EXTERN_METHOD(getLabelStylePosition: (NSString *) displayRuleId
530
+ resolver:(RCTPromiseResolveBlock) resolve
531
+ rejecter:(RCTPromiseRejectBlock) reject)
532
+
533
+ RCT_EXTERN_METHOD(setLabelStylePosition: (NSString *) displayRuleId
534
+ value:(nonnull NSNumber *) value
535
+ resolver:(RCTPromiseResolveBlock) resolve
536
+ rejecter:(RCTPromiseRejectBlock) reject)
537
+
529
538
  RCT_EXTERN_METHOD(setLabelStyleGraphic: (NSString *) displayRuleId
530
539
  value:(NSString *) value
531
540
  resolver:(RCTPromiseResolveBlock) resolve
@@ -38,6 +38,52 @@ public class MPDisplayRuleModule: NSObject {
38
38
  }
39
39
  }
40
40
 
41
+ private func getIconPlacementIntValue(iconPlacement: MPIconPlacement) -> Int {
42
+ switch(iconPlacement) {
43
+ case .above:
44
+ return 1
45
+ case .below:
46
+ return 2
47
+ case .left:
48
+ return 3
49
+ case .right:
50
+ return 4
51
+ default:
52
+ return 0
53
+ }
54
+ }
55
+
56
+
57
+ private func getLabelPosition(labelPosition: NSNumber) -> MPLabelPosition {
58
+ switch(labelPosition.intValue) {
59
+ case 0:
60
+ return .left
61
+ case 1:
62
+ return .bottom
63
+ case 2:
64
+ return .top
65
+ case 3:
66
+ return .right
67
+ default:
68
+ return .bottom
69
+ }
70
+ }
71
+
72
+ private func getLabelPositionIntValue(labelPosition: MPLabelPosition) -> Int {
73
+ switch(labelPosition) {
74
+ case .left:
75
+ return 0
76
+ case .bottom:
77
+ return 1
78
+ case .top:
79
+ return 2
80
+ case .right:
81
+ return 3
82
+ default:
83
+ return 2
84
+ }
85
+ }
86
+
41
87
  private func getLabelType(labelType: NSNumber) -> MPLabelType {
42
88
  switch(labelType.intValue) {
43
89
  case 0:
@@ -51,6 +97,19 @@ public class MPDisplayRuleModule: NSObject {
51
97
  }
52
98
  }
53
99
 
100
+ private func getLabelTypeIntValue(labelType: MPLabelType) -> Int {
101
+ switch(labelType) {
102
+ case .flat:
103
+ return 0
104
+ case .floating:
105
+ return 1
106
+ case .graphic:
107
+ return 2
108
+ default:
109
+ return 1
110
+ }
111
+ }
112
+
54
113
  private func getBadgePosition(badgePosition: NSNumber) -> MPBadgePosition {
55
114
  switch(badgePosition.intValue) {
56
115
  case 1:
@@ -64,6 +123,19 @@ public class MPDisplayRuleModule: NSObject {
64
123
  }
65
124
  }
66
125
 
126
+ private func getBadgePositionIntValue(badgePosition: MPBadgePosition) -> Int {
127
+ switch(badgePosition) {
128
+ case .bottomRight:
129
+ return 1
130
+ case .topLeft:
131
+ return 2
132
+ case .topRight:
133
+ return 3
134
+ default:
135
+ return 0
136
+ }
137
+ }
138
+
67
139
  private func getTypeRule(typeName: String) -> MPDisplayRuleType? {
68
140
  // TODO: very similar to FLutter code, maybe combine shared functions somewhere
69
141
  switch (typeName) {
@@ -1034,7 +1106,7 @@ public class MPDisplayRuleModule: NSObject {
1034
1106
  return doReject(reject, displayRuleId: displayRuleId)
1035
1107
  }
1036
1108
 
1037
- return resolve(displayRule.badgePosition)
1109
+ return resolve(getBadgePositionIntValue(badgePosition: displayRule.badgePosition ?? MPBadgePosition.bottomLeft))
1038
1110
  }
1039
1111
 
1040
1112
  @objc public func setBadgePosition(_ displayRuleId: String, value: NSNumber, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
@@ -1056,7 +1128,7 @@ public class MPDisplayRuleModule: NSObject {
1056
1128
  return doReject(reject, displayRuleId: displayRuleId)
1057
1129
  }
1058
1130
 
1059
- return resolve(displayRule.iconPlacement)
1131
+ return resolve(getIconPlacementIntValue(iconPlacement: displayRule.iconPlacement ?? MPIconPlacement.center))
1060
1132
  }
1061
1133
 
1062
1134
  @objc public func setIconPlacement(_ displayRuleId: String, value: NSNumber, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
@@ -1078,7 +1150,7 @@ public class MPDisplayRuleModule: NSObject {
1078
1150
  return doReject(reject, displayRuleId: displayRuleId)
1079
1151
  }
1080
1152
 
1081
- return resolve(displayRule.iconPlacement)
1153
+ return resolve(getLabelTypeIntValue(labelType: displayRule.labelType ?? MPLabelType.floating))
1082
1154
  }
1083
1155
 
1084
1156
  @objc public func setLabelType(_ displayRuleId: String, value: NSNumber, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
@@ -1247,6 +1319,26 @@ public class MPDisplayRuleModule: NSObject {
1247
1319
  return resolve(nil)
1248
1320
  }
1249
1321
 
1322
+ @objc public func getLabelStylePosition(_ displayRuleId: String, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
1323
+ guard let displayRule = getRule(name: displayRuleId) else {
1324
+ return doReject(reject, displayRuleId: displayRuleId)
1325
+ }
1326
+
1327
+ return resolve(getLabelPositionIntValue(labelPosition: displayRule.labelStylePosition))
1328
+ }
1329
+
1330
+ @objc public func setLabelStylePosition(_ displayRuleId: String, value: NSNumber, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
1331
+ guard let displayRule = getRule(name: displayRuleId) else {
1332
+ return doReject(reject, displayRuleId: displayRuleId)
1333
+ }
1334
+
1335
+ if (value != -1) {
1336
+ displayRule.labelStylePosition = getLabelPosition(labelPosition: value)
1337
+ }
1338
+
1339
+ return resolve(nil)
1340
+ }
1341
+
1250
1342
  @objc public func setLabelStyleGraphic(_ displayRuleId: String, value: String, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
1251
1343
  guard let displayRule = getRule(name: displayRuleId) else {
1252
1344
  return doReject(reject, displayRuleId: displayRuleId)
@@ -1604,4 +1696,4 @@ public class MPDisplayRuleModule: NSObject {
1604
1696
  return resolve(nil)
1605
1697
  }
1606
1698
 
1607
- }
1699
+ }
@@ -53,6 +53,9 @@ public class MapControlModule: RCTEventEmitter {
53
53
  return doReject(reject, message: "Unable to initialize Map Control")
54
54
  }
55
55
 
56
+ if let showUserPosition = config["showUserPosition"] as? Bool {
57
+ mapControl.showUserPosition = showUserPosition
58
+ }
56
59
 
57
60
  let mapsIndoorsData = MapsIndoorsData.sharedInstance
58
61
 
@@ -525,19 +528,21 @@ public class MapControlModule: RCTEventEmitter {
525
528
  return doReject(reject, message: "mapControl is not available")
526
529
  }
527
530
 
528
- if (setup) {
529
- let delegate = mapsIndoorsData.mapControlListenerDelegate!
530
- mapControl.delegate = delegate
531
+ DispatchQueue.main.async {
532
+ if (setup) {
533
+ let delegate = mapsIndoorsData.mapControlListenerDelegate!
534
+ mapControl.delegate = delegate
531
535
 
532
- let floorSelector = FloorSelector(delegate: delegate)
533
- floorSelector.autoFloorChange = isAutoFloorChangeEnabled
536
+ let floorSelector = FloorSelector(delegate: delegate)
537
+ floorSelector.autoFloorChange = isAutoFloorChangeEnabled
534
538
 
535
- mapControl.floorSelector = floorSelector
536
- mapsIndoorsData.floorSelector = floorSelector
539
+ mapControl.floorSelector = floorSelector
540
+ mapsIndoorsData.floorSelector = floorSelector
537
541
 
538
- } else {
539
- mapControl.floorSelector = nil
540
- mapsIndoorsData.floorSelector = nil
542
+ } else {
543
+ mapControl.floorSelector = nil
544
+ mapsIndoorsData.floorSelector = nil
545
+ }
541
546
  }
542
547
 
543
548
  return resolve(nil)
@@ -78,21 +78,21 @@ class MapControlDelegate: MPMapControlDelegate, LiveDataDelegate, MPFloorSelecto
78
78
  if (respondToCameraEvents) {
79
79
  sendEvent(event: .cameraEvent, body: ["event": 5])
80
80
  }
81
- return true;
81
+ return false;
82
82
  }
83
83
 
84
84
  func cameraIdle() -> Bool {
85
85
  if (respondToCameraEvents) {
86
86
  sendEvent(event: .cameraEvent, body: ["event": 7])
87
87
  }
88
- return true;
88
+ return false;
89
89
  }
90
90
 
91
91
  func cameraWillMove() -> Bool {
92
92
  if (respondToCameraEvents) {
93
93
  sendEvent(event: .cameraEvent, body: ["event": 5])
94
94
  }
95
- return true;
95
+ return false;
96
96
  }
97
97
 
98
98
  func didTap(coordinate: MPPoint) -> Bool {
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.1.1",
4
+ "version": "2.2.0",
5
5
  "description": "React Native MapsIndoors component with mapbox",
6
6
  "react-native": "index.ts",
7
7
  "files": [
@@ -24,7 +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.6.1"
28
- s.dependency "MapsIndoorsCodable", "4.6.1"
27
+ s.dependency "MapsIndoorsMapbox11", "4.8.0"
28
+ s.dependency "MapsIndoorsCodable", "4.8.0"
29
29
  end
30
-
@@ -4,6 +4,7 @@ import { MPIconPlacement } from './MPIconPlacement';
4
4
  import { MPLabelType } from './MPLabelType';
5
5
  import { MPBadgePosition } from './MPBadgePosition';
6
6
  import MPLabelGraphic from './MPLabelGraphic';
7
+ import { MPLabelPosition } from './MPLabelPosition';
7
8
  const { DisplayRule } = NativeModules;
8
9
 
9
10
 
@@ -1309,6 +1310,27 @@ export default class MPDisplayRule {
1309
1310
  });
1310
1311
  }
1311
1312
 
1313
+ /**
1314
+ * Get the label's position
1315
+ * @returns Promise<MPLabelPosition>
1316
+ */
1317
+ public async getLabelStylePosition(): Promise<MPLabelPosition> {
1318
+ return DisplayRule.getLabelStylePosition(this.id).catch((err: Error) => {
1319
+ return Promise.reject(MPError.create(JSON.parse(err.message)));
1320
+ });
1321
+ }
1322
+
1323
+ /**
1324
+ * Set the label's position
1325
+ * @param position MPLabelPosition
1326
+ * @returns Promise<void>
1327
+ */
1328
+ public async setLabelStylePosition(position: MPLabelPosition): Promise<void> {
1329
+ return DisplayRule.setLabelStylePosition(this.id, position.valueOf()).catch((err: Error) => {
1330
+ return Promise.reject(MPError.create(JSON.parse(err.message)));
1331
+ });
1332
+ }
1333
+
1312
1334
  /**
1313
1335
  * Set the label's Graphic style
1314
1336
  * @param graphicLabel MPLabelGraphic
@@ -45,11 +45,11 @@ export default class MPHighlightBehavior {
45
45
  */
46
46
  public static create(object?: MPHighlightBehaviorParams): MPHighlightBehavior {
47
47
  return new MPHighlightBehavior(
48
- object?.allowFloorChange ? object.allowFloorChange : false,
49
- object?.moveCamera ? object.moveCamera : false,
50
- object?.animationDuration ? object.animationDuration : 0,
51
- object?.showInfoWindow ? object.showInfoWindow : false,
52
- object?.zoomToFit ? object?.zoomToFit : true
48
+ object?.allowFloorChange ?? false,
49
+ object?.moveCamera ?? false,
50
+ object?.animationDuration ?? 0,
51
+ object?.showInfoWindow ?? false,
52
+ object?.zoomToFit ?? true
53
53
  );
54
54
  };
55
55
  }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The possible position of the label, anchored on the icon.
3
+ *
4
+ * @export
5
+ * @enum {number}
6
+ */
7
+ export enum MPLabelPosition {
8
+ left,
9
+ top,
10
+ bottom,
11
+ right
12
+ }
@@ -139,7 +139,7 @@ export default class MPPoint extends MPGeometry {
139
139
  public toJSON(): MPPointParams {
140
140
  return {
141
141
  type: this.type,
142
- coordinates: [this.longitude, this.latitude, this.floorIndex ? this.floorIndex : 0],
142
+ coordinates: [this.longitude, this.latitude, this.floorIndex ?? 0],
143
143
  };
144
144
  }
145
145
  }
@@ -43,11 +43,11 @@ export default class MPSelectionBehavior {
43
43
  */
44
44
  static create(object: MPSelectionBehaviorParams): MPSelectionBehavior {
45
45
  return new MPSelectionBehavior(
46
- object?.allowFloorChange ? object.allowFloorChange : true,
47
- object?.moveCamera ? object.moveCamera : true,
48
- object?.animationDuration ? object.animationDuration : 500,
49
- object?.showInfoWindow ? object.showInfoWindow : true,
50
- object?.zoomToFit ? object.zoomToFit : true
46
+ object?.allowFloorChange ?? true,
47
+ object?.moveCamera ?? true,
48
+ object?.animationDuration ?? 500,
49
+ object?.showInfoWindow ?? true,
50
+ object?.zoomToFit ?? true
51
51
  );
52
52
  }
53
53
  }