@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.
- package/android/src/main/java/com/rnmapbox/rnmbx/RNMBXPackage.kt +13 -2
- package/android/src/main/java/com/rnmapbox/rnmbx/components/AbstractEventEmitter.kt +13 -7
- package/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapViewManager.kt +3 -1
- package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/layers/RNMBXLayer.kt +4 -4
- package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/sources/RNMBXShapeSource.kt +23 -17
- package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/sources/RNMBXShapeSourceManager.kt +1 -2
- package/android/src/main/java/com/rnmapbox/rnmbx/shapeAnimators/AnimatableElement.kt +38 -0
- package/android/src/main/java/com/rnmapbox/rnmbx/shapeAnimators/RNMBXChangeLineOffsetsShapeAnimatorModule.kt +217 -0
- package/android/src/main/java/com/rnmapbox/rnmbx/shapeAnimators/RNMBXMovePointShapeAnimatorModule.kt +108 -0
- package/android/src/main/java/com/rnmapbox/rnmbx/shapeAnimators/ShapeAnimatorCommon.kt +142 -0
- package/android/src/main/old-arch/com/rnmapbox/rnmbx/NativeRNMBXChangeLineOffsetsShapeAnimatorModuleSpec.java +52 -0
- package/android/src/main/old-arch/com/rnmapbox/rnmbx/NativeRNMBXMovePointShapeAnimatorModuleSpec.java +2 -2
- package/ios/RNMBX/RNMBXCircleLayer.swift +48 -1
- package/ios/RNMBX/RNMBXFillExtrusionLayer.swift +47 -1
- package/ios/RNMBX/RNMBXFillLayer.swift +47 -1
- package/ios/RNMBX/RNMBXLineLayer.swift +44 -1
- package/ios/RNMBX/RNMBXLogging.swift +78 -39
- package/ios/RNMBX/RNMBXModelLayer.swift +44 -1
- package/ios/RNMBX/RNMBXRasterLayer.swift +48 -2
- package/ios/RNMBX/RNMBXShapeSource.swift +30 -17
- package/ios/RNMBX/RNMBXSkyLayer.swift +22 -1
- package/ios/RNMBX/RNMBXSymbolLayer.swift +47 -1
- package/ios/RNMBX/ShapeAnimators/AnimatableElement.swift +48 -0
- package/ios/RNMBX/ShapeAnimators/RNMBXChangeLineOffsetsShapeAnimatorModule.m +64 -0
- package/ios/RNMBX/ShapeAnimators/RNMBXChangeLineOffsetsShapeAnimatorModule.swift +214 -0
- package/ios/RNMBX/ShapeAnimators/RNMBXMovePointShapeAnimatorModule.m +5 -10
- package/ios/RNMBX/ShapeAnimators/RNMBXMovePointShapeAnimatorModule.swift +92 -24
- package/ios/RNMBX/ShapeAnimators/ShapeAnimatorCommon.swift +71 -33
- package/ios/RNMBX/ShapeAnimators/ShapeAnimatorManager.swift +3 -1
- package/ios/RNMBX/codeparts/LayerPropsCommon.codepart-swift.ejs +51 -0
- package/lib/commonjs/Mapbox.js +4 -2
- package/lib/commonjs/Mapbox.js.map +1 -1
- package/lib/commonjs/components/ShapeSource.js.map +1 -1
- package/lib/commonjs/shapeAnimators/ChangeLineOffsetsShapeAnimator.js +27 -0
- package/lib/commonjs/shapeAnimators/ChangeLineOffsetsShapeAnimator.js.map +1 -0
- package/lib/commonjs/{shape_animators → shapeAnimators}/MovePointShapeAnimator.js +4 -4
- package/lib/commonjs/shapeAnimators/MovePointShapeAnimator.js.map +1 -0
- package/lib/commonjs/shapeAnimators/ShapeAnimatorManager.js.map +1 -0
- package/lib/commonjs/shapeAnimators/index.js +2 -0
- package/lib/commonjs/shapeAnimators/index.js.map +1 -0
- package/lib/commonjs/specs/NativeRNMBXChangeLineOffsetsShapeAnimatorModule.js +10 -0
- package/lib/commonjs/specs/NativeRNMBXChangeLineOffsetsShapeAnimatorModule.js.map +1 -0
- package/lib/commonjs/specs/NativeRNMBXMovePointShapeAnimatorModule.js.map +1 -1
- package/lib/commonjs/utils/Logger.js +13 -7
- package/lib/commonjs/utils/Logger.js.map +1 -1
- package/lib/module/Mapbox.js +4 -2
- package/lib/module/Mapbox.js.map +1 -1
- package/lib/module/components/ShapeSource.js.map +1 -1
- package/lib/module/shapeAnimators/ChangeLineOffsetsShapeAnimator.js +19 -0
- package/lib/module/shapeAnimators/ChangeLineOffsetsShapeAnimator.js.map +1 -0
- package/lib/module/shapeAnimators/MovePointShapeAnimator.js +13 -0
- package/lib/module/shapeAnimators/MovePointShapeAnimator.js.map +1 -0
- package/lib/module/shapeAnimators/ShapeAnimatorManager.js.map +1 -0
- package/lib/module/shapeAnimators/index.js +2 -0
- package/lib/module/shapeAnimators/index.js.map +1 -0
- package/lib/module/specs/NativeRNMBXChangeLineOffsetsShapeAnimatorModule.js +6 -0
- package/lib/module/specs/NativeRNMBXChangeLineOffsetsShapeAnimatorModule.js.map +1 -0
- package/lib/module/specs/NativeRNMBXMovePointShapeAnimatorModule.js.map +1 -1
- package/lib/module/utils/Logger.js +13 -7
- package/lib/module/utils/Logger.js.map +1 -1
- package/lib/typescript/src/Mapbox.d.ts +3 -1
- package/lib/typescript/src/Mapbox.d.ts.map +1 -1
- package/lib/typescript/src/components/ShapeSource.d.ts +2 -1
- package/lib/typescript/src/components/ShapeSource.d.ts.map +1 -1
- package/lib/typescript/src/shapeAnimators/ChangeLineOffsetsShapeAnimator.d.ts +24 -0
- package/lib/typescript/src/shapeAnimators/ChangeLineOffsetsShapeAnimator.d.ts.map +1 -0
- package/lib/typescript/src/shapeAnimators/MovePointShapeAnimator.d.ts +11 -0
- package/lib/typescript/src/shapeAnimators/MovePointShapeAnimator.d.ts.map +1 -0
- package/lib/typescript/src/shapeAnimators/ShapeAnimatorManager.d.ts.map +1 -0
- package/lib/typescript/src/shapeAnimators/index.d.ts +4 -0
- package/lib/typescript/src/shapeAnimators/index.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeRNMBXChangeLineOffsetsShapeAnimatorModule.d.ts +13 -0
- package/lib/typescript/src/specs/NativeRNMBXChangeLineOffsetsShapeAnimatorModule.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeRNMBXMovePointShapeAnimatorModule.d.ts +2 -2
- package/lib/typescript/src/specs/NativeRNMBXMovePointShapeAnimatorModule.d.ts.map +1 -1
- package/lib/typescript/src/utils/Logger.d.ts +2 -2
- package/lib/typescript/src/utils/Logger.d.ts.map +1 -1
- package/package.json +1 -1
- package/setup-jest.js +5 -0
- package/src/Mapbox.ts +3 -1
- package/src/components/ShapeSource.tsx +3 -1
- package/src/shapeAnimators/ChangeLineOffsetsShapeAnimator.ts +57 -0
- package/src/shapeAnimators/MovePointShapeAnimator.ts +27 -0
- package/src/shapeAnimators/index.ts +3 -0
- package/src/specs/NativeRNMBXChangeLineOffsetsShapeAnimatorModule.ts +37 -0
- package/src/specs/NativeRNMBXMovePointShapeAnimatorModule.ts +6 -2
- package/src/utils/Logger.ts +17 -9
- package/android/src/main/java/com/rnmapbox/rnmbx/shape_animators/RNMBXMovePointShapeAnimatorModule.kt +0 -55
- package/android/src/main/java/com/rnmapbox/rnmbx/shape_animators/ShapeAnimatorCommon.kt +0 -110
- package/lib/commonjs/shape_animators/MovePointShapeAnimator.js.map +0 -1
- package/lib/commonjs/shape_animators/ShapeAnimatorManager.js.map +0 -1
- package/lib/module/shape_animators/MovePointShapeAnimator.js +0 -13
- package/lib/module/shape_animators/MovePointShapeAnimator.js.map +0 -1
- package/lib/module/shape_animators/ShapeAnimatorManager.js.map +0 -1
- package/lib/typescript/src/shape_animators/MovePointShapeAnimator.d.ts +0 -7
- package/lib/typescript/src/shape_animators/MovePointShapeAnimator.d.ts.map +0 -1
- package/lib/typescript/src/shape_animators/ShapeAnimatorManager.d.ts.map +0 -1
- package/src/shape_animators/MovePointShapeAnimator.ts +0 -18
- /package/lib/commonjs/{shape_animators → shapeAnimators}/ShapeAnimatorManager.js +0 -0
- /package/lib/module/{shape_animators → shapeAnimators}/ShapeAnimatorManager.js +0 -0
- /package/lib/typescript/src/{shape_animators → shapeAnimators}/ShapeAnimatorManager.d.ts +0 -0
- /package/src/{shape_animators → shapeAnimators}/ShapeAnimatorManager.tsx +0 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
package com.rnmapbox.rnmbx.shapeAnimators
|
|
2
|
+
|
|
3
|
+
import android.util.Log
|
|
4
|
+
import com.facebook.react.bridge.UiThreadUtil.runOnUiThread
|
|
5
|
+
import com.mapbox.geojson.FeatureCollection
|
|
6
|
+
import com.mapbox.geojson.GeoJson
|
|
7
|
+
import com.rnmapbox.rnmbx.utils.Logger
|
|
8
|
+
import org.json.JSONObject
|
|
9
|
+
import java.util.Date
|
|
10
|
+
import java.util.Timer
|
|
11
|
+
import java.util.TimerTask
|
|
12
|
+
|
|
13
|
+
typealias Tag = Long
|
|
14
|
+
|
|
15
|
+
interface ShapeAnimationConsumer {
|
|
16
|
+
fun shapeUpdated(geoJson: GeoJson)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
abstract class ShapeAnimator(val tag: Tag) {
|
|
20
|
+
abstract fun getShape(): GeoJson
|
|
21
|
+
abstract fun getAnimatedShape(animatorAgeSec: Double): GeoJson
|
|
22
|
+
abstract fun subscribe(consumer: ShapeAnimationConsumer)
|
|
23
|
+
abstract fun unsubscribe(consumer: ShapeAnimationConsumer)
|
|
24
|
+
abstract fun refresh()
|
|
25
|
+
abstract fun start()
|
|
26
|
+
abstract fun stop()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private const val LOG_TAG = "RNMBXShapeAnimator"
|
|
30
|
+
|
|
31
|
+
abstract class ShapeAnimatorCommon(tag: Tag): ShapeAnimator(tag) {
|
|
32
|
+
val emptyGeoJsonObj: FeatureCollection = FeatureCollection.fromFeatures(listOf())
|
|
33
|
+
|
|
34
|
+
private var timer: Timer? = null
|
|
35
|
+
private var startedAt = Date()
|
|
36
|
+
|
|
37
|
+
private val fps = 30.0
|
|
38
|
+
private val period = 1.0 / fps
|
|
39
|
+
|
|
40
|
+
/** The number of seconds the animator has been running continuously. */
|
|
41
|
+
fun getAnimatorAgeSec(): Double {
|
|
42
|
+
val now = Date()
|
|
43
|
+
return (now.time - startedAt.time).toDouble() / 1000
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// region subscribers
|
|
47
|
+
private var subscribers = mutableListOf<ShapeAnimationConsumer>()
|
|
48
|
+
|
|
49
|
+
override fun subscribe(consumer: ShapeAnimationConsumer) {
|
|
50
|
+
if (subscribers.contains(consumer)) {
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
subscribers.add(consumer)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
override fun unsubscribe(consumer: ShapeAnimationConsumer) {
|
|
58
|
+
subscribers.remove(consumer)
|
|
59
|
+
if (subscribers.isEmpty()) {
|
|
60
|
+
stop()
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// endregion
|
|
64
|
+
|
|
65
|
+
override fun refresh() {
|
|
66
|
+
val timestamp = getAnimatorAgeSec()
|
|
67
|
+
// Log.d(
|
|
68
|
+
// LOG_TAG,
|
|
69
|
+
// "Refreshing animator for tag $tag (timestamp: $timestamp, subscribers: ${subscribers.count()})"
|
|
70
|
+
// )
|
|
71
|
+
|
|
72
|
+
val shape = getAnimatedShape(timestamp)
|
|
73
|
+
runOnUiThread {
|
|
74
|
+
subscribers.forEach {
|
|
75
|
+
it.shapeUpdated(shape)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
override fun start() {
|
|
81
|
+
if (timer != null) {
|
|
82
|
+
Log.d(LOG_TAG, "Timer for animator $tag is already running (subscribers: ${subscribers.count()})")
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
Log.d(LOG_TAG, "Started timer for animator $tag (subscribers: ${subscribers.count()})")
|
|
87
|
+
|
|
88
|
+
startedAt = Date()
|
|
89
|
+
timer = Timer()
|
|
90
|
+
timer?.schedule(object : TimerTask() {
|
|
91
|
+
override fun run() {
|
|
92
|
+
refresh()
|
|
93
|
+
}
|
|
94
|
+
}, 0, (period * 1000).toLong())
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
override fun stop() {
|
|
98
|
+
if (timer == null) {
|
|
99
|
+
Log.d(LOG_TAG, "Timer for animator $tag is already stopped (subscribers: ${subscribers.count()})")
|
|
100
|
+
return
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
Log.d(LOG_TAG,"Stopped timer for animator $tag (subscribers: ${subscribers.count()})")
|
|
104
|
+
|
|
105
|
+
timer?.cancel()
|
|
106
|
+
timer = null
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
override fun getShape(): GeoJson {
|
|
110
|
+
return getAnimatedShape(getAnimatorAgeSec())
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
class ShapeAnimatorManager {
|
|
115
|
+
private val animators = hashMapOf<Tag, ShapeAnimator>();
|
|
116
|
+
|
|
117
|
+
fun add(animator: ShapeAnimator) {
|
|
118
|
+
animators[animator.tag] = animator
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
fun isShapeAnimatorTag(shape: String): Boolean {
|
|
122
|
+
return shape.startsWith("{\"__nativeTag\":")
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
fun get(tag: String): ShapeAnimator? {
|
|
126
|
+
return if (isShapeAnimatorTag(tag)) {
|
|
127
|
+
val obj = JSONObject(tag)
|
|
128
|
+
val _tag = obj.getLong("__nativeTag")
|
|
129
|
+
get(_tag);
|
|
130
|
+
} else {
|
|
131
|
+
null
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
fun get(tag: Tag): ShapeAnimator? {
|
|
136
|
+
val result = animators[tag]
|
|
137
|
+
if (result == null) {
|
|
138
|
+
Logger.e(LOG_TAG, "Shape animator for tag $tag was not found")
|
|
139
|
+
}
|
|
140
|
+
return result
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateModuleJavaSpec.js
|
|
9
|
+
*
|
|
10
|
+
* @nolint
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
package com.rnmapbox.rnmbx;
|
|
14
|
+
|
|
15
|
+
import com.facebook.proguard.annotations.DoNotStrip;
|
|
16
|
+
import com.facebook.react.bridge.Promise;
|
|
17
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
18
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
19
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
20
|
+
import com.facebook.react.bridge.ReactModuleWithSpec;
|
|
21
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
22
|
+
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
|
|
23
|
+
import javax.annotation.Nonnull;
|
|
24
|
+
|
|
25
|
+
public abstract class NativeRNMBXChangeLineOffsetsShapeAnimatorModuleSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
|
|
26
|
+
public static final String NAME = "RNMBXChangeLineOffsetsShapeAnimatorModule";
|
|
27
|
+
|
|
28
|
+
public NativeRNMBXChangeLineOffsetsShapeAnimatorModuleSpec(ReactApplicationContext reactContext) {
|
|
29
|
+
super(reactContext);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@Override
|
|
33
|
+
public @Nonnull String getName() {
|
|
34
|
+
return NAME;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@ReactMethod
|
|
38
|
+
@DoNotStrip
|
|
39
|
+
public abstract void create(double tag, ReadableArray coordinates, double startOffset, double endOffset, Promise promise);
|
|
40
|
+
|
|
41
|
+
@ReactMethod
|
|
42
|
+
@DoNotStrip
|
|
43
|
+
public abstract void setLineString(double tag, ReadableArray coordinates, double startOffset, double endOffset, Promise promise);
|
|
44
|
+
|
|
45
|
+
@ReactMethod
|
|
46
|
+
@DoNotStrip
|
|
47
|
+
public abstract void setStartOffset(double tag, double offset, double duration, Promise promise);
|
|
48
|
+
|
|
49
|
+
@ReactMethod
|
|
50
|
+
@DoNotStrip
|
|
51
|
+
public abstract void setEndOffset(double tag, double offset, double duration, Promise promise);
|
|
52
|
+
}
|
|
@@ -36,9 +36,9 @@ public abstract class NativeRNMBXMovePointShapeAnimatorModuleSpec extends ReactC
|
|
|
36
36
|
|
|
37
37
|
@ReactMethod
|
|
38
38
|
@DoNotStrip
|
|
39
|
-
public abstract void create(double tag, ReadableArray
|
|
39
|
+
public abstract void create(double tag, ReadableArray coordinate, Promise promise);
|
|
40
40
|
|
|
41
41
|
@ReactMethod
|
|
42
42
|
@DoNotStrip
|
|
43
|
-
public abstract void
|
|
43
|
+
public abstract void moveTo(double tag, ReadableArray coordinate, double duration, Promise promise);
|
|
44
44
|
}
|
|
@@ -20,14 +20,61 @@ public class RNMBXCircleLayer: RNMBXVectorLayer {
|
|
|
20
20
|
override func layerType() -> Layer.Type {
|
|
21
21
|
return LayerType.self
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
// @{codepart-replace-start(LayerPropsCommon.codepart-swift.ejs,{layerType:"Circle"})}
|
|
26
|
+
func setCommonOptions(_ layer: inout CircleLayer) -> Bool {
|
|
27
|
+
var changed = false
|
|
28
|
+
|
|
29
|
+
#if RNMBX_11
|
|
30
|
+
if let sourceLayerID = sourceLayerID {
|
|
31
|
+
layer.sourceLayer = sourceLayerID
|
|
32
|
+
changed = true
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if let sourceID = sourceID {
|
|
36
|
+
if !(existingLayer && sourceID == DEFAULT_SOURCE_ID) && hasSource() {
|
|
37
|
+
layer.source = sourceID
|
|
38
|
+
changed = true
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if let filter = filter, filter.count > 0 {
|
|
43
|
+
do {
|
|
44
|
+
let data = try JSONSerialization.data(withJSONObject: filter, options: .prettyPrinted)
|
|
45
|
+
let decodedExpression = try JSONDecoder().decode(Expression.self, from: data)
|
|
46
|
+
layer.filter = decodedExpression
|
|
47
|
+
changed = true
|
|
48
|
+
} catch {
|
|
49
|
+
Logger.log(level: .error, message: "parsing filters failed for layer \(optional: id): \(error.localizedDescription)")
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
#endif
|
|
53
|
+
|
|
54
|
+
return changed
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
override func setOptions(_ layer: inout Layer) {
|
|
58
|
+
if var actualLayer = layer as? LayerType {
|
|
59
|
+
if self.setCommonOptions(&actualLayer) {
|
|
60
|
+
layer = actualLayer
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
Logger.log(level: .error, message: "Expected layer type to be Circle but was \(type(of: layer))")
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
24
67
|
override func apply(style : Style) throws {
|
|
25
68
|
try style.updateLayer(withId: id, type: LayerType.self) { (layer : inout CircleLayer) in
|
|
69
|
+
if self.styleLayer != nil {
|
|
70
|
+
self.setOptions(&self.styleLayer!)
|
|
71
|
+
}
|
|
26
72
|
if let styleLayer = self.styleLayer as? LayerType {
|
|
27
73
|
layer = styleLayer
|
|
28
74
|
}
|
|
29
75
|
}
|
|
30
76
|
}
|
|
77
|
+
// @{codepart-replace-end}
|
|
31
78
|
|
|
32
79
|
override func addStyles() {
|
|
33
80
|
if let style : Style = self.style,
|
|
@@ -19,14 +19,60 @@ public class RNMBXFillExtrusionLayer: RNMBXVectorLayer {
|
|
|
19
19
|
override func layerType() -> Layer.Type {
|
|
20
20
|
return LayerType.self
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
|
|
23
|
+
// @{codepart-replace-start(LayerPropsCommon.codepart-swift.ejs,{layerType:"FillExtrusion"})}
|
|
24
|
+
func setCommonOptions(_ layer: inout FillExtrusionLayer) -> 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 FillExtrusion 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 FillExtrusionLayer) in
|
|
67
|
+
if self.styleLayer != nil {
|
|
68
|
+
self.setOptions(&self.styleLayer!)
|
|
69
|
+
}
|
|
25
70
|
if let styleLayer = self.styleLayer as? LayerType {
|
|
26
71
|
layer = styleLayer
|
|
27
72
|
}
|
|
28
73
|
}
|
|
29
74
|
}
|
|
75
|
+
// @{codepart-replace-end}
|
|
30
76
|
|
|
31
77
|
override func addStyles() {
|
|
32
78
|
if let style : Style = self.style,
|
|
@@ -20,14 +20,60 @@ public class RNMBXFillLayer: RNMBXVectorLayer {
|
|
|
20
20
|
override func layerType() -> Layer.Type {
|
|
21
21
|
return LayerType.self
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
|
|
24
|
+
// @{codepart-replace-start(LayerPropsCommon.codepart-swift.ejs,{layerType:"Fill"})}
|
|
25
|
+
func setCommonOptions(_ layer: inout FillLayer) -> 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 Fill 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 FillLayer) in
|
|
68
|
+
if self.styleLayer != nil {
|
|
69
|
+
self.setOptions(&self.styleLayer!)
|
|
70
|
+
}
|
|
26
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,
|
|
@@ -20,16 +20,59 @@ public class RNMBXLineLayer: RNMBXVectorLayer {
|
|
|
20
20
|
return LayerType.self
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
// @{codepart-replace-start(LayerPropsCommon.codepart-swift.ejs,{layerType:"Line"})}
|
|
24
|
+
func setCommonOptions(_ layer: inout LineLayer) -> 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 Line 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 LineLayer) in
|
|
25
67
|
if self.styleLayer != nil {
|
|
26
68
|
self.setOptions(&self.styleLayer!)
|
|
27
69
|
}
|
|
28
|
-
if let styleLayer = self.styleLayer as?
|
|
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 {
|
|
@@ -12,7 +12,7 @@ public enum RNMBXError: Error, LocalizedError {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
public class Logger {
|
|
15
|
-
public enum LogLevel
|
|
15
|
+
public enum LogLevel: String, Comparable {
|
|
16
16
|
public static func < (lhs: Logger.LogLevel, rhs: Logger.LogLevel) -> Bool {
|
|
17
17
|
return lhs.intValue < rhs.intValue
|
|
18
18
|
}
|
|
@@ -42,79 +42,119 @@ public class Logger {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
static let sharedInstance = Logger()
|
|
45
|
+
internal static let sharedInstance = Logger()
|
|
46
46
|
|
|
47
|
-
var level: LogLevel = .info
|
|
48
|
-
var handler
|
|
47
|
+
fileprivate var level: LogLevel = .info
|
|
48
|
+
fileprivate var handler: (LogLevel, String) -> Void = { (level, message) in
|
|
49
49
|
fatalError("Handler not yet installed")
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
func log(level: LogLevel, message: String) {
|
|
53
|
-
|
|
52
|
+
public func log(level: LogLevel, tag: String, message: String) {
|
|
53
|
+
log(level: level, message: "\(tag) | \(message)")
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@available(*, deprecated, message: "Use log(level:tag:message:) instead.")
|
|
57
|
+
public func log(level: LogLevel, message: String) {
|
|
58
|
+
print("\(level) | \(message)")
|
|
54
59
|
if self.level <= level {
|
|
55
60
|
handler(level, message)
|
|
56
61
|
}
|
|
57
62
|
}
|
|
58
63
|
|
|
59
|
-
public static func log(level: LogLevel, message: String) {
|
|
60
|
-
|
|
64
|
+
public static func log(level: LogLevel, tag: String, message: String, error: Error? = nil) {
|
|
65
|
+
if let error = error {
|
|
66
|
+
sharedInstance.log(level: level, message: "\(tag) | \(message), \(error.localizedDescription), \(error)")
|
|
67
|
+
} else {
|
|
68
|
+
sharedInstance.log(level: level, message: "\(tag) | \(message)")
|
|
69
|
+
}
|
|
61
70
|
}
|
|
62
71
|
|
|
63
|
-
|
|
64
|
-
|
|
72
|
+
@available(*, deprecated, message: "Use log(level:tag:message:error:) instead.")
|
|
73
|
+
public static func log(level: LogLevel, message: String, error: Error? = nil) {
|
|
74
|
+
if let error = error {
|
|
75
|
+
sharedInstance.log(level: level, message: "\(message), \(error.localizedDescription), \(error)")
|
|
76
|
+
} else {
|
|
77
|
+
sharedInstance.log(level: level, message: message)
|
|
78
|
+
}
|
|
65
79
|
}
|
|
66
|
-
|
|
67
|
-
static func error(_ message: String) {
|
|
80
|
+
|
|
81
|
+
public static func error(_ message: String) {
|
|
68
82
|
log(level: .error, message: message)
|
|
69
83
|
}
|
|
70
84
|
|
|
71
|
-
static func assert(_ message: String) {
|
|
85
|
+
public static func assert(_ message: String) {
|
|
72
86
|
log(level: .error, message: "Assertion failure: \(message)")
|
|
73
87
|
}
|
|
74
88
|
}
|
|
75
89
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
90
|
+
/// Logs tag and message if `fn` throws and returns nil
|
|
91
|
+
public func logged<T>(_ tag: String, _ msg: String, info: (() -> String)? = nil, level: Logger.LogLevel = .error, rejecter: RCTPromiseRejectBlock? = nil, fn: () throws -> T) -> T? {
|
|
92
|
+
logged(
|
|
93
|
+
"\(tag) | \(msg)",
|
|
94
|
+
info: info,
|
|
95
|
+
level: level,
|
|
96
|
+
rejecter: rejecter,
|
|
97
|
+
fn: fn
|
|
98
|
+
)
|
|
84
99
|
}
|
|
85
100
|
|
|
86
|
-
///
|
|
87
|
-
func logged<T>(_ msg: String, info: (() -> String)? = nil, level: Logger.LogLevel = .error, rejecter: RCTPromiseRejectBlock? = nil, fn: () -> T
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
101
|
+
/// Logs tag and message if `fn` returns nil
|
|
102
|
+
public func logged<T>(_ tag: String, _ msg: String, info: (() -> String)? = nil, level: Logger.LogLevel = .error, rejecter: RCTPromiseRejectBlock? = nil, fn: () -> T) -> T? {
|
|
103
|
+
logged(
|
|
104
|
+
"\(tag) | \(msg)",
|
|
105
|
+
info: info,
|
|
106
|
+
level: level,
|
|
107
|
+
rejecter: rejecter,
|
|
108
|
+
fn: fn
|
|
109
|
+
)
|
|
96
110
|
}
|
|
97
111
|
|
|
98
|
-
|
|
99
|
-
func logged<T>(_ msg: String, info: (() -> String)? = nil, level: Logger.LogLevel = .error, rejecter: RCTPromiseRejectBlock? = nil, fn
|
|
112
|
+
@available(*, deprecated, message: "Use logged(tag:msg:info:level:rejecter:fn:) instead.")
|
|
113
|
+
public func logged<T>(_ msg: String, info: (() -> String)? = nil, level: Logger.LogLevel = .error, rejecter: RCTPromiseRejectBlock? = nil, fn: () throws -> T) -> T? {
|
|
100
114
|
do {
|
|
101
115
|
return try fn()
|
|
102
116
|
} catch {
|
|
103
|
-
|
|
104
|
-
|
|
117
|
+
let _info = info?() ?? ""
|
|
118
|
+
let _error = errorMessage(error)
|
|
119
|
+
Logger.log(level: level, message: "\(msg) \(_info) \(_error)")
|
|
120
|
+
rejecter?(msg, "\(_info) \(_error)", error)
|
|
121
|
+
return nil
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@available(*, deprecated, message: "Use logged(tag:msg:info:level:rejecter:fn:) instead.")
|
|
126
|
+
public func logged<T>(_ msg: String, info: (() -> String)? = nil, level: Logger.LogLevel = .error, rejecter: RCTPromiseRejectBlock? = nil, fn: () -> T?) ->T? {
|
|
127
|
+
if let ret = fn() {
|
|
128
|
+
return ret
|
|
129
|
+
} else {
|
|
130
|
+
let _info = info?() ?? ""
|
|
131
|
+
Logger.log(level: level, message: "\(msg) \(_info)")
|
|
132
|
+
rejecter?(msg, _info, NSError(domain: "is null", code: 0))
|
|
105
133
|
return nil
|
|
106
134
|
}
|
|
107
135
|
}
|
|
108
136
|
|
|
109
|
-
|
|
137
|
+
@available(*, deprecated, message: "Use logged(tag:msg:info:level:rejecter:fn:) instead.")
|
|
138
|
+
public func logged<T>(_ msg: String, info: (() -> String)? = nil, errorResult: (Error) -> T, level: Logger.LogLevel = .error, fn: () throws -> T) -> T {
|
|
110
139
|
do {
|
|
111
140
|
return try fn()
|
|
112
141
|
} catch {
|
|
113
|
-
|
|
142
|
+
let _info = info?() ?? ""
|
|
143
|
+
Logger.log(level: level, message: "\(msg) \(_info) \(error.localizedDescription)")
|
|
114
144
|
return errorResult(error)
|
|
115
145
|
}
|
|
116
146
|
}
|
|
117
147
|
|
|
148
|
+
private func errorMessage(_ error: Error) -> String {
|
|
149
|
+
if case DecodingError.typeMismatch(let _, let context) = error {
|
|
150
|
+
return "\(error.localizedDescription) \(context.codingPath) \(context.debugDescription)"
|
|
151
|
+
} else if let mapError = error as? MapError {
|
|
152
|
+
return "MapError: \(mapError.errorDescription)"
|
|
153
|
+
} else {
|
|
154
|
+
return "\(error.localizedDescription)"
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
118
158
|
@objc(RNMBXLogger)
|
|
119
159
|
public class RNMBXLogger : NSObject {
|
|
120
160
|
@objc
|
|
@@ -165,8 +205,7 @@ class RNMBXLogging: RCTEventEmitter {
|
|
|
165
205
|
}
|
|
166
206
|
|
|
167
207
|
@objc
|
|
168
|
-
override func supportedEvents() -> [String]
|
|
169
|
-
{
|
|
208
|
+
override func supportedEvents() -> [String] {
|
|
170
209
|
return ["LogEvent"];
|
|
171
210
|
}
|
|
172
211
|
}
|