@rnmapbox/maps 10.0.15-rc.1 → 10.1.0-beta.2
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/build.gradle +20 -0
- package/android/src/main/java-v10/com/mapbox/rctmgl/RCTMGLPackage.java +109 -12
- package/android/src/main/java-v10/com/mapbox/rctmgl/components/AbstractEventEmitter.kt +2 -3
- package/android/src/main/java-v10/com/mapbox/rctmgl/components/mapview/NativeMapViewModule.kt +193 -0
- package/android/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLAndroidTextureMapViewManager.kt +16 -2
- package/android/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.kt +1 -1
- package/android/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapViewManager.kt +75 -160
- package/android/src/main/java-v10/com/mapbox/rctmgl/mapbox/Light.kt +6 -0
- package/android/src/main/old-arch/com/facebook/react/viewmanagers/MBXAndroidTextureMapViewManagerDelegate.java +89 -0
- package/android/src/main/old-arch/com/facebook/react/viewmanagers/MBXAndroidTextureMapViewManagerInterface.java +37 -0
- package/android/src/main/old-arch/com/facebook/react/viewmanagers/MBXMapViewManagerDelegate.java +89 -0
- package/android/src/main/old-arch/com/facebook/react/viewmanagers/MBXMapViewManagerInterface.java +37 -0
- package/android/src/main/old-arch/com/mapbox/rctmgl/NativeMapViewModuleSpec.java +88 -0
- package/ios/RCTMGL-v10/CustomHttpHeaders.swift +18 -0
- package/ios/RCTMGL-v10/MBXMapViewComponentView.h +18 -0
- package/ios/RCTMGL-v10/MBXMapViewComponentView.mm +203 -0
- package/ios/RCTMGL-v10/MBXMapViewManager.m +37 -0
- package/ios/RCTMGL-v10/MBXMapViewManager.swift +250 -0
- package/ios/RCTMGL-v10/MBXMapViewModule.h +18 -0
- package/ios/RCTMGL-v10/MBXMapViewModule.mm +167 -0
- package/ios/RCTMGL-v10/MGLModule.swift +15 -1
- package/ios/RCTMGL-v10/MGLSnapshotModule.swift +7 -1
- package/ios/RCTMGL-v10/RCTMGLAtmosphere.swift +4 -0
- package/ios/RCTMGL-v10/RCTMGLBackgroundLayer.swift +2 -1
- package/ios/RCTMGL-v10/RCTMGLCamera.swift +23 -0
- package/ios/RCTMGL-v10/RCTMGLCircleLayer.swift +4 -0
- package/ios/RCTMGL-v10/RCTMGLFillExtrustionLayer.swift +4 -0
- package/ios/RCTMGL-v10/RCTMGLFillLayer.swift +4 -0
- package/ios/RCTMGL-v10/RCTMGLHeatmapLayer.swift +4 -1
- package/ios/RCTMGL-v10/RCTMGLImageSource.swift +4 -0
- package/ios/RCTMGL-v10/RCTMGLImages.swift +14 -2
- package/ios/RCTMGL-v10/RCTMGLLayer.swift +35 -11
- package/ios/RCTMGL-v10/RCTMGLLight.swift +14 -4
- package/ios/RCTMGL-v10/RCTMGLLineLayer.swift +4 -0
- package/ios/RCTMGL-v10/RCTMGLLocationModule.swift +65 -12
- package/ios/RCTMGL-v10/RCTMGLLocationModuleV11.swift +32 -0
- package/ios/RCTMGL-v10/RCTMGLMapView.swift +115 -27
- package/ios/RCTMGL-v10/RCTMGLNativeUserLocation.swift +4 -0
- package/ios/RCTMGL-v10/RCTMGLOfflineModule.swift +17 -0
- package/ios/RCTMGL-v10/RCTMGLRasterDemSource.swift +4 -0
- package/ios/RCTMGL-v10/RCTMGLRasterLayer.swift +4 -0
- package/ios/RCTMGL-v10/RCTMGLRasterSource.swift +4 -0
- package/ios/RCTMGL-v10/RCTMGLShapeSource.swift +65 -3
- package/ios/RCTMGL-v10/RCTMGLSource.swift +4 -0
- package/ios/RCTMGL-v10/RCTMGLStyleValue.swift +60 -1
- package/ios/RCTMGL-v10/RCTMGLSymbolLayer.swift +4 -0
- package/ios/RCTMGL-v10/RCTMGLVectorSource.swift +4 -0
- package/ios/RCTMGL-v10/rnmapbox_maps.h +1 -0
- package/lib/commonjs/components/MapView.js +47 -11
- package/lib/commonjs/components/MapView.js.map +1 -1
- package/lib/commonjs/specs/MBXAndroidTextureMapViewNativeComponent.js +13 -0
- package/lib/commonjs/specs/MBXAndroidTextureMapViewNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/MBXMapViewNativeComponent.js +11 -0
- package/lib/commonjs/specs/MBXMapViewNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/NativeMapViewModule.js +11 -0
- package/lib/commonjs/specs/NativeMapViewModule.js.map +1 -0
- package/lib/commonjs/specs/codegenUtils.js +2 -0
- package/lib/commonjs/specs/codegenUtils.js.map +1 -0
- package/lib/module/components/MapView.js +47 -10
- package/lib/module/components/MapView.js.map +1 -1
- package/lib/module/specs/MBXAndroidTextureMapViewNativeComponent.js +5 -0
- package/lib/module/specs/MBXAndroidTextureMapViewNativeComponent.js.map +1 -0
- package/lib/module/specs/MBXMapViewNativeComponent.js +3 -0
- package/lib/module/specs/MBXMapViewNativeComponent.js.map +1 -0
- package/lib/module/specs/NativeMapViewModule.js +5 -0
- package/lib/module/specs/NativeMapViewModule.js.map +1 -0
- package/lib/module/specs/codegenUtils.js +2 -0
- package/lib/module/specs/codegenUtils.js.map +1 -0
- package/lib/typescript/components/MapView.d.ts +13 -3
- package/lib/typescript/components/MapView.d.ts.map +1 -1
- package/lib/typescript/specs/MBXAndroidTextureMapViewNativeComponent.d.ts +52 -0
- package/lib/typescript/specs/MBXAndroidTextureMapViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/specs/MBXMapViewNativeComponent.d.ts +52 -0
- package/lib/typescript/specs/MBXMapViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/specs/NativeMapViewModule.d.ts +21 -0
- package/lib/typescript/specs/NativeMapViewModule.d.ts.map +1 -0
- package/lib/typescript/specs/codegenUtils.d.ts +2 -0
- package/lib/typescript/specs/codegenUtils.d.ts.map +1 -0
- package/package.json +9 -1
- package/rnmapbox-maps.podspec +22 -4
- package/setup-jest.js +16 -0
- package/src/components/MapView.tsx +56 -12
- package/src/specs/MBXAndroidTextureMapViewNativeComponent.ts +63 -0
- package/src/specs/MBXMapViewNativeComponent.ts +63 -0
- package/src/specs/NativeMapViewModule.ts +54 -0
- package/src/specs/codegenUtils.ts +4 -0
- package/ios/RCTMGL-v10/RCTMGLMapViewManager.m +0 -107
- package/ios/RCTMGL-v10/RCTMGLMapViewManager.swift +0 -285
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* This file should be updated after modifying `NativeMapViewModule.ts`.
|
|
6
|
+
*
|
|
7
|
+
* @generated by codegen project: GenerateModuleJavaSpec.js
|
|
8
|
+
*
|
|
9
|
+
* @nolint
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
package com.mapbox.rctmgl;
|
|
13
|
+
|
|
14
|
+
import com.facebook.proguard.annotations.DoNotStrip;
|
|
15
|
+
import com.facebook.react.bridge.Promise;
|
|
16
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
17
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
18
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
19
|
+
import com.facebook.react.bridge.ReactModuleWithSpec;
|
|
20
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
21
|
+
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
|
|
22
|
+
import javax.annotation.Nonnull;
|
|
23
|
+
import javax.annotation.Nullable;
|
|
24
|
+
|
|
25
|
+
public abstract class NativeMapViewModuleSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
|
|
26
|
+
public static final String NAME = "MBXMapViewModule";
|
|
27
|
+
|
|
28
|
+
public NativeMapViewModuleSpec(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 takeSnap(@Nullable Double viewRef, boolean writeToDisk, Promise promise);
|
|
40
|
+
|
|
41
|
+
@ReactMethod
|
|
42
|
+
@DoNotStrip
|
|
43
|
+
public abstract void queryTerrainElevation(@Nullable Double viewRef, ReadableArray coordinates, Promise promise);
|
|
44
|
+
|
|
45
|
+
@ReactMethod
|
|
46
|
+
@DoNotStrip
|
|
47
|
+
public abstract void setSourceVisibility(@Nullable Double viewRef, boolean visible, String sourceId, String sourceLayerId, Promise promise);
|
|
48
|
+
|
|
49
|
+
@ReactMethod
|
|
50
|
+
@DoNotStrip
|
|
51
|
+
public abstract void getCenter(@Nullable Double viewRef, Promise promise);
|
|
52
|
+
|
|
53
|
+
@ReactMethod
|
|
54
|
+
@DoNotStrip
|
|
55
|
+
public abstract void getCoordinateFromView(@Nullable Double viewRef, ReadableArray atPoint, Promise promise);
|
|
56
|
+
|
|
57
|
+
@ReactMethod
|
|
58
|
+
@DoNotStrip
|
|
59
|
+
public abstract void getPointInView(@Nullable Double viewRef, ReadableArray atCoordinate, Promise promise);
|
|
60
|
+
|
|
61
|
+
@ReactMethod
|
|
62
|
+
@DoNotStrip
|
|
63
|
+
public abstract void getZoom(@Nullable Double viewRef, Promise promise);
|
|
64
|
+
|
|
65
|
+
@ReactMethod
|
|
66
|
+
@DoNotStrip
|
|
67
|
+
public abstract void getVisibleBounds(@Nullable Double viewRef, Promise promise);
|
|
68
|
+
|
|
69
|
+
@ReactMethod
|
|
70
|
+
@DoNotStrip
|
|
71
|
+
public abstract void queryRenderedFeaturesAtPoint(@Nullable Double viewRef, ReadableArray atPoint, ReadableArray withFilter, ReadableArray withLayerIDs, Promise promise);
|
|
72
|
+
|
|
73
|
+
@ReactMethod
|
|
74
|
+
@DoNotStrip
|
|
75
|
+
public abstract void queryRenderedFeaturesInRect(@Nullable Double viewRef, ReadableArray withBBox, ReadableArray withFilter, ReadableArray withLayerIDs, Promise promise);
|
|
76
|
+
|
|
77
|
+
@ReactMethod
|
|
78
|
+
@DoNotStrip
|
|
79
|
+
public abstract void setHandledMapChangedEvents(@Nullable Double viewRef, ReadableArray events, Promise promise);
|
|
80
|
+
|
|
81
|
+
@ReactMethod
|
|
82
|
+
@DoNotStrip
|
|
83
|
+
public abstract void clearData(@Nullable Double viewRef, Promise promise);
|
|
84
|
+
|
|
85
|
+
@ReactMethod
|
|
86
|
+
@DoNotStrip
|
|
87
|
+
public abstract void querySourceFeatures(@Nullable Double viewRef, String sourceId, ReadableArray withFilter, ReadableArray withSourceLayerIDs, Promise promise);
|
|
88
|
+
}
|
|
@@ -10,11 +10,20 @@ class CustomHttpHeaders : HttpServiceInterceptorInterface {
|
|
|
10
10
|
var customHeaders : [String:String] = [:]
|
|
11
11
|
|
|
12
12
|
func install() {
|
|
13
|
+
#if RNMBX_11
|
|
14
|
+
HttpServiceFactory.setHttpServiceInterceptorForInterceptor(self)
|
|
15
|
+
#else
|
|
13
16
|
HttpServiceFactory.getInstance().setInterceptorForInterceptor(self)
|
|
17
|
+
#endif
|
|
14
18
|
}
|
|
15
19
|
|
|
16
20
|
func reset() {
|
|
21
|
+
#if RNMBX_11
|
|
22
|
+
HttpServiceFactory.setHttpServiceInterceptorForInterceptor(nil)
|
|
23
|
+
#else
|
|
17
24
|
HttpServiceFactory.getInstance().setInterceptorForInterceptor(nil)
|
|
25
|
+
|
|
26
|
+
#endif
|
|
18
27
|
}
|
|
19
28
|
|
|
20
29
|
// MARK: - HttpServiceInterceptorInterface
|
|
@@ -36,4 +45,13 @@ class CustomHttpHeaders : HttpServiceInterceptorInterface {
|
|
|
36
45
|
func onResponse(for response: HttpResponse) -> HttpResponse {
|
|
37
46
|
return response
|
|
38
47
|
}
|
|
48
|
+
|
|
49
|
+
#if RNMBX_11
|
|
50
|
+
func onUpload(forUpload upload: UploadOptions) -> UploadOptions {
|
|
51
|
+
customHeaders.forEach {(key,value) in
|
|
52
|
+
upload.headers[key] = value
|
|
53
|
+
}
|
|
54
|
+
return upload
|
|
55
|
+
}
|
|
56
|
+
#endif
|
|
39
57
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
2
|
+
|
|
3
|
+
#import <UIKit/UIKit.h>
|
|
4
|
+
|
|
5
|
+
#import <React/RCTUIManager.h>
|
|
6
|
+
#import <React/RCTViewComponentView.h>
|
|
7
|
+
|
|
8
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
9
|
+
|
|
10
|
+
@interface MBXMapViewComponentView : RCTViewComponentView
|
|
11
|
+
|
|
12
|
+
- (void)dispatchCameraChangedEvent:(NSDictionary*)event;
|
|
13
|
+
|
|
14
|
+
@end
|
|
15
|
+
|
|
16
|
+
NS_ASSUME_NONNULL_END
|
|
17
|
+
|
|
18
|
+
#endif // RCT_NEW_ARCH_ENABLED
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
2
|
+
|
|
3
|
+
#import "MBXMapViewComponentView.h"
|
|
4
|
+
|
|
5
|
+
#import <React/RCTConversions.h>
|
|
6
|
+
#import <React/RCTFabricComponentsPlugins.h>
|
|
7
|
+
|
|
8
|
+
#import <react/renderer/components/rnmapbox_maps_specs/ComponentDescriptors.h>
|
|
9
|
+
#import <react/renderer/components/rnmapbox_maps_specs/EventEmitters.h>
|
|
10
|
+
#import <react/renderer/components/rnmapbox_maps_specs/Props.h>
|
|
11
|
+
#import <react/renderer/components/rnmapbox_maps_specs/RCTComponentViewHelpers.h>
|
|
12
|
+
// needed for compilation for some reason
|
|
13
|
+
#import <CoreFoundation/CoreFoundation.h>
|
|
14
|
+
#import <CoreLocation/CoreLocation.h>
|
|
15
|
+
|
|
16
|
+
@interface MapView : UIView
|
|
17
|
+
@end
|
|
18
|
+
|
|
19
|
+
#import <rnmapbox_maps-Swift.h>
|
|
20
|
+
|
|
21
|
+
using namespace facebook::react;
|
|
22
|
+
|
|
23
|
+
@interface MBXMapViewComponentView () <RCTMBXMapViewViewProtocol>
|
|
24
|
+
@end
|
|
25
|
+
|
|
26
|
+
@interface MBXMapViewEventDispatcher : NSObject<RCTEventDispatcherProtocol>
|
|
27
|
+
@end
|
|
28
|
+
|
|
29
|
+
@implementation MBXMapViewEventDispatcher {
|
|
30
|
+
MBXMapViewComponentView* _componentView;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
- (instancetype)initWithComponentView:(MBXMapViewComponentView*)componentView {
|
|
34
|
+
if (self = [super init]) {
|
|
35
|
+
_componentView = componentView;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return self;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
- (void)sendEvent:(id<RCTEvent>)event {
|
|
42
|
+
NSDictionary* payload = [event arguments][2];
|
|
43
|
+
[_componentView dispatchCameraChangedEvent:payload];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@end
|
|
47
|
+
|
|
48
|
+
@implementation MBXMapViewComponentView {
|
|
49
|
+
MBXMapView *_view;
|
|
50
|
+
MBXMapViewEventDispatcher *_eventDispatcher;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
- (instancetype)initWithFrame:(CGRect)frame
|
|
54
|
+
{
|
|
55
|
+
if (self = [super initWithFrame:frame]) {
|
|
56
|
+
static const auto defaultProps = std::make_shared<const MBXMapViewProps>();
|
|
57
|
+
_props = defaultProps;
|
|
58
|
+
_eventDispatcher = [[MBXMapViewEventDispatcher alloc] initWithComponentView:self];
|
|
59
|
+
_view = [[MBXMapView alloc] initWithFrame:frame eventDispatcher:_eventDispatcher];
|
|
60
|
+
|
|
61
|
+
// just need to pass something, it won't really be used on fabric, but it's used to create events (it won't impact sending them)
|
|
62
|
+
_view.reactTag = @-1;
|
|
63
|
+
|
|
64
|
+
// capture weak self reference to prevent retain cycle
|
|
65
|
+
__weak __typeof__(self) weakSelf = self;
|
|
66
|
+
|
|
67
|
+
[_view setReactOnPress:^(NSDictionary* event) {
|
|
68
|
+
__typeof__(self) strongSelf = weakSelf;
|
|
69
|
+
|
|
70
|
+
if (strongSelf != nullptr && strongSelf->_eventEmitter != nullptr) {
|
|
71
|
+
const auto [type, json] = [MBXMapViewComponentView stringifyEventData:event];
|
|
72
|
+
std::dynamic_pointer_cast<const facebook::react::MBXMapViewEventEmitter>(strongSelf->_eventEmitter)->onPress({type, json});
|
|
73
|
+
}
|
|
74
|
+
}];
|
|
75
|
+
|
|
76
|
+
[_view setReactOnLongPress:^(NSDictionary* event) {
|
|
77
|
+
__typeof__(self) strongSelf = weakSelf;
|
|
78
|
+
|
|
79
|
+
if (strongSelf != nullptr && strongSelf->_eventEmitter != nullptr) {
|
|
80
|
+
const auto [type, json] = [MBXMapViewComponentView stringifyEventData:event];
|
|
81
|
+
std::dynamic_pointer_cast<const facebook::react::MBXMapViewEventEmitter>(strongSelf->_eventEmitter)->onLongPress({type, json});
|
|
82
|
+
}
|
|
83
|
+
}];
|
|
84
|
+
|
|
85
|
+
[_view setReactOnMapChange:^(NSDictionary* event) {
|
|
86
|
+
__typeof__(self) strongSelf = weakSelf;
|
|
87
|
+
|
|
88
|
+
if (strongSelf != nullptr && strongSelf->_eventEmitter != nullptr) {
|
|
89
|
+
const auto [type, json] = [MBXMapViewComponentView stringifyEventData:event];
|
|
90
|
+
std::dynamic_pointer_cast<const facebook::react::MBXMapViewEventEmitter>(strongSelf->_eventEmitter)->onMapChange({type, json});
|
|
91
|
+
}
|
|
92
|
+
}];
|
|
93
|
+
|
|
94
|
+
self.contentView = _view;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return self;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
- (void)dispatchCameraChangedEvent:(NSDictionary*)event {
|
|
101
|
+
const auto [type, json] = [MBXMapViewComponentView stringifyEventData:event];
|
|
102
|
+
std::dynamic_pointer_cast<const facebook::react::MBXMapViewEventEmitter>(self->_eventEmitter)->onCameraChanged({type, json});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
+ (std::tuple<std::string, std::string>)stringifyEventData:(NSDictionary*)event {
|
|
106
|
+
std::string type = [event valueForKey:@"type"] == nil ? "" : std::string([[event valueForKey:@"type"] UTF8String]);
|
|
107
|
+
std::string json = "{}";
|
|
108
|
+
|
|
109
|
+
NSError *error;
|
|
110
|
+
NSData *jsonData = nil;
|
|
111
|
+
|
|
112
|
+
if ([event valueForKey:@"payload"] != nil) {
|
|
113
|
+
jsonData = [NSJSONSerialization dataWithJSONObject:[event valueForKey:@"payload"]
|
|
114
|
+
options:0
|
|
115
|
+
error:&error];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (jsonData) {
|
|
119
|
+
json = std::string([[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding] UTF8String]);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return {type, json};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
- (NSDictionary*)convertPositionToDictionary:(const folly::dynamic*)position {
|
|
126
|
+
NSMutableDictionary<NSString*, NSNumber*>* result = [[NSMutableDictionary alloc] init];
|
|
127
|
+
|
|
128
|
+
if (!position->isNull()) {
|
|
129
|
+
for (auto& pair : position->items()) {
|
|
130
|
+
NSString* key = [NSString stringWithUTF8String:pair.first.getString().c_str()];
|
|
131
|
+
NSNumber* value = [[NSNumber alloc] initWithInt:pair.second.getDouble()];
|
|
132
|
+
[result setValue:value forKey:key];
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
- (NSDictionary*)convertLocalizeLabels:(const MBXMapViewLocalizeLabelsStruct*)labels {
|
|
140
|
+
NSMutableDictionary* result = [[NSMutableDictionary alloc] init];
|
|
141
|
+
NSMutableArray* ids = [[NSMutableArray alloc] init];
|
|
142
|
+
|
|
143
|
+
[result setValue:[NSString stringWithUTF8String:labels->locale.c_str()] forKey:@"locale"];
|
|
144
|
+
|
|
145
|
+
for (auto& layerId : labels->layerIds) {
|
|
146
|
+
NSString* value = [NSString stringWithUTF8String:layerId.c_str()];
|
|
147
|
+
[ids addObject:value];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
[result setValue:ids forKey:@"layerIds"];
|
|
151
|
+
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
#pragma mark - RCTComponentViewProtocol
|
|
157
|
+
|
|
158
|
+
+ (ComponentDescriptorProvider)componentDescriptorProvider
|
|
159
|
+
{
|
|
160
|
+
return concreteComponentDescriptorProvider<MBXMapViewComponentDescriptor>();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
- (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps
|
|
164
|
+
{
|
|
165
|
+
const auto &newProps = *std::static_pointer_cast<const MBXMapViewProps>(props);
|
|
166
|
+
[_view setReactAttributionEnabled:newProps.attributionEnabled];
|
|
167
|
+
[_view setReactAttributionPosition:[self convertPositionToDictionary:&newProps.attributionPosition]];
|
|
168
|
+
|
|
169
|
+
[_view setReactLogoEnabled:newProps.logoEnabled];
|
|
170
|
+
[_view setReactLogoPosition:[self convertPositionToDictionary:&newProps.logoPosition]];
|
|
171
|
+
|
|
172
|
+
[_view setReactCompassEnabled:newProps.compassEnabled];
|
|
173
|
+
[_view setReactCompassFadeWhenNorth:newProps.compassFadeWhenNorth];
|
|
174
|
+
[_view setReactCompassPosition:[self convertPositionToDictionary:&newProps.compassPosition]];
|
|
175
|
+
[_view setReactCompassViewPosition:newProps.compassViewPosition];
|
|
176
|
+
[_view setReactCompassViewMargins:CGPointMake(newProps.compassViewMargins.x, newProps.compassViewMargins.y)];
|
|
177
|
+
[_view setReactCompassImage:[NSString stringWithUTF8String:newProps.compassImage.c_str()]];
|
|
178
|
+
|
|
179
|
+
[_view setReactScaleBarEnabled:newProps.scaleBarEnabled];
|
|
180
|
+
[_view setReactScaleBarPosition:[self convertPositionToDictionary:&newProps.scaleBarPosition]];
|
|
181
|
+
|
|
182
|
+
[_view setReactZoomEnabled:newProps.zoomEnabled];
|
|
183
|
+
[_view setReactScrollEnabled:newProps.scrollEnabled];
|
|
184
|
+
[_view setReactRotateEnabled:newProps.rotateEnabled];
|
|
185
|
+
[_view setReactPitchEnabled:newProps.pitchEnabled];
|
|
186
|
+
|
|
187
|
+
[_view setReactProjection:newProps.projection == MBXMapViewProjection::Mercator ? @"mercator" : @"globe"];
|
|
188
|
+
[_view setReactStyleURL:[NSString stringWithUTF8String:newProps.styleURL.c_str()]];
|
|
189
|
+
|
|
190
|
+
if (!newProps.localizeLabels.locale.empty()) {
|
|
191
|
+
[_view setReactLocalizeLabels:[self convertLocalizeLabels:&newProps.localizeLabels]];
|
|
192
|
+
}
|
|
193
|
+
[super updateProps:props oldProps:oldProps];
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
@end
|
|
197
|
+
|
|
198
|
+
Class<RCTComponentViewProtocol> MBXMapViewCls(void)
|
|
199
|
+
{
|
|
200
|
+
return MBXMapViewComponentView.class;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
#endif // RCT_NEW_ARCH_ENABLED
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
|
2
|
+
#import <React/RCTViewManager.h>
|
|
3
|
+
|
|
4
|
+
@interface RCT_EXTERN_REMAP_MODULE(MBXMapView, MBXMapViewManager, RCTViewManager)
|
|
5
|
+
|
|
6
|
+
RCT_EXPORT_VIEW_PROPERTY(onCameraChanged, RCTDirectEventBlock)
|
|
7
|
+
|
|
8
|
+
RCT_REMAP_VIEW_PROPERTY(attributionEnabled, reactAttributionEnabled, BOOL)
|
|
9
|
+
RCT_REMAP_VIEW_PROPERTY(attributionPosition, reactAttributionPosition, NSDictionary)
|
|
10
|
+
|
|
11
|
+
RCT_REMAP_VIEW_PROPERTY(logoEnabled, reactLogoEnabled, BOOL)
|
|
12
|
+
RCT_REMAP_VIEW_PROPERTY(logoPosition, reactLogoPosition, NSDictionary)
|
|
13
|
+
|
|
14
|
+
RCT_REMAP_VIEW_PROPERTY(compassEnabled, reactCompassEnabled, BOOL)
|
|
15
|
+
RCT_REMAP_VIEW_PROPERTY(compassFadeWhenNorth, reactCompassFadeWhenNorth, BOOL)
|
|
16
|
+
RCT_REMAP_VIEW_PROPERTY(compassPosition, reactCompassPosition, NSDictionary)
|
|
17
|
+
RCT_REMAP_VIEW_PROPERTY(compassViewPosition, reactCompassViewPosition, NSInteger)
|
|
18
|
+
RCT_REMAP_VIEW_PROPERTY(compassViewMargins, reactCompassViewMargins, CGPoint)
|
|
19
|
+
RCT_REMAP_VIEW_PROPERTY(compassImage, reactCompassImage, NSString)
|
|
20
|
+
|
|
21
|
+
RCT_REMAP_VIEW_PROPERTY(scaleBarEnabled, reactScaleBarEnabled, BOOL)
|
|
22
|
+
RCT_REMAP_VIEW_PROPERTY(scaleBarPosition, reactScaleBarPosition, NSDictionary)
|
|
23
|
+
|
|
24
|
+
RCT_REMAP_VIEW_PROPERTY(zoomEnabled, reactZoomEnabled, BOOL)
|
|
25
|
+
RCT_REMAP_VIEW_PROPERTY(scrollEnabled, reactScrollEnabled, BOOL)
|
|
26
|
+
RCT_REMAP_VIEW_PROPERTY(rotateEnabled, reactRotateEnabled, BOOL)
|
|
27
|
+
RCT_REMAP_VIEW_PROPERTY(pitchEnabled, reactPitchEnabled, BOOL)
|
|
28
|
+
|
|
29
|
+
RCT_REMAP_VIEW_PROPERTY(projection, reactProjection, NSString)
|
|
30
|
+
RCT_REMAP_VIEW_PROPERTY(localizeLabels, reactLocalizeLabels, NSDictionary)
|
|
31
|
+
|
|
32
|
+
RCT_REMAP_VIEW_PROPERTY(styleURL, reactStyleURL, NSString)
|
|
33
|
+
RCT_REMAP_VIEW_PROPERTY(onPress, reactOnPress, RCTBubblingEventBlock)
|
|
34
|
+
RCT_REMAP_VIEW_PROPERTY(onLongPress, reactOnLongPress, RCTBubblingEventBlock)
|
|
35
|
+
RCT_REMAP_VIEW_PROPERTY(onMapChange, reactOnMapChange, RCTBubblingEventBlock)
|
|
36
|
+
|
|
37
|
+
@end
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import MapboxMaps
|
|
2
|
+
|
|
3
|
+
#if RNMBX_11
|
|
4
|
+
extension QueriedSourceFeature {
|
|
5
|
+
var feature: Feature { return self.queriedFeature.feature }
|
|
6
|
+
}
|
|
7
|
+
#endif
|
|
8
|
+
|
|
9
|
+
@objc(MBXMapViewManager)
|
|
10
|
+
public class MBXMapViewManager: RCTViewManager {
|
|
11
|
+
@objc
|
|
12
|
+
override public static func requiresMainQueueSetup() -> Bool {
|
|
13
|
+
return true
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
func defaultFrame() -> CGRect {
|
|
17
|
+
return UIScreen.main.bounds
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
override public func view() -> UIView! {
|
|
21
|
+
let result = RCTMGLMapView(frame: self.defaultFrame(), eventDispatcher: self.bridge.eventDispatcher())
|
|
22
|
+
return result
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// MARK: helpers
|
|
27
|
+
|
|
28
|
+
extension MBXMapViewManager {
|
|
29
|
+
static func withMapboxMap(
|
|
30
|
+
_ view: RCTMGLMapView,
|
|
31
|
+
name: String,
|
|
32
|
+
rejecter: @escaping RCTPromiseRejectBlock,
|
|
33
|
+
fn: @escaping (_: MapboxMap) -> Void) -> Void
|
|
34
|
+
{
|
|
35
|
+
guard let mapboxMap = view.mapboxMap else {
|
|
36
|
+
RCTMGLLogError("MapboxMap is not yet available");
|
|
37
|
+
rejecter(name, "Map not loaded yet", nil)
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
fn(mapboxMap)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// MARK: - react methods
|
|
46
|
+
|
|
47
|
+
extension MBXMapViewManager {
|
|
48
|
+
@objc public static func takeSnap(_ view: RCTMGLMapView,
|
|
49
|
+
writeToDisk: Bool,
|
|
50
|
+
resolver: @escaping RCTPromiseResolveBlock) {
|
|
51
|
+
let uri = view.takeSnap(writeToDisk: writeToDisk)
|
|
52
|
+
resolver(["uri": uri.absoluteString])
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@objc public static func queryTerrainElevation(_ view: RCTMGLMapView,
|
|
56
|
+
coordinates: [NSNumber],
|
|
57
|
+
resolver: @escaping RCTPromiseResolveBlock,
|
|
58
|
+
rejecter: @escaping RCTPromiseRejectBlock
|
|
59
|
+
) -> Void {
|
|
60
|
+
let result = view.queryTerrainElevation(coordinates: coordinates)
|
|
61
|
+
if let result = result {
|
|
62
|
+
resolver(["data": NSNumber(value: result)])
|
|
63
|
+
} else {
|
|
64
|
+
resolver(nil)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@objc public static func setSourceVisibility(_ view: RCTMGLMapView,
|
|
69
|
+
visible: Bool,
|
|
70
|
+
sourceId: String,
|
|
71
|
+
sourceLayerId: String?,
|
|
72
|
+
resolver: @escaping RCTPromiseResolveBlock,
|
|
73
|
+
rejecter: @escaping RCTPromiseRejectBlock) -> Void {
|
|
74
|
+
view.setSourceVisibility(visible, sourceId: sourceId, sourceLayerId:sourceLayerId)
|
|
75
|
+
resolver(nil)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@objc public static func getCenter(_ view: RCTMGLMapView, resolver: @escaping RCTPromiseResolveBlock, rejecter: @escaping RCTPromiseRejectBlock) {
|
|
79
|
+
withMapboxMap(view, name: "getCenter", rejecter:rejecter) { map in
|
|
80
|
+
resolver(["center": [
|
|
81
|
+
map.cameraState.center.longitude,
|
|
82
|
+
map.cameraState.center.latitude
|
|
83
|
+
]])
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@objc public static func getCoordinateFromView(
|
|
88
|
+
_ view: RCTMGLMapView,
|
|
89
|
+
atPoint point: CGPoint,
|
|
90
|
+
resolver: @escaping RCTPromiseResolveBlock,
|
|
91
|
+
rejecter: @escaping RCTPromiseRejectBlock) {
|
|
92
|
+
withMapboxMap(view, name: "getCoordinateFromView", rejecter:rejecter) { map in
|
|
93
|
+
let coordinates = map.coordinate(for: point)
|
|
94
|
+
resolver(["coordinateFromView": [coordinates.longitude, coordinates.latitude]])
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@objc public static func getPointInView(
|
|
100
|
+
_ view: RCTMGLMapView,
|
|
101
|
+
atCoordinate coordinate: [NSNumber],
|
|
102
|
+
resolver: @escaping RCTPromiseResolveBlock,
|
|
103
|
+
rejecter: @escaping RCTPromiseRejectBlock) {
|
|
104
|
+
withMapboxMap(view, name: "getPointInView", rejecter:rejecter) { map in
|
|
105
|
+
let coordinate = CLLocationCoordinate2DMake(coordinate[1].doubleValue, coordinate[0].doubleValue)
|
|
106
|
+
let point = map.point(for: coordinate)
|
|
107
|
+
resolver(["pointInView": [(point.x), (point.y)]])
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@objc public static func setHandledMapChangedEvents(
|
|
113
|
+
_ view: RCTMGLMapView,
|
|
114
|
+
events: [String],
|
|
115
|
+
resolver: @escaping RCTPromiseResolveBlock,
|
|
116
|
+
rejecter: @escaping RCTPromiseRejectBlock) {
|
|
117
|
+
view.handleMapChangedEvents = Set(events.compactMap {
|
|
118
|
+
RCTMGLEvent.EventType(rawValue: $0)
|
|
119
|
+
})
|
|
120
|
+
resolver(nil);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
@objc public static func getZoom(
|
|
124
|
+
_ view: RCTMGLMapView,
|
|
125
|
+
resolver: @escaping RCTPromiseResolveBlock,
|
|
126
|
+
rejecter: @escaping RCTPromiseRejectBlock) {
|
|
127
|
+
withMapboxMap(view, name: "getZoom", rejecter:rejecter) { map in
|
|
128
|
+
resolver(["zoom": map.cameraState.zoom])
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
@objc public static func getVisibleBounds(
|
|
134
|
+
_ view: RCTMGLMapView,
|
|
135
|
+
resolver: @escaping RCTPromiseResolveBlock) {
|
|
136
|
+
resolver(["visibleBounds": view.mapboxMap.coordinateBounds(for: view.bounds).toArray()])
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// MARK: - queryRenderedFeatures
|
|
142
|
+
|
|
143
|
+
extension MBXMapViewManager {
|
|
144
|
+
@objc public static func queryRenderedFeaturesAtPoint(
|
|
145
|
+
_ view: RCTMGLMapView,
|
|
146
|
+
atPoint point: [NSNumber],
|
|
147
|
+
withFilter filter: [Any]?,
|
|
148
|
+
withLayerIDs layerIDs: [String]?,
|
|
149
|
+
resolver: @escaping RCTPromiseResolveBlock,
|
|
150
|
+
rejecter: @escaping RCTPromiseRejectBlock) -> Void {
|
|
151
|
+
withMapboxMap(view, name: "queryRenderedFeaturesAtPoint", rejecter:rejecter) { map in
|
|
152
|
+
let point = CGPoint(x: CGFloat(point[0].floatValue), y: CGFloat(point[1].floatValue))
|
|
153
|
+
|
|
154
|
+
logged("queryRenderedFeaturesAtPoint.option", rejecter: rejecter) {
|
|
155
|
+
let options = try RenderedQueryOptions(layerIds: (layerIDs ?? []).isEmpty ? nil : layerIDs, filter: filter?.asExpression())
|
|
156
|
+
|
|
157
|
+
map.queryRenderedFeatures(with: point, options: options) { result in
|
|
158
|
+
switch result {
|
|
159
|
+
case .success(let features):
|
|
160
|
+
resolver([
|
|
161
|
+
"data": ["type": "FeatureCollection", "features": features.compactMap { queriedFeature in
|
|
162
|
+
logged("queryRenderedFeaturesAtPoint.feature.toJSON") { try queriedFeature.feature.toJSON() }
|
|
163
|
+
}]
|
|
164
|
+
])
|
|
165
|
+
case .failure(let error):
|
|
166
|
+
rejecter("queryRenderedFeaturesAtPoint","failed to query features", error)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
@objc public static func queryRenderedFeaturesInRect(
|
|
175
|
+
_ map: RCTMGLMapView,
|
|
176
|
+
withBBox bbox: [NSNumber],
|
|
177
|
+
withFilter filter: [Any]?,
|
|
178
|
+
withLayerIDs layerIDs: [String]?,
|
|
179
|
+
resolver: @escaping RCTPromiseResolveBlock,
|
|
180
|
+
rejecter: @escaping RCTPromiseRejectBlock) -> Void {
|
|
181
|
+
let top = bbox.isEmpty ? 0.0 : CGFloat(bbox[0].floatValue)
|
|
182
|
+
let right = bbox.isEmpty ? 0.0 : CGFloat(bbox[1].floatValue)
|
|
183
|
+
let bottom = bbox.isEmpty ? 0.0 : CGFloat(bbox[2].floatValue)
|
|
184
|
+
let left = bbox.isEmpty ? 0.0 : CGFloat(bbox[3].floatValue)
|
|
185
|
+
let rect = bbox.isEmpty ? CGRect(x: 0.0, y: 0.0, width: map.bounds.size.width, height: map.bounds.size.height) : CGRect(x: [left,right].min()!, y: [top,bottom].min()!, width: abs(right-left), height: abs(bottom-top))
|
|
186
|
+
logged("queryRenderedFeaturesInRect.option", rejecter: rejecter) {
|
|
187
|
+
let options = try RenderedQueryOptions(layerIds: layerIDs?.isEmpty ?? true ? nil : layerIDs, filter: filter?.asExpression())
|
|
188
|
+
map.mapboxMap.queryRenderedFeatures(with: rect, options: options) { result in
|
|
189
|
+
switch result {
|
|
190
|
+
case .success(let features):
|
|
191
|
+
resolver([
|
|
192
|
+
"data": ["type": "FeatureCollection", "features": features.compactMap { queriedFeature in
|
|
193
|
+
logged("queryRenderedFeaturesInRect.queriedfeature.map") { try queriedFeature.feature.toJSON() }
|
|
194
|
+
}]
|
|
195
|
+
])
|
|
196
|
+
case .failure(let error):
|
|
197
|
+
rejecter("queryRenderedFeaturesInRect","failed to query features", error)
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
@objc public static func querySourceFeatures(
|
|
204
|
+
_ map: RCTMGLMapView,
|
|
205
|
+
withSourceId sourceId: String,
|
|
206
|
+
withFilter filter: [Any]?,
|
|
207
|
+
withSourceLayerIds sourceLayerIds: [String]?,
|
|
208
|
+
resolver: @escaping RCTPromiseResolveBlock,
|
|
209
|
+
rejecter: @escaping RCTPromiseRejectBlock) -> Void {
|
|
210
|
+
let sourceLayerIds = sourceLayerIds?.isEmpty ?? true ? nil : sourceLayerIds
|
|
211
|
+
logged("querySourceFeatures.option", rejecter: rejecter) {
|
|
212
|
+
let options = SourceQueryOptions(sourceLayerIds: sourceLayerIds, filter: filter ?? Exp(arguments: []))
|
|
213
|
+
map.mapboxMap.querySourceFeatures(for: sourceId, options: options) { result in
|
|
214
|
+
switch result {
|
|
215
|
+
case .success(let features):
|
|
216
|
+
resolver([
|
|
217
|
+
"data": ["type": "FeatureCollection", "features": features.compactMap { queriedFeature in
|
|
218
|
+
logged("querySourceFeatures.queriedfeature.map") { try queriedFeature.feature.toJSON() }
|
|
219
|
+
}] as [String : Any]
|
|
220
|
+
])
|
|
221
|
+
case .failure(let error):
|
|
222
|
+
rejecter("querySourceFeatures", "failed to query source features: \(error.localizedDescription)", error)
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
static func clearData(_ view: RCTMGLMapView, completion: @escaping (Error?) -> Void) {
|
|
229
|
+
#if RNMBX_11
|
|
230
|
+
MapboxMap.clearData(completion: completion)
|
|
231
|
+
#else
|
|
232
|
+
view.mapboxMap.clearData(completion: completion)
|
|
233
|
+
#endif
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
@objc public static func clearData(
|
|
237
|
+
_ mapView: RCTMGLMapView,
|
|
238
|
+
resolver:@escaping RCTPromiseResolveBlock,
|
|
239
|
+
rejecter:@escaping RCTPromiseRejectBlock
|
|
240
|
+
) {
|
|
241
|
+
self.clearData(mapView) { error in
|
|
242
|
+
if let error = error {
|
|
243
|
+
rejecter("clearData","failed to clearData: \(error.localizedDescription)", error)
|
|
244
|
+
} else {
|
|
245
|
+
resolver(nil)
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <UIKit/UIKit.h>
|
|
3
|
+
|
|
4
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
5
|
+
#import "rnmapbox_maps_specs.h"
|
|
6
|
+
#else
|
|
7
|
+
#import <React/RCTBridge.h>
|
|
8
|
+
#endif
|
|
9
|
+
|
|
10
|
+
@interface MBXMapViewModule : NSObject
|
|
11
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
12
|
+
<NativeMapViewModuleSpec>
|
|
13
|
+
#else
|
|
14
|
+
<RCTBridgeModule>
|
|
15
|
+
#endif
|
|
16
|
+
|
|
17
|
+
@end
|
|
18
|
+
|