@rnmapbox/maps 10.1.15 → 10.1.17

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 (102) hide show
  1. package/android/src/main/java/com/rnmapbox/rnmbx/RNMBXPackage.kt +13 -2
  2. package/android/src/main/java/com/rnmapbox/rnmbx/components/AbstractEventEmitter.kt +13 -7
  3. package/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapViewManager.kt +3 -1
  4. package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/layers/RNMBXLayer.kt +4 -4
  5. package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/sources/RNMBXShapeSource.kt +23 -17
  6. package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/sources/RNMBXShapeSourceManager.kt +1 -2
  7. package/android/src/main/java/com/rnmapbox/rnmbx/shapeAnimators/AnimatableElement.kt +38 -0
  8. package/android/src/main/java/com/rnmapbox/rnmbx/shapeAnimators/RNMBXChangeLineOffsetsShapeAnimatorModule.kt +217 -0
  9. package/android/src/main/java/com/rnmapbox/rnmbx/shapeAnimators/RNMBXMovePointShapeAnimatorModule.kt +108 -0
  10. package/android/src/main/java/com/rnmapbox/rnmbx/shapeAnimators/ShapeAnimatorCommon.kt +142 -0
  11. package/android/src/main/old-arch/com/rnmapbox/rnmbx/NativeRNMBXChangeLineOffsetsShapeAnimatorModuleSpec.java +52 -0
  12. package/android/src/main/old-arch/com/rnmapbox/rnmbx/NativeRNMBXMovePointShapeAnimatorModuleSpec.java +2 -2
  13. package/ios/RNMBX/RNMBXCircleLayer.swift +48 -1
  14. package/ios/RNMBX/RNMBXFillExtrusionLayer.swift +47 -1
  15. package/ios/RNMBX/RNMBXFillLayer.swift +47 -1
  16. package/ios/RNMBX/RNMBXLineLayer.swift +44 -1
  17. package/ios/RNMBX/RNMBXLogging.swift +78 -39
  18. package/ios/RNMBX/RNMBXModelLayer.swift +44 -1
  19. package/ios/RNMBX/RNMBXRasterLayer.swift +48 -2
  20. package/ios/RNMBX/RNMBXShapeSource.swift +30 -17
  21. package/ios/RNMBX/RNMBXSkyLayer.swift +22 -1
  22. package/ios/RNMBX/RNMBXSymbolLayer.swift +47 -1
  23. package/ios/RNMBX/ShapeAnimators/AnimatableElement.swift +48 -0
  24. package/ios/RNMBX/ShapeAnimators/RNMBXChangeLineOffsetsShapeAnimatorModule.m +64 -0
  25. package/ios/RNMBX/ShapeAnimators/RNMBXChangeLineOffsetsShapeAnimatorModule.swift +214 -0
  26. package/ios/RNMBX/ShapeAnimators/RNMBXMovePointShapeAnimatorModule.m +5 -10
  27. package/ios/RNMBX/ShapeAnimators/RNMBXMovePointShapeAnimatorModule.swift +92 -24
  28. package/ios/RNMBX/ShapeAnimators/ShapeAnimatorCommon.swift +71 -33
  29. package/ios/RNMBX/ShapeAnimators/ShapeAnimatorManager.swift +3 -1
  30. package/ios/RNMBX/codeparts/LayerPropsCommon.codepart-swift.ejs +51 -0
  31. package/lib/commonjs/Mapbox.js +4 -2
  32. package/lib/commonjs/Mapbox.js.map +1 -1
  33. package/lib/commonjs/components/ShapeSource.js.map +1 -1
  34. package/lib/commonjs/shapeAnimators/ChangeLineOffsetsShapeAnimator.js +27 -0
  35. package/lib/commonjs/shapeAnimators/ChangeLineOffsetsShapeAnimator.js.map +1 -0
  36. package/lib/commonjs/{shape_animators → shapeAnimators}/MovePointShapeAnimator.js +4 -4
  37. package/lib/commonjs/shapeAnimators/MovePointShapeAnimator.js.map +1 -0
  38. package/lib/commonjs/shapeAnimators/ShapeAnimatorManager.js.map +1 -0
  39. package/lib/commonjs/shapeAnimators/index.js +2 -0
  40. package/lib/commonjs/shapeAnimators/index.js.map +1 -0
  41. package/lib/commonjs/specs/NativeRNMBXChangeLineOffsetsShapeAnimatorModule.js +10 -0
  42. package/lib/commonjs/specs/NativeRNMBXChangeLineOffsetsShapeAnimatorModule.js.map +1 -0
  43. package/lib/commonjs/specs/NativeRNMBXMovePointShapeAnimatorModule.js.map +1 -1
  44. package/lib/commonjs/utils/Logger.js +13 -7
  45. package/lib/commonjs/utils/Logger.js.map +1 -1
  46. package/lib/module/Mapbox.js +4 -2
  47. package/lib/module/Mapbox.js.map +1 -1
  48. package/lib/module/components/ShapeSource.js.map +1 -1
  49. package/lib/module/shapeAnimators/ChangeLineOffsetsShapeAnimator.js +19 -0
  50. package/lib/module/shapeAnimators/ChangeLineOffsetsShapeAnimator.js.map +1 -0
  51. package/lib/module/shapeAnimators/MovePointShapeAnimator.js +13 -0
  52. package/lib/module/shapeAnimators/MovePointShapeAnimator.js.map +1 -0
  53. package/lib/module/shapeAnimators/ShapeAnimatorManager.js.map +1 -0
  54. package/lib/module/shapeAnimators/index.js +2 -0
  55. package/lib/module/shapeAnimators/index.js.map +1 -0
  56. package/lib/module/specs/NativeRNMBXChangeLineOffsetsShapeAnimatorModule.js +6 -0
  57. package/lib/module/specs/NativeRNMBXChangeLineOffsetsShapeAnimatorModule.js.map +1 -0
  58. package/lib/module/specs/NativeRNMBXMovePointShapeAnimatorModule.js.map +1 -1
  59. package/lib/module/utils/Logger.js +13 -7
  60. package/lib/module/utils/Logger.js.map +1 -1
  61. package/lib/typescript/src/Mapbox.d.ts +3 -1
  62. package/lib/typescript/src/Mapbox.d.ts.map +1 -1
  63. package/lib/typescript/src/components/ShapeSource.d.ts +2 -1
  64. package/lib/typescript/src/components/ShapeSource.d.ts.map +1 -1
  65. package/lib/typescript/src/shapeAnimators/ChangeLineOffsetsShapeAnimator.d.ts +24 -0
  66. package/lib/typescript/src/shapeAnimators/ChangeLineOffsetsShapeAnimator.d.ts.map +1 -0
  67. package/lib/typescript/src/shapeAnimators/MovePointShapeAnimator.d.ts +11 -0
  68. package/lib/typescript/src/shapeAnimators/MovePointShapeAnimator.d.ts.map +1 -0
  69. package/lib/typescript/src/shapeAnimators/ShapeAnimatorManager.d.ts.map +1 -0
  70. package/lib/typescript/src/shapeAnimators/index.d.ts +4 -0
  71. package/lib/typescript/src/shapeAnimators/index.d.ts.map +1 -0
  72. package/lib/typescript/src/specs/NativeRNMBXChangeLineOffsetsShapeAnimatorModule.d.ts +13 -0
  73. package/lib/typescript/src/specs/NativeRNMBXChangeLineOffsetsShapeAnimatorModule.d.ts.map +1 -0
  74. package/lib/typescript/src/specs/NativeRNMBXMovePointShapeAnimatorModule.d.ts +2 -2
  75. package/lib/typescript/src/specs/NativeRNMBXMovePointShapeAnimatorModule.d.ts.map +1 -1
  76. package/lib/typescript/src/utils/Logger.d.ts +2 -2
  77. package/lib/typescript/src/utils/Logger.d.ts.map +1 -1
  78. package/package.json +1 -1
  79. package/setup-jest.js +5 -0
  80. package/src/Mapbox.ts +3 -1
  81. package/src/components/ShapeSource.tsx +3 -1
  82. package/src/shapeAnimators/ChangeLineOffsetsShapeAnimator.ts +57 -0
  83. package/src/shapeAnimators/MovePointShapeAnimator.ts +27 -0
  84. package/src/shapeAnimators/index.ts +3 -0
  85. package/src/specs/NativeRNMBXChangeLineOffsetsShapeAnimatorModule.ts +37 -0
  86. package/src/specs/NativeRNMBXMovePointShapeAnimatorModule.ts +6 -2
  87. package/src/utils/Logger.ts +17 -9
  88. package/android/src/main/java/com/rnmapbox/rnmbx/shape_animators/RNMBXMovePointShapeAnimatorModule.kt +0 -55
  89. package/android/src/main/java/com/rnmapbox/rnmbx/shape_animators/ShapeAnimatorCommon.kt +0 -110
  90. package/lib/commonjs/shape_animators/MovePointShapeAnimator.js.map +0 -1
  91. package/lib/commonjs/shape_animators/ShapeAnimatorManager.js.map +0 -1
  92. package/lib/module/shape_animators/MovePointShapeAnimator.js +0 -13
  93. package/lib/module/shape_animators/MovePointShapeAnimator.js.map +0 -1
  94. package/lib/module/shape_animators/ShapeAnimatorManager.js.map +0 -1
  95. package/lib/typescript/src/shape_animators/MovePointShapeAnimator.d.ts +0 -7
  96. package/lib/typescript/src/shape_animators/MovePointShapeAnimator.d.ts.map +0 -1
  97. package/lib/typescript/src/shape_animators/ShapeAnimatorManager.d.ts.map +0 -1
  98. package/src/shape_animators/MovePointShapeAnimator.ts +0 -18
  99. /package/lib/commonjs/{shape_animators → shapeAnimators}/ShapeAnimatorManager.js +0 -0
  100. /package/lib/module/{shape_animators → shapeAnimators}/ShapeAnimatorManager.js +0 -0
  101. /package/lib/typescript/src/{shape_animators → shapeAnimators}/ShapeAnimatorManager.d.ts +0 -0
  102. /package/src/{shape_animators → shapeAnimators}/ShapeAnimatorManager.tsx +0 -0
@@ -20,16 +20,59 @@ public class RNMBXModelLayer: RNMBXVectorLayer {
20
20
  return LayerType.self
21
21
  }
22
22
 
23
+ // @{codepart-replace-start(LayerPropsCommon.codepart-swift.ejs,{layerType:"Model"})}
24
+ func setCommonOptions(_ layer: inout ModelLayer) -> Bool {
25
+ var changed = false
26
+
27
+ #if RNMBX_11
28
+ if let sourceLayerID = sourceLayerID {
29
+ layer.sourceLayer = sourceLayerID
30
+ changed = true
31
+ }
32
+
33
+ if let sourceID = sourceID {
34
+ if !(existingLayer && sourceID == DEFAULT_SOURCE_ID) && hasSource() {
35
+ layer.source = sourceID
36
+ changed = true
37
+ }
38
+ }
39
+
40
+ if let filter = filter, filter.count > 0 {
41
+ do {
42
+ let data = try JSONSerialization.data(withJSONObject: filter, options: .prettyPrinted)
43
+ let decodedExpression = try JSONDecoder().decode(Expression.self, from: data)
44
+ layer.filter = decodedExpression
45
+ changed = true
46
+ } catch {
47
+ Logger.log(level: .error, message: "parsing filters failed for layer \(optional: id): \(error.localizedDescription)")
48
+ }
49
+ }
50
+ #endif
51
+
52
+ return changed
53
+ }
54
+
55
+ override func setOptions(_ layer: inout Layer) {
56
+ if var actualLayer = layer as? LayerType {
57
+ if self.setCommonOptions(&actualLayer) {
58
+ layer = actualLayer
59
+ }
60
+ } else {
61
+ Logger.log(level: .error, message: "Expected layer type to be Model but was \(type(of: layer))")
62
+ }
63
+ }
64
+
23
65
  override func apply(style : Style) throws {
24
66
  try style.updateLayer(withId: id, type: LayerType.self) { (layer : inout ModelLayer) in
25
67
  if self.styleLayer != nil {
26
68
  self.setOptions(&self.styleLayer!)
27
69
  }
28
- if let styleLayer = self.styleLayer as? ModelLayer {
70
+ if let styleLayer = self.styleLayer as? LayerType {
29
71
  layer = styleLayer
30
72
  }
31
73
  }
32
74
  }
75
+ // @{codepart-replace-end}
33
76
 
34
77
  override func addStyles() {
35
78
  if let style : Style = self.style {
@@ -15,13 +15,59 @@ public class RNMBXRasterLayer: RNMBXLayer {
15
15
  return layer
16
16
  }
17
17
 
18
+ // @{codepart-replace-start(LayerPropsCommon.codepart-swift.ejs,{layerType:"Raster"})}
19
+ func setCommonOptions(_ layer: inout RasterLayer) -> Bool {
20
+ var changed = false
21
+
22
+ #if RNMBX_11
23
+ if let sourceLayerID = sourceLayerID {
24
+ layer.sourceLayer = sourceLayerID
25
+ changed = true
26
+ }
27
+
28
+ if let sourceID = sourceID {
29
+ if !(existingLayer && sourceID == DEFAULT_SOURCE_ID) && hasSource() {
30
+ layer.source = sourceID
31
+ changed = true
32
+ }
33
+ }
34
+
35
+ if let filter = filter, filter.count > 0 {
36
+ do {
37
+ let data = try JSONSerialization.data(withJSONObject: filter, options: .prettyPrinted)
38
+ let decodedExpression = try JSONDecoder().decode(Expression.self, from: data)
39
+ layer.filter = decodedExpression
40
+ changed = true
41
+ } catch {
42
+ Logger.log(level: .error, message: "parsing filters failed for layer \(optional: id): \(error.localizedDescription)")
43
+ }
44
+ }
45
+ #endif
46
+
47
+ return changed
48
+ }
49
+
50
+ override func setOptions(_ layer: inout Layer) {
51
+ if var actualLayer = layer as? LayerType {
52
+ if self.setCommonOptions(&actualLayer) {
53
+ layer = actualLayer
54
+ }
55
+ } else {
56
+ Logger.log(level: .error, message: "Expected layer type to be Raster but was \(type(of: layer))")
57
+ }
58
+ }
59
+
18
60
  override func apply(style : Style) throws {
19
- try style.updateLayer(withId: id, type: RasterLayer.self) { (layer : inout RasterLayer) in
20
- if let styleLayer = self.styleLayer as? RasterLayer {
61
+ try style.updateLayer(withId: id, type: LayerType.self) { (layer : inout RasterLayer) in
62
+ if self.styleLayer != nil {
63
+ self.setOptions(&self.styleLayer!)
64
+ }
65
+ if let styleLayer = self.styleLayer as? LayerType {
21
66
  layer = styleLayer
22
67
  }
23
68
  }
24
69
  }
70
+ // @{codepart-replace-end}
25
71
 
26
72
  override func addStyles() {
27
73
  if let style : Style = self.style,
@@ -1,6 +1,8 @@
1
1
  import MapboxMaps
2
2
  import Turf
3
3
 
4
+ private let LOG_TAG = "RNMBXShapeSource"
5
+
4
6
  @objc
5
7
  public class RNMBXShapeSource : RNMBXSource {
6
8
  @objc public var url : String? {
@@ -11,13 +13,12 @@ public class RNMBXShapeSource : RNMBXSource {
11
13
  switch result {
12
14
  case .success(let obj):
13
15
  self.doUpdate { (style) in
14
- logged("RNMBXShapeSource.setUrl") {
16
+ logged(LOG_TAG, "setUrl") {
15
17
  try style.updateGeoJSONSource(withId: self.id, geoJSON: obj)
16
18
  }
17
19
  }
18
-
19
20
  case .failure(let error):
20
- Logger.log(level: .error, message: ":: Error - update url failed \(error) \(error.localizedDescription)")
21
+ Logger.log(level: .error, message: "Update url failed", error: error)
21
22
  }
22
23
  }
23
24
  }
@@ -30,21 +31,22 @@ public class RNMBXShapeSource : RNMBXSource {
30
31
  didSet {
31
32
  shapeAnimator?.unsubscribe(consumer: self)
32
33
  shapeAnimator = nil
33
-
34
- if let shape = shape, ShapeAnimatorManager.shared.isShapeAnimatorTag(shape: shape), let animatedShape = ShapeAnimatorManager.shared.get(shape: shape) {
34
+
35
+ if let shape = shape, ShapeAnimatorManager.shared.isShapeAnimatorTag(shape: shape) {
35
36
  if let shapeAnimator = ShapeAnimatorManager.shared.get(shape: shape) {
36
37
  self.shapeAnimator = shapeAnimator
37
38
  shapeAnimator.subscribe(consumer: self)
38
39
 
39
- shapeUpdated(shape: shapeAnimator.getShape())
40
+ let shape = shapeAnimator.getShape()
41
+ shapeUpdated(shape: shape)
40
42
  }
41
- } else {
42
- logged("RNMBXShapeSource.updateShape") {
43
+ } else {
44
+ logged(LOG_TAG, "updateShape") {
43
45
  let obj : GeoJSONObject = try parse(shape)
44
46
  shapeObject = obj
45
47
 
46
48
  doUpdate { (style) in
47
- logged("RNMBXShapeSource.setShape") {
49
+ logged(LOG_TAG, "setShape") {
48
50
  try style.updateGeoJSONSource(withId: id, geoJSON: obj)
49
51
  }
50
52
  }
@@ -52,15 +54,26 @@ public class RNMBXShapeSource : RNMBXSource {
52
54
  }
53
55
  }
54
56
  }
57
+
58
+ public override func addToMap(_ map: RNMBXMapView, style: Style) {
59
+ super.addToMap(map, style: style)
60
+ }
61
+
62
+ public override func removeFromMap(_ map: RNMBXMapView, reason: RemovalReason) -> Bool {
63
+ if (reason == .ViewRemoval) {
64
+ shapeAnimator?.unsubscribe(consumer: self)
65
+ }
66
+ return super.removeFromMap(map, reason: reason)
67
+ }
55
68
 
56
69
  @objc public var cluster : NSNumber?
57
70
  @objc public var clusterRadius : NSNumber?
58
71
  @objc public var clusterMaxZoomLevel : NSNumber? {
59
72
  didSet {
60
- logged("RNMBXShapeSource.clusterMaxZoomLevel") {
73
+ logged(LOG_TAG, "clusterMaxZoomLevel") {
61
74
  if let number = clusterMaxZoomLevel?.doubleValue {
62
75
  doUpdate { (style) in
63
- logged("RNMBXShapeSource.doUpdate") {
76
+ logged(LOG_TAG, "clusterMaxZoomLevel") {
64
77
  try style.setSourceProperty(for: id, property: "clusterMaxZoom", value: number)
65
78
  }
66
79
  }
@@ -119,7 +132,7 @@ public class RNMBXShapeSource : RNMBXSource {
119
132
  }
120
133
  }
121
134
  } catch {
122
- Logger.log(level: .error, message: "RNMBXShapeSource.parsing clusterProperties failed", error: error)
135
+ Logger.log(level: .error, tag: LOG_TAG, message: "makeSource: parsing clusterProperties failed", error: error)
123
136
  }
124
137
 
125
138
  if let maxZoomLevel = maxZoomLevel {
@@ -271,10 +284,10 @@ extension RNMBXShapeSource
271
284
  return nil
272
285
  }
273
286
  guard let data = shape.data(using: .utf8) else {
274
- Logger.log(level: .error, message: "shapeSource.setShape: Shape is not utf8")
287
+ Logger.log(level: .error, tag: LOG_TAG, message: "parseAsJSONObject: Shape is not utf8")
275
288
  return nil
276
289
  }
277
- let objs = logged("shapeSource.setShape.parseJSON") {
290
+ let objs = logged(LOG_TAG, "parseAsJSONObject") {
278
291
  try JSONSerialization.jsonObject(with: data)
279
292
  }
280
293
  return objs
@@ -344,7 +357,7 @@ extension RNMBXShapeSource
344
357
  return
345
358
  }
346
359
 
347
- logged("RNMBXShapeSource.getClusterExpansionZoom", rejecter: { (_,_,error) in
360
+ logged(LOG_TAG, "getClusterExpansionZoom", rejecter: { (_,_,error) in
348
361
  completion(.failure(error!))
349
362
  }) {
350
363
  let cluster : Feature = try parse(featureJSON);
@@ -375,7 +388,7 @@ extension RNMBXShapeSource
375
388
  return
376
389
  }
377
390
 
378
- logged("RNMBXShapeSource.getClusterLeaves", rejecter: { (_,_,error) in
391
+ logged(LOG_TAG, "getClusterLeaves", rejecter: { (_,_,error) in
379
392
  completion(.failure(error!))
380
393
  }) {
381
394
  let cluster : Feature = try parse(featureJSON);
@@ -397,7 +410,7 @@ extension RNMBXShapeSource
397
410
  return
398
411
  }
399
412
 
400
- logged("RNMBXShapeSource.getClusterChildren", rejecter: { (_,_,error) in
413
+ logged(LOG_TAG, "getClusterChildren", rejecter: { (_,_,error) in
401
414
  completion(.failure(error!))
402
415
  }) {
403
416
  let cluster : Feature = try parse(featureJSON);
@@ -13,13 +13,34 @@ public class RNMBXSkyLayer: RNMBXLayer {
13
13
  return LayerType.self
14
14
  }
15
15
 
16
+ // @{codepart-replace-start(LayerPropsCommon.codepart-swift.ejs,{layerType:"Sky"})}
17
+ func setCommonOptions(_ layer: inout SkyLayer) -> Bool {
18
+ var changed = false
19
+
20
+ return changed
21
+ }
22
+
23
+ override func setOptions(_ layer: inout Layer) {
24
+ if var actualLayer = layer as? LayerType {
25
+ if self.setCommonOptions(&actualLayer) {
26
+ layer = actualLayer
27
+ }
28
+ } else {
29
+ Logger.log(level: .error, message: "Expected layer type to be Sky but was \(type(of: layer))")
30
+ }
31
+ }
32
+
16
33
  override func apply(style : Style) throws {
17
- try style.updateLayer(withId: id, type: LayerType.self) { (layer : inout LayerType) in
34
+ try style.updateLayer(withId: id, type: LayerType.self) { (layer : inout SkyLayer) in
35
+ if self.styleLayer != nil {
36
+ self.setOptions(&self.styleLayer!)
37
+ }
18
38
  if let styleLayer = self.styleLayer as? LayerType {
19
39
  layer = styleLayer
20
40
  }
21
41
  }
22
42
  }
43
+ // @{codepart-replace-end}
23
44
 
24
45
  override func addStyles() {
25
46
  if let style : Style = self.style {
@@ -21,13 +21,59 @@ public class RNMBXSymbolLayer: RNMBXVectorLayer {
21
21
  return LayerType.self
22
22
  }
23
23
 
24
+ // @{codepart-replace-start(LayerPropsCommon.codepart-swift.ejs,{layerType:"Symbol"})}
25
+ func setCommonOptions(_ layer: inout SymbolLayer) -> Bool {
26
+ var changed = false
27
+
28
+ #if RNMBX_11
29
+ if let sourceLayerID = sourceLayerID {
30
+ layer.sourceLayer = sourceLayerID
31
+ changed = true
32
+ }
33
+
34
+ if let sourceID = sourceID {
35
+ if !(existingLayer && sourceID == DEFAULT_SOURCE_ID) && hasSource() {
36
+ layer.source = sourceID
37
+ changed = true
38
+ }
39
+ }
40
+
41
+ if let filter = filter, filter.count > 0 {
42
+ do {
43
+ let data = try JSONSerialization.data(withJSONObject: filter, options: .prettyPrinted)
44
+ let decodedExpression = try JSONDecoder().decode(Expression.self, from: data)
45
+ layer.filter = decodedExpression
46
+ changed = true
47
+ } catch {
48
+ Logger.log(level: .error, message: "parsing filters failed for layer \(optional: id): \(error.localizedDescription)")
49
+ }
50
+ }
51
+ #endif
52
+
53
+ return changed
54
+ }
55
+
56
+ override func setOptions(_ layer: inout Layer) {
57
+ if var actualLayer = layer as? LayerType {
58
+ if self.setCommonOptions(&actualLayer) {
59
+ layer = actualLayer
60
+ }
61
+ } else {
62
+ Logger.log(level: .error, message: "Expected layer type to be Symbol but was \(type(of: layer))")
63
+ }
64
+ }
65
+
24
66
  override func apply(style : Style) throws {
25
67
  try style.updateLayer(withId: id, type: LayerType.self) { (layer : inout SymbolLayer) in
26
- if var styleLayer = self.styleLayer as? LayerType {
68
+ if self.styleLayer != nil {
69
+ self.setOptions(&self.styleLayer!)
70
+ }
71
+ if let styleLayer = self.styleLayer as? LayerType {
27
72
  layer = styleLayer
28
73
  }
29
74
  }
30
75
  }
76
+ // @{codepart-replace-end}
31
77
 
32
78
  override func addStyles() {
33
79
  if let style : Style = self.style {
@@ -0,0 +1,48 @@
1
+ import Foundation
2
+
3
+ internal class AnimatableElement<T> {
4
+ var source: T
5
+ var progress: T
6
+ var target: T
7
+ var startedAtSec: TimeInterval
8
+ var progressDurationSec: TimeInterval
9
+ var totalDurationSec: TimeInterval
10
+ /// A function returning the difference in meters between the two values.
11
+ var getDistanceRemaining: (_ a: T, _ b: T) -> Double
12
+
13
+ init(source: T, progress: T, target: T, startedAtSec: TimeInterval, progressDurationSec: TimeInterval, totalDurationSec: TimeInterval, getDistanceRemaining: @escaping (_: T, _: T) -> Double) {
14
+ self.source = source
15
+ self.progress = progress
16
+ self.target = target
17
+ self.startedAtSec = startedAtSec
18
+ self.progressDurationSec = progressDurationSec
19
+ self.totalDurationSec = totalDurationSec
20
+ self.getDistanceRemaining = getDistanceRemaining
21
+ }
22
+
23
+ func distanceRemaining() -> Double {
24
+ getDistanceRemaining(source, target)
25
+ }
26
+
27
+ func durationRatio() -> Double {
28
+ if (totalDurationSec > 0) {
29
+ return progressDurationSec / totalDurationSec
30
+ } else {
31
+ return 1
32
+ }
33
+ }
34
+
35
+ func setProgress(value: T, animatorAgeSec: TimeInterval) {
36
+ progress = value
37
+ progressDurationSec = animatorAgeSec - startedAtSec
38
+ }
39
+
40
+ func reset(_source: T, _progress: T, _target: T, durationSec: TimeInterval, animatorAgeSec: TimeInterval) {
41
+ self.source = _source
42
+ self.progress = _progress
43
+ self.target = _target
44
+ self.startedAtSec = animatorAgeSec
45
+ self.progressDurationSec = 0
46
+ self.totalDurationSec = durationSec
47
+ }
48
+ }
@@ -0,0 +1,64 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import <UIKit/UIKit.h>
3
+
4
+ #import <React/RCTBridge.h>
5
+ #import <React/RCTUIManager.h>
6
+ #import <React/RCTUIManagerUtils.h>
7
+
8
+ #import "rnmapbox_maps-Swift.pre.h"
9
+
10
+ #ifdef RCT_NEW_ARCH_ENABLED
11
+ #import "rnmapbox_maps_specs.h"
12
+ #else
13
+ #import <React/RCTBridge.h>
14
+ #endif
15
+
16
+ @interface RNMBXChangeLineOffsetsShapeAnimatorModule: NSObject
17
+ #ifdef RCT_NEW_ARCH_ENABLED
18
+ <NativeRNMBXChangeLineOffsetsShapeAnimatorModuleSpec>
19
+ #else
20
+ <RCTBridgeModule>
21
+ #endif
22
+ @end
23
+
24
+ @implementation RNMBXChangeLineOffsetsShapeAnimatorModule
25
+
26
+ RCT_EXPORT_MODULE();
27
+
28
+ #ifdef RCT_NEW_ARCH_ENABLED
29
+ @synthesize viewRegistry_DEPRECATED = _viewRegistry_DEPRECATED;
30
+ #endif // RCT_NEW_ARCH_ENABLED
31
+ @synthesize bridge = _bridge;
32
+
33
+ - (dispatch_queue_t)methodQueue {
34
+ // It seems that due to how UIBlocks work with uiManager, we need to call the methods there
35
+ // for the blocks to be dispatched before the batch is completed
36
+ return RCTGetUIManagerQueue();
37
+ }
38
+
39
+ RCT_EXPORT_METHOD(create:(nonnull NSNumber*)tag lineString: (nonnull NSArray*)coordinates startOffset: (nonnull NSNumber*)startOffset endOffset: (nonnull NSNumber*)endOffset resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
40
+ resolve([[ChangeLineOffsetsShapeAnimator createWithTag:tag coordinates:coordinates startOffset:startOffset endOffset:endOffset] getTag]);
41
+ }
42
+
43
+ RCT_EXPORT_METHOD(setLineString:(nonnull NSNumber*)tag coordinates: (nonnull NSArray*)coordinates startOffset: (nonnull NSNumber*)startOffset endOffset: (nonnull NSNumber*)endOffset resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
44
+ [ChangeLineOffsetsShapeAnimator setLineStringWithTag:tag coordinates:coordinates startOffset:startOffset endOffset:endOffset resolve:resolve reject:reject];
45
+ }
46
+
47
+ RCT_EXPORT_METHOD(setStartOffset:(nonnull NSNumber*)tag offset: (nonnull NSNumber*)offset durationMs: (nonnull NSNumber*)durationMs resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
48
+ [ChangeLineOffsetsShapeAnimator setStartOffsetWithTag:tag offset:offset durationMs:durationMs resolve:resolve reject:reject];
49
+ }
50
+
51
+ RCT_EXPORT_METHOD(setEndOffset:(nonnull NSNumber*)tag offset: (nonnull NSNumber*)offset durationMs: (nonnull NSNumber*)durationMs resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
52
+ [ChangeLineOffsetsShapeAnimator setEndOffsetWithTag:tag offset:offset durationMs:durationMs resolve:resolve reject:reject];
53
+ }
54
+
55
+ // Thanks to this guard, we won't compile this code when we build for the old architecture.
56
+ #ifdef RCT_NEW_ARCH_ENABLED
57
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
58
+ (const facebook::react::ObjCTurboModule::InitParams &)params
59
+ {
60
+ return std::make_shared<facebook::react::NativeRNMBXShapeSourceModuleSpecJSI>(params);
61
+ }
62
+ #endif // RCT_NEW_ARCH_ENABLED
63
+
64
+ @end
@@ -0,0 +1,214 @@
1
+ import MapboxMaps
2
+ import Turf
3
+
4
+ private let LOG_TAG = "ChangeLineOffsetsShapeAnimator"
5
+
6
+ @objc
7
+ public class ChangeLineOffsetsShapeAnimator: ShapeAnimatorCommon {
8
+ private var lineString: LineString
9
+ private var startOfLine: AnimatableElement<Double>
10
+ private var endOfLine: AnimatableElement<Double>
11
+
12
+ init(tag: Int, lineString: LineString, startOffset: Double, endOffset: Double) {
13
+ self.lineString = lineString
14
+ self.startOfLine = AnimatableElement<Double>(
15
+ source: startOffset,
16
+ progress: startOffset,
17
+ target: startOffset,
18
+ startedAtSec: 0,
19
+ progressDurationSec: 0,
20
+ totalDurationSec: 0,
21
+ getDistanceRemaining: { a, b in b - a }
22
+ )
23
+ self.endOfLine = AnimatableElement<Double>(
24
+ source: endOffset,
25
+ progress: endOffset,
26
+ target: endOffset,
27
+ startedAtSec: 0,
28
+ progressDurationSec: 0,
29
+ totalDurationSec: 0,
30
+ getDistanceRemaining: { a, b in b - a }
31
+ )
32
+
33
+ super.init(tag: tag)
34
+ }
35
+
36
+ override func getShape() -> GeoJSONObject {
37
+ return .geometry(.lineString(lineString))
38
+ }
39
+
40
+ override func getAnimatedShape(animatorAgeSec: TimeInterval) -> GeoJSONObject {
41
+ if (startOfLine.durationRatio() < 1) {
42
+ startOfLine.setProgress(
43
+ value: startOfLine.source + (startOfLine.distanceRemaining() * startOfLine.durationRatio()),
44
+ animatorAgeSec: animatorAgeSec
45
+ )
46
+ }
47
+
48
+ if (endOfLine.durationRatio() < 1) {
49
+ endOfLine.setProgress(
50
+ value: endOfLine.source + (endOfLine.distanceRemaining() * endOfLine.durationRatio()),
51
+ animatorAgeSec: animatorAgeSec
52
+ )
53
+ }
54
+
55
+ if (startOfLine.durationRatio() >= 1 && endOfLine.durationRatio() >= 1) {
56
+ stop()
57
+ }
58
+
59
+ if (lineString.coordinates.count < 2) {
60
+ return emptyGeoJsonObj
61
+ }
62
+
63
+ guard let totalDistance = lineString.distance(), totalDistance > 0 else {
64
+ return emptyGeoJsonObj
65
+ }
66
+
67
+ if (startOfLine.progress + endOfLine.progress >= totalDistance) {
68
+ return emptyGeoJsonObj
69
+ }
70
+
71
+ guard let trimmed = lineString.trimmed(from: startOfLine.progress, to: totalDistance - endOfLine.progress) else {
72
+ return emptyGeoJsonObj
73
+ }
74
+
75
+ return .geometry(.lineString(trimmed))
76
+ }
77
+
78
+ private func setLineString(lineString: LineString, startOffset: Double?, endOffset: Double?) {
79
+ self.lineString = lineString
80
+ if let _startOffset = startOffset {
81
+ startOfLine.reset(
82
+ _source: _startOffset,
83
+ _progress: _startOffset,
84
+ _target: _startOffset,
85
+ durationSec: 0,
86
+ animatorAgeSec: getAnimatorAgeSec()
87
+ )
88
+ }
89
+ if let _endOffset = endOffset {
90
+ endOfLine.reset(
91
+ _source: _endOffset,
92
+ _progress: _endOffset,
93
+ _target: _endOffset,
94
+ durationSec: 0,
95
+ animatorAgeSec: getAnimatorAgeSec()
96
+ )
97
+ }
98
+ refresh()
99
+ }
100
+
101
+ private func setStartOffset(offset: Double, durationSec: TimeInterval) {
102
+ if durationSec == 0 {
103
+ startOfLine.reset(
104
+ _source: offset,
105
+ _progress: offset,
106
+ _target: offset,
107
+ durationSec: durationSec,
108
+ animatorAgeSec: getAnimatorAgeSec()
109
+ )
110
+ refresh()
111
+ } else {
112
+ start()
113
+ startOfLine.reset(
114
+ _source: startOfLine.progress,
115
+ _progress: startOfLine.progress,
116
+ _target: offset,
117
+ durationSec: durationSec,
118
+ animatorAgeSec: getAnimatorAgeSec()
119
+ )
120
+ }
121
+ }
122
+
123
+ private func setEndOffset(offset: Double, durationSec: TimeInterval) {
124
+ if durationSec == 0 {
125
+ endOfLine.reset(
126
+ _source: offset,
127
+ _progress: offset,
128
+ _target: offset,
129
+ durationSec: durationSec,
130
+ animatorAgeSec: getAnimatorAgeSec()
131
+ )
132
+ refresh()
133
+ } else {
134
+ start()
135
+ endOfLine.reset(
136
+ _source: endOfLine.progress,
137
+ _progress: endOfLine.progress,
138
+ _target: offset,
139
+ durationSec: durationSec,
140
+ animatorAgeSec: getAnimatorAgeSec()
141
+ )
142
+ }
143
+ }
144
+
145
+ private static func getAnimator(tag: NSNumber) -> ChangeLineOffsetsShapeAnimator? {
146
+ let animator = ShapeAnimatorManager.shared.get(tag: tag.intValue)
147
+ return animator as? ChangeLineOffsetsShapeAnimator
148
+ }
149
+ }
150
+
151
+ // MARK: Exposed functions
152
+
153
+ extension ChangeLineOffsetsShapeAnimator {
154
+ @objc
155
+ public func getTag() -> NSNumber {
156
+ return NSNumber(value: tag)
157
+ }
158
+
159
+ @objc
160
+ public static func create(tag: NSNumber, coordinates: NSArray, startOffset: NSNumber, endOffset: NSNumber) -> ChangeLineOffsetsShapeAnimator? {
161
+ let lineString = buildLineString(_coordinates: coordinates)
162
+ let animator = ChangeLineOffsetsShapeAnimator(tag: tag.intValue, lineString: lineString, startOffset: startOffset.doubleValue, endOffset: endOffset.doubleValue)
163
+ ShapeAnimatorManager.shared.register(tag: tag.intValue, animator: animator)
164
+ return animator
165
+ }
166
+
167
+ @objc
168
+ public static func setLineString(tag: NSNumber, coordinates: NSArray, startOffset: NSNumber, endOffset: NSNumber, resolve: RCTPromiseResolveBlock, reject: @escaping (_ code: String, _ message: String, _ error: NSError) -> Void) {
169
+ let lineString = buildLineString(_coordinates: coordinates)
170
+ guard let animator = getAnimator(tag: tag) else {
171
+ reject("\(LOG_TAG): setLineString", "Unable to find animator with tag \(tag)", NSError())
172
+ return
173
+ }
174
+
175
+ let _startOffset: NSNumber? = startOffset != -1 ? startOffset : nil
176
+ let _endOffset: NSNumber? = endOffset != -1 ? endOffset : nil
177
+
178
+ animator.setLineString(lineString: lineString, startOffset: _startOffset?.doubleValue, endOffset: _endOffset?.doubleValue)
179
+ resolve(tag)
180
+ }
181
+
182
+ @objc
183
+ public static func setStartOffset(tag: NSNumber, offset: NSNumber, durationMs: NSNumber, resolve: RCTPromiseResolveBlock, reject: @escaping (_ code: String, _ message: String, _ error: NSError) -> Void) {
184
+ guard let animator = getAnimator(tag: tag) else {
185
+ reject("\(LOG_TAG): setStartOffset", "Unable to find animator with tag \(tag)", NSError())
186
+ return
187
+ }
188
+
189
+ animator.setStartOffset(offset: offset.doubleValue, durationSec: durationMs.doubleValue / 1000)
190
+ resolve(tag)
191
+ }
192
+
193
+ @objc
194
+ public static func setEndOffset(tag: NSNumber, offset: NSNumber, durationMs: NSNumber, resolve: RCTPromiseResolveBlock, reject: @escaping (_ code: String, _ message: String, _ error: NSError) -> Void) {
195
+ guard let animator = getAnimator(tag: tag) else {
196
+ reject("\(LOG_TAG): setEndOffset", "Unable to find animator with tag \(tag)", NSError())
197
+ return
198
+ }
199
+
200
+ animator.setEndOffset(offset: offset.doubleValue, durationSec: durationMs.doubleValue / 1000)
201
+ resolve(tag)
202
+ }
203
+ }
204
+
205
+ // - MARK: Utils
206
+
207
+ private func buildLineString(_coordinates: NSArray) -> LineString {
208
+ let coordinates = _coordinates.map { coord in
209
+ let coord = coord as! [NSNumber]
210
+ return LocationCoordinate2D(latitude: coord[1].doubleValue, longitude: coord[0].doubleValue)
211
+ }
212
+
213
+ return .init(coordinates)
214
+ }