@rnmapbox/maps 10.0.0-beta.41 → 10.0.0-beta.42
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/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 +21 -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/MapView.md +2 -2
- package/docs/Terrain.md +64 -9
- package/docs/docs.json +54 -45
- package/index.d.ts +2 -7
- package/ios/RCTMGL-v10/RCTMGLCamera.swift +25 -7
- 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/Camera.tsx +17 -1
- package/javascript/components/MapView.js +8 -12
- package/javascript/components/Terrain.tsx +112 -0
- package/javascript/index.js +8 -4
- package/javascript/types/index.ts +0 -14
- package/javascript/utils/MapboxStyles.ts +20 -2
- package/javascript/utils/deprecation.ts +39 -0
- package/javascript/utils/styleMap.ts +26 -0
- package/package.json +6 -6
- package/scripts/autogenHelpers/globals.js +2 -0
- package/scripts/autogenerate.js +13 -0
- package/scripts/templates/MapboxStyles.ts.ejs +1 -1
- package/scripts/templates/RCTMGLStyleFactoryv10.java.ejs +1 -0
- package/.eslintignore +0 -1
- package/javascript/components/Terrain.js +0 -56
- package/javascript/utils/deprecation.js +0 -24
package/index.d.ts
CHANGED
|
@@ -32,14 +32,14 @@ import {
|
|
|
32
32
|
CameraBoundsWithPadding as _CameraBoundsWithPadding,
|
|
33
33
|
CameraStops as _CameraStops,
|
|
34
34
|
CameraAnimationMode as _CameraAnimationMode,
|
|
35
|
+
type UserTrackingMode as _UserTrackingMode,
|
|
36
|
+
type UserTrackingModeChangeCallback as _UserTrackingModeChangeCallback,
|
|
35
37
|
} from './javascript/components/Camera';
|
|
36
38
|
import { MarkerView as _MarkerView } from './javascript/components/MarkerView';
|
|
37
39
|
import { PointAnnotation as _PointAnnotation } from './javascript/components/PointAnnotation';
|
|
38
40
|
import { Atmosphere as _Atmosphere } from './javascript/components/Atmosphere';
|
|
39
41
|
import type {
|
|
40
42
|
MapboxGLEvent as _MapboxGLEvent,
|
|
41
|
-
UserTrackingMode as _UserTrackingMode,
|
|
42
|
-
UserTrackingModeChangeCallback as _UserTrackingModeChangeCallback,
|
|
43
43
|
AnimatedPoint as _AnimatedPoint,
|
|
44
44
|
AnimatedShape as _AnimatedShape,
|
|
45
45
|
} from './javascript/types/index';
|
|
@@ -482,11 +482,6 @@ declare namespace MapboxGL {
|
|
|
482
482
|
/**
|
|
483
483
|
* Constants
|
|
484
484
|
*/
|
|
485
|
-
enum UserTrackingModes {
|
|
486
|
-
Follow = 'normal',
|
|
487
|
-
FollowWithHeading = 'compass',
|
|
488
|
-
FollowWithCourse = 'course',
|
|
489
|
-
}
|
|
490
485
|
|
|
491
486
|
enum InterpolationMode {
|
|
492
487
|
Exponential = 0,
|
|
@@ -13,6 +13,10 @@ enum CameraMode: String, CaseIterable {
|
|
|
13
13
|
case flight, ease, linear, none
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
enum UserTrackingMode: String {
|
|
17
|
+
case none,compass, course, normal
|
|
18
|
+
}
|
|
19
|
+
|
|
16
20
|
struct CameraUpdateItem {
|
|
17
21
|
var camera: CameraOptions
|
|
18
22
|
var mode: CameraMode
|
|
@@ -133,7 +137,7 @@ class RCTMGLCamera : RCTMGLMapComponentBase, LocationConsumer {
|
|
|
133
137
|
_updateCameraFromTrackingMode()
|
|
134
138
|
}
|
|
135
139
|
}
|
|
136
|
-
@objc var followUserMode:
|
|
140
|
+
@objc var followUserMode: String? {
|
|
137
141
|
didSet {
|
|
138
142
|
_updateCameraFromTrackingMode()
|
|
139
143
|
}
|
|
@@ -192,11 +196,22 @@ class RCTMGLCamera : RCTMGLMapComponentBase, LocationConsumer {
|
|
|
192
196
|
}
|
|
193
197
|
}
|
|
194
198
|
|
|
199
|
+
func _disableUsetTracking(_ map: MapView) {
|
|
200
|
+
map.viewport.idle()
|
|
201
|
+
map.location.removeLocationConsumer(consumer: self)
|
|
202
|
+
}
|
|
203
|
+
|
|
195
204
|
func _updateCameraFromTrackingMode() {
|
|
196
205
|
withMapView { map in
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
206
|
+
let userTrackingMode = UserTrackingMode(rawValue: self.followUserMode ?? "none")
|
|
207
|
+
guard let userTrackingMode = userTrackingMode else {
|
|
208
|
+
Logger.error("RCTMGLCamera: Unexpected followUserMode \(optional: self.followUserMode)")
|
|
209
|
+
self._disableUsetTracking(map)
|
|
210
|
+
return
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
guard self.followUserLocation && userTrackingMode != .none else {
|
|
214
|
+
self._disableUsetTracking(map)
|
|
200
215
|
return
|
|
201
216
|
}
|
|
202
217
|
|
|
@@ -207,17 +222,20 @@ class RCTMGLCamera : RCTMGLMapComponentBase, LocationConsumer {
|
|
|
207
222
|
map.location.addLocationConsumer(newConsumer: self)
|
|
208
223
|
var trackingModeChanged = false
|
|
209
224
|
var followOptions = FollowPuckViewportStateOptions()
|
|
210
|
-
|
|
225
|
+
switch userTrackingMode {
|
|
226
|
+
case .none:
|
|
227
|
+
Logger.assert("RCTMGLCamera, userTrackingModes should not be none here")
|
|
228
|
+
case .compass:
|
|
211
229
|
map.location.options.puckBearingEnabled = true
|
|
212
230
|
map.location.options.puckBearingSource = PuckBearingSource.heading
|
|
213
231
|
followOptions.bearing = FollowPuckViewportStateBearing.heading
|
|
214
232
|
trackingModeChanged = true
|
|
215
|
-
|
|
233
|
+
case .course:
|
|
216
234
|
map.location.options.puckBearingEnabled = true
|
|
217
235
|
map.location.options.puckBearingSource = PuckBearingSource.course
|
|
218
236
|
followOptions.bearing = FollowPuckViewportStateBearing.course
|
|
219
237
|
trackingModeChanged = true
|
|
220
|
-
|
|
238
|
+
case .normal:
|
|
221
239
|
map.location.options.puckBearingEnabled = false
|
|
222
240
|
followOptions.bearing = nil
|
|
223
241
|
trackingModeChanged = true
|
|
@@ -69,7 +69,7 @@ class RCTMGLImages : UIView, RCTMGLMapComponent {
|
|
|
69
69
|
return false
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
public func sendImageMissingEvent(imageName: String,
|
|
72
|
+
public func sendImageMissingEvent(imageName: String, payload: StyleImageMissingPayload) {
|
|
73
73
|
let payload = ["imageKey":imageName]
|
|
74
74
|
let event = RCTMGLEvent(type: .imageMissing, payload: payload)
|
|
75
75
|
if let onImageMissing = onImageMissing {
|
|
@@ -97,101 +97,3 @@ class RCTMGLImages : UIView, RCTMGLMapComponent {
|
|
|
97
97
|
}()
|
|
98
98
|
|
|
99
99
|
}
|
|
100
|
-
/*
|
|
101
|
-
#import "RCTMGLImages.h"
|
|
102
|
-
#import "UIView+React.h"
|
|
103
|
-
#import "RCTMGLMapView.h"
|
|
104
|
-
#import "RCTMGLUtils.h"
|
|
105
|
-
#import "RCTMGLEvent.h"
|
|
106
|
-
#import "RCTMGLEventTypes.h"
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
@implementation RCTMGLImages : UIView
|
|
110
|
-
|
|
111
|
-
static UIImage * _placeHolderImage;
|
|
112
|
-
|
|
113
|
-
- (void)addToMap
|
|
114
|
-
{
|
|
115
|
-
if (self.map.style == nil) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
[self _addNativeImages:_nativeImages];
|
|
119
|
-
[self _addRemoteImages:_images];
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
- (void)removeFromMap
|
|
123
|
-
{
|
|
124
|
-
if (self.map.style == nil) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
[self _removeImages];
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
- (void)_removeImages
|
|
132
|
-
{
|
|
133
|
-
if ([self _hasImages]) {
|
|
134
|
-
NSArray<NSString *> *imageNames = _images.allKeys;
|
|
135
|
-
|
|
136
|
-
for (NSString *imageName in imageNames) {
|
|
137
|
-
[self.map.style removeImageForName:imageName];
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if ([self _hasNativeImages]) {
|
|
142
|
-
for (NSString *imageName in _nativeImages) {
|
|
143
|
-
[self.map.style removeImageForName:imageName];
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
- (void)_addNativeImages:(NSArray<NSString *>*)nativeImages
|
|
149
|
-
{
|
|
150
|
-
if (!nativeImages) return;
|
|
151
|
-
|
|
152
|
-
for (NSString *imageName in nativeImages) {
|
|
153
|
-
// only add native images if they are not in the style yet (similar to [RCTMGLUtils fetchImages: style:])
|
|
154
|
-
if (![self.map.style imageForName:imageName]) {
|
|
155
|
-
UIImage *image = [UIImage imageNamed:imageName];
|
|
156
|
-
[self.map.style setImage:image forName:imageName];
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
- (void)_addRemoteImages:(NSDictionary<NSString *, NSString *>*)remoteImages
|
|
162
|
-
{
|
|
163
|
-
if (!remoteImages) return;
|
|
164
|
-
NSDictionary<NSString *, NSString *> *missingImages = [NSMutableDictionary new];
|
|
165
|
-
|
|
166
|
-
// Add image placeholder for images that are not yet available in the style. This way
|
|
167
|
-
// we can load the images asynchronously and add the ShapeSource to the map without delay.
|
|
168
|
-
// The same is required when this ShapeSource is updated with new/added images and the
|
|
169
|
-
// data references them. In which case addMissingImageToStyle will take care of loading
|
|
170
|
-
// them in a similar way.
|
|
171
|
-
//
|
|
172
|
-
// See also: https://github.com/mapbox/mapbox-gl-native/pull/14253#issuecomment-478827792
|
|
173
|
-
for (NSString *imageName in remoteImages.allKeys) {
|
|
174
|
-
if (![self.map.style imageForName:imageName]) {
|
|
175
|
-
[self.map.style setImage:[RCTMGLImages placeholderImage] forName:imageName];
|
|
176
|
-
[missingImages setValue:_images[imageName] forKey:imageName];
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (missingImages.count > 0) {
|
|
181
|
-
// forceUpdate to ensure the placeholder images are updated
|
|
182
|
-
[RCTMGLUtils fetchImages:_bridge style:self.map.style objects:_images forceUpdate:true callback:^{ }];
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
- (BOOL)_hasImages
|
|
187
|
-
{
|
|
188
|
-
return _images != nil && _images.count > 0;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
- (BOOL)_hasNativeImages
|
|
192
|
-
{
|
|
193
|
-
return _nativeImages != nil && _nativeImages.count > 0;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
@end
|
|
197
|
-
*/
|
|
@@ -63,6 +63,14 @@ class Logger {
|
|
|
63
63
|
static func log(level: LogLevel, message: String, error: Error) {
|
|
64
64
|
sharedInstance.log(level: level, message: "\(message) - error: \(error.localizedDescription) \(error)")
|
|
65
65
|
}
|
|
66
|
+
|
|
67
|
+
static func error(_ message: String) {
|
|
68
|
+
log(level: .error, message: message)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static func assert(_ message: String) {
|
|
72
|
+
log(level: .error, message: "Assertion failure: \(message)")
|
|
73
|
+
}
|
|
66
74
|
}
|
|
67
75
|
|
|
68
76
|
func logged<T>(_ msg: String, info: (() -> String)? = nil, level: Logger.LogLevel = .error, rejecter: RCTPromiseRejectBlock? = nil, fn : () throws -> T) -> T? {
|
|
@@ -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
|
}
|
|
@@ -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
|
*/
|
|
@@ -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',
|