@rnmapbox/maps 10.0.0-beta.41 → 10.0.0-beta.43
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/.eslintrc.js +2 -1
- package/.github/workflows/ios-actions.yml +1 -1
- package/android/install.md +20 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/RCTMGLPackage.java +2 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.kt +22 -31
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/RCTMGLStyleFactory.java +26 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/atmosphere/RCTMGLAtmosphere.kt +59 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/atmosphere/RCTMGLAtmosphereManager.kt +30 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/terrain/RCTMGLTerrain.kt +32 -27
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/terrain/RCTMGLTerrainManager.kt +5 -11
- package/docs/Annotations.md +4 -3
- package/docs/Camera.md +1 -1
- package/docs/HeadingIndicator.md +1 -1
- package/docs/MapView.md +2 -2
- package/docs/SymbolLayer.md +4 -3
- package/docs/Terrain.md +64 -9
- package/docs/docs.json +66 -53
- package/index.d.ts +13 -80
- package/ios/RCTMGL-v10/RCTMGLCamera.swift +28 -26
- package/ios/RCTMGL-v10/RCTMGLImages.swift +1 -99
- package/ios/RCTMGL-v10/RCTMGLLogging.swift +8 -0
- package/ios/RCTMGL-v10/RCTMGLMapView.swift +35 -39
- package/ios/RCTMGL-v10/RCTMGLSingletonLayer.swift +7 -1
- package/ios/RCTMGL-v10/RCTMGLStyle.swift +34 -0
- package/ios/RCTMGL-v10/RCTMGLTerrain.swift +56 -63
- package/ios/RCTMGL-v10/RCTMGLTerrainManager.m +2 -3
- package/javascript/components/AbstractLayer.tsx +72 -0
- package/javascript/components/BackgroundLayer.js +1 -1
- package/javascript/components/Camera.tsx +17 -1
- package/javascript/components/CircleLayer.js +1 -1
- package/javascript/components/FillExtrusionLayer.js +1 -1
- package/javascript/components/FillLayer.js +1 -1
- package/javascript/components/{HeadingIndicator.js → HeadingIndicator.tsx} +5 -6
- package/javascript/components/HeatmapLayer.js +1 -1
- package/javascript/components/LineLayer.js +1 -1
- package/javascript/components/MapView.js +8 -12
- package/javascript/components/RasterLayer.js +1 -1
- package/javascript/components/SkyLayer.js +1 -1
- package/javascript/components/SymbolLayer.tsx +113 -0
- package/javascript/components/Terrain.tsx +52 -0
- package/javascript/components/UserLocation.js +1 -1
- package/javascript/global.d.ts +4 -0
- package/javascript/index.js +8 -4
- package/javascript/types/index.ts +0 -14
- package/javascript/utils/MapboxStyles.ts +177 -52
- package/javascript/utils/StyleValue.ts +8 -6
- package/javascript/utils/deprecation.ts +39 -0
- package/javascript/utils/{filterUtils.js → filterUtils.tsx} +1 -1
- package/javascript/utils/styleMap.ts +26 -0
- package/package.json +6 -6
- package/scripts/autogenHelpers/DocJSONBuilder.js +2 -3
- package/scripts/autogenHelpers/globals.js +20 -7
- package/scripts/autogenerate.js +13 -0
- package/scripts/templates/MapboxStyles.ts.ejs +8 -3
- package/scripts/templates/RCTMGLStyleFactoryv10.java.ejs +1 -0
- package/.eslintignore +0 -1
- package/javascript/components/AbstractLayer.js +0 -46
- package/javascript/components/SymbolLayer.js +0 -120
- package/javascript/components/Terrain.js +0 -56
- package/javascript/utils/deprecation.js +0 -24
|
@@ -22,8 +22,8 @@ open class RCTMGLMapView : MapView {
|
|
|
22
22
|
var onStyleLoadedComponents: [RCTMGLMapComponent] = []
|
|
23
23
|
|
|
24
24
|
private var isPendingInitialLayout = true
|
|
25
|
+
private var wasGestureActive = false
|
|
25
26
|
private var isGestureActive = false
|
|
26
|
-
private var isAnimatingFromGesture = false
|
|
27
27
|
|
|
28
28
|
var layerWaiters : [String:[(String) -> Void]] = [:]
|
|
29
29
|
|
|
@@ -274,8 +274,9 @@ open class RCTMGLMapView : MapView {
|
|
|
274
274
|
extension RCTMGLMapView {
|
|
275
275
|
@objc func setReactOnMapChange(_ value: @escaping RCTBubblingEventBlock) {
|
|
276
276
|
self.reactOnMapChange = value
|
|
277
|
-
|
|
278
|
-
self.mapView.mapboxMap.onEvery(.cameraChanged, handler: { cameraEvent in
|
|
277
|
+
|
|
278
|
+
self.mapView.mapboxMap.onEvery(event: .cameraChanged, handler: { cameraEvent in
|
|
279
|
+
self.wasGestureActive = self.isGestureActive
|
|
279
280
|
if self.handleMapChangedEvents.contains(.regionIsChanging) {
|
|
280
281
|
let event = RCTMGLEvent(type:.regionIsChanging, payload: self.buildRegionObject());
|
|
281
282
|
self.fireEvent(event: event, callback: self.reactOnMapChange)
|
|
@@ -285,7 +286,7 @@ extension RCTMGLMapView {
|
|
|
285
286
|
}
|
|
286
287
|
})
|
|
287
288
|
|
|
288
|
-
self.mapView.mapboxMap.onEvery(.mapIdle, handler: { cameraEvent in
|
|
289
|
+
self.mapView.mapboxMap.onEvery(event: .mapIdle, handler: { cameraEvent in
|
|
289
290
|
if self.handleMapChangedEvents.contains(.regionDidChange) {
|
|
290
291
|
let event = RCTMGLEvent(type:.regionDidChange, payload: self.buildRegionObject());
|
|
291
292
|
self.fireEvent(event: event, callback: self.reactOnMapChange)
|
|
@@ -293,6 +294,8 @@ extension RCTMGLMapView {
|
|
|
293
294
|
let event = RCTMGLEvent(type:.mapIdle, payload: self.buildStateObject());
|
|
294
295
|
self.fireEvent(event: event, callback: self.reactOnMapChange)
|
|
295
296
|
}
|
|
297
|
+
|
|
298
|
+
self.wasGestureActive = false
|
|
296
299
|
})
|
|
297
300
|
}
|
|
298
301
|
|
|
@@ -324,8 +327,7 @@ extension RCTMGLMapView {
|
|
|
324
327
|
"pitch": Double(mapView.cameraState.pitch),
|
|
325
328
|
],
|
|
326
329
|
"gestures": [
|
|
327
|
-
"isGestureActive":
|
|
328
|
-
"isAnimatingFromGesture": isAnimatingFromGesture
|
|
330
|
+
"isGestureActive": wasGestureActive
|
|
329
331
|
]
|
|
330
332
|
]
|
|
331
333
|
}
|
|
@@ -347,8 +349,7 @@ extension RCTMGLMapView {
|
|
|
347
349
|
"bearing": .number(mapView.cameraState.bearing),
|
|
348
350
|
"pitch": .number(mapView.cameraState.pitch),
|
|
349
351
|
"visibleBounds": .array(boundsArray),
|
|
350
|
-
"isUserInteraction": .boolean(
|
|
351
|
-
"isAnimatingFromUserInteraction": .boolean(isAnimatingFromGesture),
|
|
352
|
+
"isUserInteraction": .boolean(wasGestureActive),
|
|
352
353
|
]
|
|
353
354
|
return logged("buildRegionObject", errorResult: { ["error":["toJSON":$0.localizedDescription]] }) {
|
|
354
355
|
try result.toJSON()
|
|
@@ -356,50 +357,48 @@ extension RCTMGLMapView {
|
|
|
356
357
|
}
|
|
357
358
|
|
|
358
359
|
public func setupEvents() {
|
|
359
|
-
self.mapboxMap.onEvery(.mapLoadingError, handler: {(event) in
|
|
360
|
-
if let
|
|
360
|
+
self.mapboxMap.onEvery(event: .mapLoadingError, handler: {(event) in
|
|
361
|
+
if let message = event.payload.error.errorDescription {
|
|
361
362
|
Logger.log(level: .error, message: "MapLoad error \(message)")
|
|
362
363
|
} else {
|
|
363
364
|
Logger.log(level: .error, message: "MapLoad error \(event)")
|
|
364
365
|
}
|
|
365
366
|
})
|
|
366
367
|
|
|
367
|
-
self.mapboxMap.onEvery(.styleImageMissing) { (event) in
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
return
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
self.images.forEach {
|
|
378
|
-
$0.sendImageMissingEvent(imageName: imageName, event: event)
|
|
379
|
-
}
|
|
368
|
+
self.mapboxMap.onEvery(event: .styleImageMissing) { (event) in
|
|
369
|
+
let imageName = event.payload.id
|
|
370
|
+
|
|
371
|
+
self.images.forEach {
|
|
372
|
+
if $0.addMissingImageToStyle(style: self.mapboxMap.style, imageName: imageName) {
|
|
373
|
+
return
|
|
380
374
|
}
|
|
381
375
|
}
|
|
376
|
+
|
|
377
|
+
self.images.forEach {
|
|
378
|
+
$0.sendImageMissingEvent(imageName: imageName, payload: event.payload)
|
|
379
|
+
}
|
|
382
380
|
}
|
|
383
381
|
|
|
384
|
-
self.mapboxMap.onEvery(.renderFrameFinished, handler: { (event) in
|
|
382
|
+
self.mapboxMap.onEvery(event: .renderFrameFinished, handler: { (event) in
|
|
385
383
|
var type = RCTMGLEvent.EventType.didFinishRendering
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
if let renderMode = data["render-mode"], let renderMode = renderMode as? String, renderMode == "full" {
|
|
389
|
-
type = .didFinishRenderingFully
|
|
390
|
-
}
|
|
391
|
-
payload = data
|
|
384
|
+
if event.payload.renderMode == .full {
|
|
385
|
+
type = .didFinishRenderingFully
|
|
392
386
|
}
|
|
387
|
+
let payload : [String:Any] = [
|
|
388
|
+
"renderMode": event.payload.renderMode.rawValue,
|
|
389
|
+
"needsRepaint": event.payload.needsRepaint,
|
|
390
|
+
"placementChanged": event.payload.placementChanged
|
|
391
|
+
]
|
|
393
392
|
let event = RCTMGLEvent(type: type, payload: payload);
|
|
394
393
|
self.fireEvent(event: event, callback: self.reactOnMapChange)
|
|
395
394
|
})
|
|
396
395
|
|
|
397
|
-
self.mapboxMap.onNext(.mapLoaded, handler: { (event) in
|
|
396
|
+
self.mapboxMap.onNext(event: .mapLoaded, handler: { (event) in
|
|
398
397
|
let event = RCTMGLEvent(type:.didFinishLoadingMap, payload: nil);
|
|
399
398
|
self.fireEvent(event: event, callback: self.reactOnMapChange)
|
|
400
399
|
})
|
|
401
400
|
|
|
402
|
-
self.mapboxMap.onEvery(.styleLoaded, handler: { (event) in
|
|
401
|
+
self.mapboxMap.onEvery(event: .styleLoaded, handler: { (event) in
|
|
403
402
|
self.onStyleLoadedComponents.forEach { (component) in
|
|
404
403
|
component.addToMap(self, style: self.mapboxMap.style)
|
|
405
404
|
}
|
|
@@ -589,21 +588,19 @@ extension RCTMGLMapView: GestureManagerDelegate {
|
|
|
589
588
|
}
|
|
590
589
|
}
|
|
591
590
|
}
|
|
592
|
-
|
|
591
|
+
|
|
593
592
|
public func gestureManager(_ gestureManager: GestureManager, didBegin gestureType: GestureType) {
|
|
594
593
|
isGestureActive = true
|
|
595
594
|
}
|
|
596
595
|
|
|
597
596
|
public func gestureManager(_ gestureManager: GestureManager, didEnd gestureType: GestureType, willAnimate: Bool) {
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
isAnimatingFromGesture = true
|
|
597
|
+
if !willAnimate {
|
|
598
|
+
isGestureActive = false;
|
|
601
599
|
}
|
|
602
600
|
}
|
|
603
601
|
|
|
604
602
|
public func gestureManager(_ gestureManager: GestureManager, didEndAnimatingFor gestureType: GestureType) {
|
|
605
|
-
isGestureActive = false
|
|
606
|
-
isAnimatingFromGesture = false
|
|
603
|
+
isGestureActive = false;
|
|
607
604
|
}
|
|
608
605
|
}
|
|
609
606
|
|
|
@@ -922,4 +919,3 @@ class PointAnnotationManager : AnnotationInteractionDelegate {
|
|
|
922
919
|
}
|
|
923
920
|
}
|
|
924
921
|
}
|
|
925
|
-
|
|
@@ -15,8 +15,14 @@ class RCTMGLSingletonLayer : UIView {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/// apply style updates to our copy and copy the changes to the map style
|
|
18
19
|
func addStylesAndUpdate() {
|
|
19
20
|
addStyles()
|
|
21
|
+
update()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/// apply the changes made to our copy to the map style
|
|
25
|
+
func update() {
|
|
20
26
|
if let style = style,
|
|
21
27
|
let map = map {
|
|
22
28
|
self.update(map, style)
|
|
@@ -38,4 +44,4 @@ class RCTMGLSingletonLayer : UIView {
|
|
|
38
44
|
func apply(style: Style) throws {
|
|
39
45
|
fatalError("Subclasses should overrride")
|
|
40
46
|
}
|
|
41
|
-
}
|
|
47
|
+
}
|
|
@@ -801,6 +801,29 @@ func atmosphereLayer(layer: inout Atmosphere, reactStyle:Dictionary<String, Any>
|
|
|
801
801
|
}
|
|
802
802
|
}
|
|
803
803
|
|
|
804
|
+
func terrainLayer(layer: inout Terrain, reactStyle:Dictionary<String, Any>, applyUpdater: @escaping ((inout Terrain)->Void)->Void, isValid: @escaping () -> Bool)
|
|
805
|
+
{
|
|
806
|
+
guard self._hasReactStyle(reactStyle) else {
|
|
807
|
+
Logger.log(level:.error, message: "Invalid style: \(reactStyle)")
|
|
808
|
+
return
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
let styleProps = reactStyle.keys
|
|
812
|
+
for prop in styleProps {
|
|
813
|
+
if (prop == "__MAPBOX_STYLESHEET__") {
|
|
814
|
+
continue;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
let styleValue = RCTMGLStyleValue.make(reactStyle[prop])
|
|
818
|
+
|
|
819
|
+
if (prop == "exaggeration") {
|
|
820
|
+
self.setExaggeration(&layer, styleValue:styleValue);
|
|
821
|
+
} else {
|
|
822
|
+
Logger.log(level:.error, message: "Unexpected property \(prop) for layer: terrain")
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
|
|
804
827
|
|
|
805
828
|
|
|
806
829
|
|
|
@@ -2501,6 +2524,17 @@ func setStarIntensityTransition(_ layer: inout Atmosphere, styleValue: RCTMGLSty
|
|
|
2501
2524
|
|
|
2502
2525
|
|
|
2503
2526
|
|
|
2527
|
+
func setExaggeration(_ layer: inout Terrain, styleValue: RCTMGLStyleValue)
|
|
2528
|
+
{
|
|
2529
|
+
|
|
2530
|
+
|
|
2531
|
+
layer.exaggeration = styleValue.mglStyleValueNumber();
|
|
2532
|
+
|
|
2533
|
+
|
|
2534
|
+
}
|
|
2535
|
+
|
|
2536
|
+
|
|
2537
|
+
|
|
2504
2538
|
func _hasReactStyle(_ reactStyle: Dictionary<String, Any>) -> Bool
|
|
2505
2539
|
{
|
|
2506
2540
|
return reactStyle != nil && reactStyle.keys.count > 0;
|
|
@@ -1,49 +1,16 @@
|
|
|
1
1
|
import MapboxMaps
|
|
2
2
|
|
|
3
3
|
@objc
|
|
4
|
-
class RCTMGLTerrain :
|
|
5
|
-
weak var map : RCTMGLMapView!
|
|
6
|
-
var style : Style! = nil
|
|
7
|
-
|
|
8
|
-
var bridge : RCTBridge? = nil
|
|
4
|
+
class RCTMGLTerrain : RCTMGLSingletonLayer, RCTMGLMapComponent, RCTMGLSourceConsumer {
|
|
9
5
|
var terrain : Terrain? = nil
|
|
10
6
|
|
|
11
|
-
@objc var sourceID: String? = nil
|
|
12
|
-
|
|
13
|
-
@objc var exaggeration : Any? = nil
|
|
14
|
-
|
|
15
|
-
func waitForStyleLoad() -> Bool {
|
|
16
|
-
return true
|
|
17
|
-
}
|
|
18
|
-
|
|
19
7
|
func makeTerrain() -> Terrain {
|
|
20
|
-
print("=> sourceID \(sourceID)")
|
|
21
8
|
guard let sourceID = sourceID else {
|
|
22
9
|
Logger.log(level: .error, message: "Terrain should have a sourceID")
|
|
23
10
|
return Terrain(sourceId: "n/a")
|
|
24
11
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
do {
|
|
28
|
-
terrain.exaggeration = try toValue(exaggeration)
|
|
29
|
-
} catch {
|
|
30
|
-
Logger.log(level: .error, message: "Faied to parse exaggeration value: \(exaggeration) \(error)")
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return terrain
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
func toValue(_ value: Any) throws -> Value<Double>? {
|
|
38
|
-
if let value = value as? NSNumber {
|
|
39
|
-
return .constant(value.doubleValue)
|
|
40
|
-
} else if let value = value as? [Any] {
|
|
41
|
-
let data = try JSONSerialization.data(withJSONObject: value, options: .prettyPrinted)
|
|
42
|
-
let decodedExpression = try JSONDecoder().decode(Expression.self, from: data)
|
|
43
|
-
return .expression(decodedExpression)
|
|
44
|
-
} else {
|
|
45
|
-
throw RCTMGLError.parseError("failed to parse value")
|
|
46
|
-
}
|
|
12
|
+
|
|
13
|
+
return Terrain(sourceId: sourceID)
|
|
47
14
|
}
|
|
48
15
|
|
|
49
16
|
func addToMap(_ map: RCTMGLMapView, style: Style) {
|
|
@@ -52,32 +19,7 @@ class RCTMGLTerrain : UIView, RCTMGLMapComponent, RCTMGLSourceConsumer {
|
|
|
52
19
|
|
|
53
20
|
let terrain = self.makeTerrain()
|
|
54
21
|
self.terrain = terrain
|
|
55
|
-
|
|
56
|
-
if let mapboxMap = map.mapboxMap {
|
|
57
|
-
let style = mapboxMap.style
|
|
58
|
-
logged("RCTMGLTerrain.addToMap") {
|
|
59
|
-
try style.setTerrain(terrain)
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
func addToMap(_ map: RCTMGLMapView) {
|
|
66
|
-
self.map = map
|
|
67
|
-
|
|
68
|
-
guard let mapboxMap = map.mapboxMap else {
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
mapboxMap.onNext(.styleLoaded) {_ in
|
|
73
|
-
let style = mapboxMap.style
|
|
74
|
-
|
|
75
|
-
do {
|
|
76
|
-
try style.setTerrain(self.makeTerrain())
|
|
77
|
-
} catch {
|
|
78
|
-
Logger.log(level: .error, message: "setTerrain failed: \(error)")
|
|
79
|
-
}
|
|
80
|
-
}
|
|
22
|
+
addStylesAndUpdate()
|
|
81
23
|
}
|
|
82
24
|
|
|
83
25
|
func removeFromMap(_ map: RCTMGLMapView) {
|
|
@@ -91,7 +33,58 @@ class RCTMGLTerrain : UIView, RCTMGLMapComponent, RCTMGLSourceConsumer {
|
|
|
91
33
|
removeFromMap(map, style: style)
|
|
92
34
|
}
|
|
93
35
|
|
|
36
|
+
func waitForStyleLoad() -> Bool {
|
|
37
|
+
return true
|
|
38
|
+
}
|
|
39
|
+
|
|
94
40
|
func removeFromMap(_ map: RCTMGLMapView, style: Style) {
|
|
95
|
-
|
|
41
|
+
logged("RCTMGLTerrain.removeFromMap") {
|
|
42
|
+
style.removeTerrain()
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@objc var sourceID: String? = nil {
|
|
47
|
+
didSet {
|
|
48
|
+
guard let sourceID = sourceID else {
|
|
49
|
+
Logger.log(level: .error, message: "RCTMGLTerrain cannot set source to nil")
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
terrain?.source = sourceID
|
|
54
|
+
self.update()
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
override func addStylesAndUpdate() {
|
|
59
|
+
guard terrain != nil else {
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
super.addStylesAndUpdate()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
override func addStyles() {
|
|
67
|
+
if let style : Style = self.style {
|
|
68
|
+
let styler = RCTMGLStyle(style: style)
|
|
69
|
+
styler.bridge = self.bridge
|
|
70
|
+
|
|
71
|
+
if var terrain = terrain {
|
|
72
|
+
styler.terrainLayer(
|
|
73
|
+
layer: &terrain,
|
|
74
|
+
reactStyle: reactStyle ?? [:],
|
|
75
|
+
applyUpdater: { (updater) in fatalError("Terrain: TODO - implement apply updater")},
|
|
76
|
+
isValid: { fatalError("Terrain: TODO - no isValid") }
|
|
77
|
+
)
|
|
78
|
+
self.terrain = terrain
|
|
79
|
+
} else {
|
|
80
|
+
fatalError("[xxx] terrain is nil \(optional: self.terrain)")
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
override func apply(style : Style) throws {
|
|
86
|
+
if let terrain = terrain {
|
|
87
|
+
try style.setTerrain(terrain)
|
|
88
|
+
}
|
|
96
89
|
}
|
|
97
90
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/* eslint react/prop-types:0 */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { NativeMethods, processColor } from 'react-native';
|
|
4
|
+
|
|
5
|
+
import { getFilter } from '../utils/filterUtils';
|
|
6
|
+
import { transformStyle } from '../utils/StyleValue';
|
|
7
|
+
import { AllLayerStyleProps } from '../utils/MapboxStyles';
|
|
8
|
+
|
|
9
|
+
type PropsBase = {
|
|
10
|
+
id: string;
|
|
11
|
+
sourceID?: string;
|
|
12
|
+
minZoomLevel?: number;
|
|
13
|
+
maxZoomLevel?: number;
|
|
14
|
+
aboveLayerID?: string;
|
|
15
|
+
belowLayerID?: string;
|
|
16
|
+
layerIndex?: number;
|
|
17
|
+
filter?: string[];
|
|
18
|
+
style: AllLayerStyleProps;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
class AbstractLayer<
|
|
22
|
+
PropsType extends PropsBase,
|
|
23
|
+
NativePropsType,
|
|
24
|
+
> extends React.PureComponent<PropsType> {
|
|
25
|
+
get baseProps(): PropsType {
|
|
26
|
+
return {
|
|
27
|
+
...this.props,
|
|
28
|
+
id: this.props.id,
|
|
29
|
+
sourceID: this.props.sourceID,
|
|
30
|
+
reactStyle: this.getStyle(this.props.style),
|
|
31
|
+
minZoomLevel: this.props.minZoomLevel,
|
|
32
|
+
maxZoomLevel: this.props.maxZoomLevel,
|
|
33
|
+
aboveLayerID: this.props.aboveLayerID,
|
|
34
|
+
belowLayerID: this.props.belowLayerID,
|
|
35
|
+
layerIndex: this.props.layerIndex,
|
|
36
|
+
filter: getFilter(this.props.filter),
|
|
37
|
+
style: undefined,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
nativeLayer:
|
|
42
|
+
| (React.Component<NativePropsType> & Readonly<NativeMethods>)
|
|
43
|
+
| undefined = undefined;
|
|
44
|
+
|
|
45
|
+
setNativeLayer(
|
|
46
|
+
instance: React.Component<NativePropsType> & Readonly<NativeMethods>,
|
|
47
|
+
) {
|
|
48
|
+
this.nativeLayer = instance;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
getStyleTypeFormatter(styleType: string) {
|
|
52
|
+
if (styleType === 'color') {
|
|
53
|
+
return processColor;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
getStyle(style: AllLayerStyleProps) {
|
|
58
|
+
return transformStyle(style);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
setNativeProps(props: { [key: string]: unknown }) {
|
|
62
|
+
if (this.nativeLayer) {
|
|
63
|
+
let propsToPass = props;
|
|
64
|
+
if (props.style) {
|
|
65
|
+
propsToPass = { ...props, reactStyle: this.getStyle(props.style) };
|
|
66
|
+
}
|
|
67
|
+
this.nativeLayer?.setNativeProps(propsToPass);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export default AbstractLayer;
|
|
@@ -9,11 +9,27 @@ import React, {
|
|
|
9
9
|
import { NativeModules, requireNativeComponent } from 'react-native';
|
|
10
10
|
import { Position } from '@turf/helpers';
|
|
11
11
|
|
|
12
|
-
import {
|
|
12
|
+
import { MapboxGLEvent } from '../types';
|
|
13
13
|
import { makeLatLngBounds, makePoint } from '../utils/geoUtils';
|
|
14
14
|
|
|
15
15
|
const NativeModule = NativeModules.MGLModule;
|
|
16
16
|
|
|
17
|
+
export const enum UserTrackingMode {
|
|
18
|
+
Follow = 'normal',
|
|
19
|
+
FollowWithHeading = 'compass',
|
|
20
|
+
FollowWithCourse = 'course',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type UserTrackingModeChangeCallback = (
|
|
24
|
+
event: MapboxGLEvent<
|
|
25
|
+
'usertrackingmodechange',
|
|
26
|
+
{
|
|
27
|
+
followUserLocation: boolean;
|
|
28
|
+
followUserMode: UserTrackingMode | null;
|
|
29
|
+
}
|
|
30
|
+
>,
|
|
31
|
+
) => void;
|
|
32
|
+
|
|
17
33
|
/**
|
|
18
34
|
* Converts the provided React Native animation mode into the corresponding native enum value.
|
|
19
35
|
*/
|
|
@@ -83,7 +83,7 @@ class FillExtrusionLayer extends AbstractLayer {
|
|
|
83
83
|
...this.baseProps,
|
|
84
84
|
sourceLayerID: this.props.sourceLayerID,
|
|
85
85
|
};
|
|
86
|
-
return <RCTMGLFillExtrusionLayer ref=
|
|
86
|
+
return <RCTMGLFillExtrusionLayer ref={this.setNativeLayer} {...props} />;
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
2
|
|
|
4
3
|
import headingIcon from '../../assets/heading.png';
|
|
5
4
|
|
|
@@ -10,9 +9,13 @@ const style = {
|
|
|
10
9
|
iconAllowOverlap: true,
|
|
11
10
|
iconPitchAlignment: 'map',
|
|
12
11
|
iconRotationAlignment: 'map',
|
|
12
|
+
} as const;
|
|
13
|
+
|
|
14
|
+
type Props = {
|
|
15
|
+
heading?: number;
|
|
13
16
|
};
|
|
14
17
|
|
|
15
|
-
const HeadingIndicator = (heading) => (
|
|
18
|
+
const HeadingIndicator = ({ heading }: Props) => (
|
|
16
19
|
<SymbolLayer
|
|
17
20
|
key="mapboxUserLocationHeadingIndicator"
|
|
18
21
|
id="mapboxUserLocationHeadingIndicator"
|
|
@@ -24,8 +27,4 @@ const HeadingIndicator = (heading) => (
|
|
|
24
27
|
/>
|
|
25
28
|
);
|
|
26
29
|
|
|
27
|
-
HeadingIndicator.propTypes = {
|
|
28
|
-
heading: PropTypes.number,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
30
|
export default HeadingIndicator;
|
|
@@ -84,7 +84,7 @@ class HeatmapLayer extends AbstractLayer {
|
|
|
84
84
|
...this.baseProps,
|
|
85
85
|
sourceLayerID: this.props.sourceLayerID,
|
|
86
86
|
};
|
|
87
|
-
return <RCTMGLHeatmapLayer ref=
|
|
87
|
+
return <RCTMGLHeatmapLayer ref={this.setNativeLayer} {...props} />;
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
|
|
@@ -215,22 +215,12 @@ class MapView extends NativeBridgeComponent(React.Component) {
|
|
|
215
215
|
onRegionDidChange: PropTypes.func,
|
|
216
216
|
|
|
217
217
|
/**
|
|
218
|
-
* iOS, v10 only,
|
|
219
|
-
*
|
|
220
|
-
* Called when the currently displayed map area changes.
|
|
221
|
-
* Replaces onRegionIsChanging, so can't set both
|
|
222
|
-
*
|
|
223
|
-
* @param {MapState} region - A payload containing the map center, bounds, and other properties.
|
|
218
|
+
* iOS, v10 only, deprecated will be removed in next version - please use onRegionIsChanging.
|
|
224
219
|
*/
|
|
225
220
|
onCameraChanged: PropTypes.func,
|
|
226
221
|
|
|
227
222
|
/**
|
|
228
|
-
* iOS, v10 only,
|
|
229
|
-
*
|
|
230
|
-
* Called when the currently displayed map area stops changing.
|
|
231
|
-
* Replaces onRegionDidChange, so can't set both
|
|
232
|
-
*
|
|
233
|
-
* @param {MapState} region - A payload containing the map center, bounds, and other properties.
|
|
223
|
+
* iOS, v10 only, deprecated will be removed in next version - please use onRegionDidChange
|
|
234
224
|
*/
|
|
235
225
|
onMapIdle: PropTypes.func,
|
|
236
226
|
|
|
@@ -393,6 +383,9 @@ class MapView extends NativeBridgeComponent(React.Component) {
|
|
|
393
383
|
addIfHasHandler('DidFinishLoadingStyle');
|
|
394
384
|
|
|
395
385
|
if (addIfHasHandler('MapIdle')) {
|
|
386
|
+
console.warn(
|
|
387
|
+
'onMapIdle is deprecated and will be removed in next beta - please use onRegionDidChange',
|
|
388
|
+
);
|
|
396
389
|
if (props.onRegionDidChange) {
|
|
397
390
|
console.warn(
|
|
398
391
|
'rnmapbox/maps: only one of MapView.onRegionDidChange or onMapIdle is supported',
|
|
@@ -400,6 +393,9 @@ class MapView extends NativeBridgeComponent(React.Component) {
|
|
|
400
393
|
}
|
|
401
394
|
}
|
|
402
395
|
if (addIfHasHandler('CameraChanged')) {
|
|
396
|
+
console.warn(
|
|
397
|
+
'onCameraChanged is deprecated and will be removed in next beta - please use onRegionWillChange',
|
|
398
|
+
);
|
|
403
399
|
if (props.onRegionWillChange) {
|
|
404
400
|
console.warn(
|
|
405
401
|
'rnmapbox/maps: only one of MapView.onRegionWillChange or onCameraChanged is supported',
|