@maplibre/maplibre-react-native 11.0.0-alpha.42 → 11.0.0-alpha.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/android/build.gradle +1 -3
- package/android/src/main/java/org/maplibre/reactnative/MLRNPackage.kt +3 -3
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/callout/MLRNCallout.kt +7 -0
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/callout/MLRNCalloutManager.kt +29 -0
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/markerview/MLRNMarkerView.kt +220 -0
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/markerview/MLRNMarkerViewContent.kt +50 -0
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/markerview/MLRNMarkerViewManager.kt +81 -0
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/markerview/MarkerViewManager.kt +127 -0
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/pointannotation/MLRNPointAnnotation.kt +407 -0
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/pointannotation/MLRNPointAnnotationManager.kt +105 -0
- package/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapView.kt +38 -37
- package/android/src/main/java/org/maplibre/reactnative/events/PointAnnotationClickEvent.java +1 -1
- package/android/src/main/java/org/maplibre/reactnative/events/PointAnnotationDragEvent.java +1 -1
- package/android/src/main/java/org/maplibre/reactnative/events/PointAnnotationEvent.kt +30 -0
- package/ios/components/annotations/callout/MLRNCalloutComponentView.h +10 -0
- package/ios/components/annotations/callout/MLRNCalloutComponentView.mm +91 -0
- package/ios/components/annotations/point-annotation/MLRNPointAnnotation.h +44 -0
- package/ios/components/annotations/{MLRNPointAnnotation.m → point-annotation/MLRNPointAnnotation.m} +69 -35
- package/ios/components/annotations/point-annotation/MLRNPointAnnotationComponentView.h +10 -0
- package/ios/components/annotations/point-annotation/MLRNPointAnnotationComponentView.mm +331 -0
- package/ios/components/map-view/MLRNMapView.m +4 -5
- package/lib/commonjs/components/annotations/callout/Callout.js +94 -0
- package/lib/commonjs/components/annotations/callout/Callout.js.map +1 -0
- package/lib/commonjs/components/annotations/callout/CalloutNativeComponent.ts +11 -0
- package/lib/commonjs/components/annotations/marker-view/MarkerView.js +70 -0
- package/lib/commonjs/components/annotations/marker-view/MarkerView.js.map +1 -0
- package/lib/commonjs/components/annotations/marker-view/MarkerViewNativeComponent.ts +30 -0
- package/lib/commonjs/components/annotations/point-annotation/PointAnnotation.js +88 -0
- package/lib/commonjs/components/annotations/point-annotation/PointAnnotation.js.map +1 -0
- package/lib/commonjs/components/annotations/point-annotation/PointAnnotationNativeComponent.ts +58 -0
- package/lib/commonjs/index.js +3 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types/Anchor.js +68 -0
- package/lib/commonjs/types/Anchor.js.map +1 -0
- package/lib/commonjs/utils/animated/Animated.js +4 -0
- package/lib/commonjs/utils/animated/Animated.js.map +1 -1
- package/lib/module/components/annotations/callout/Callout.js +88 -0
- package/lib/module/components/annotations/callout/Callout.js.map +1 -0
- package/lib/module/components/annotations/callout/CalloutNativeComponent.ts +11 -0
- package/lib/module/components/annotations/marker-view/MarkerView.js +64 -0
- package/lib/module/components/annotations/marker-view/MarkerView.js.map +1 -0
- package/lib/module/components/annotations/marker-view/MarkerViewNativeComponent.ts +30 -0
- package/lib/module/components/annotations/point-annotation/PointAnnotation.js +83 -0
- package/lib/module/components/annotations/point-annotation/PointAnnotation.js.map +1 -0
- package/lib/module/components/annotations/point-annotation/PointAnnotationNativeComponent.ts +58 -0
- package/lib/module/index.js +3 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/types/Anchor.js +64 -0
- package/lib/module/types/Anchor.js.map +1 -0
- package/lib/module/utils/animated/Animated.js +4 -0
- package/lib/module/utils/animated/Animated.js.map +1 -1
- package/lib/typescript/{module/src/components/annotations → commonjs/src/components/annotations/callout}/Callout.d.ts +9 -9
- package/lib/typescript/commonjs/src/components/annotations/callout/Callout.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/annotations/callout/CalloutNativeComponent.d.ts +6 -0
- package/lib/typescript/commonjs/src/components/annotations/callout/CalloutNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/annotations/marker-view/MarkerView.d.ts +52 -0
- package/lib/typescript/commonjs/src/components/annotations/marker-view/MarkerView.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/annotations/marker-view/MarkerViewNativeComponent.d.ts +21 -0
- package/lib/typescript/commonjs/src/components/annotations/marker-view/MarkerViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/annotations/point-annotation/PointAnnotation.d.ts +95 -0
- package/lib/typescript/commonjs/src/components/annotations/point-annotation/PointAnnotation.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/annotations/point-annotation/PointAnnotationNativeComponent.d.ts +43 -0
- package/lib/typescript/commonjs/src/components/annotations/point-annotation/PointAnnotationNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +4 -4
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/Anchor.d.ts +17 -0
- package/lib/typescript/commonjs/src/types/Anchor.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/utils/animated/Animated.d.ts +1 -0
- package/lib/typescript/commonjs/src/utils/animated/Animated.d.ts.map +1 -1
- package/lib/typescript/{commonjs/src/components/annotations → module/src/components/annotations/callout}/Callout.d.ts +9 -9
- package/lib/typescript/module/src/components/annotations/callout/Callout.d.ts.map +1 -0
- package/lib/typescript/module/src/components/annotations/callout/CalloutNativeComponent.d.ts +6 -0
- package/lib/typescript/module/src/components/annotations/callout/CalloutNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/components/annotations/marker-view/MarkerView.d.ts +52 -0
- package/lib/typescript/module/src/components/annotations/marker-view/MarkerView.d.ts.map +1 -0
- package/lib/typescript/module/src/components/annotations/marker-view/MarkerViewNativeComponent.d.ts +21 -0
- package/lib/typescript/module/src/components/annotations/marker-view/MarkerViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/components/annotations/point-annotation/PointAnnotation.d.ts +95 -0
- package/lib/typescript/module/src/components/annotations/point-annotation/PointAnnotation.d.ts.map +1 -0
- package/lib/typescript/module/src/components/annotations/point-annotation/PointAnnotationNativeComponent.d.ts +43 -0
- package/lib/typescript/module/src/components/annotations/point-annotation/PointAnnotationNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +4 -4
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/types/Anchor.d.ts +17 -0
- package/lib/typescript/module/src/types/Anchor.d.ts.map +1 -0
- package/lib/typescript/module/src/utils/animated/Animated.d.ts +1 -0
- package/lib/typescript/module/src/utils/animated/Animated.d.ts.map +1 -1
- package/package.json +3 -1
- package/src/components/annotations/callout/Callout.tsx +145 -0
- package/src/components/annotations/callout/CalloutNativeComponent.ts +11 -0
- package/src/components/annotations/marker-view/MarkerView.tsx +124 -0
- package/src/components/annotations/marker-view/MarkerViewNativeComponent.ts +30 -0
- package/src/components/annotations/point-annotation/PointAnnotation.tsx +219 -0
- package/src/components/annotations/point-annotation/PointAnnotationNativeComponent.ts +58 -0
- package/src/index.ts +15 -4
- package/src/types/Anchor.ts +44 -0
- package/src/utils/animated/Animated.tsx +6 -0
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/MLRNCallout.java +0 -11
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/MLRNCalloutManager.java +0 -18
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/MLRNMarkerView.java +0 -112
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/MLRNMarkerViewManager.java +0 -45
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/MLRNPointAnnotation.java +0 -361
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/MLRNPointAnnotationManager.java +0 -84
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/MarkerView.java +0 -23
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/MarkerViewManager.java +0 -69
- package/ios/components/annotations/MLRNCalloutManager.h +0 -5
- package/ios/components/annotations/MLRNCalloutManager.m +0 -12
- package/ios/components/annotations/MLRNPointAnnotation.h +0 -33
- package/ios/components/annotations/MLRNPointAnnotationManager.h +0 -5
- package/ios/components/annotations/MLRNPointAnnotationManager.m +0 -27
- package/lib/commonjs/components/annotations/Callout.js +0 -101
- package/lib/commonjs/components/annotations/Callout.js.map +0 -1
- package/lib/commonjs/components/annotations/MarkerView.js +0 -60
- package/lib/commonjs/components/annotations/MarkerView.js.map +0 -1
- package/lib/commonjs/components/annotations/PointAnnotation.js +0 -114
- package/lib/commonjs/components/annotations/PointAnnotation.js.map +0 -1
- package/lib/module/components/annotations/Callout.js +0 -96
- package/lib/module/components/annotations/Callout.js.map +0 -1
- package/lib/module/components/annotations/MarkerView.js +0 -55
- package/lib/module/components/annotations/MarkerView.js.map +0 -1
- package/lib/module/components/annotations/PointAnnotation.js +0 -110
- package/lib/module/components/annotations/PointAnnotation.js.map +0 -1
- package/lib/typescript/commonjs/src/components/annotations/Callout.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/components/annotations/MarkerView.d.ts +0 -44
- package/lib/typescript/commonjs/src/components/annotations/MarkerView.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/components/annotations/PointAnnotation.d.ts +0 -90
- package/lib/typescript/commonjs/src/components/annotations/PointAnnotation.d.ts.map +0 -1
- package/lib/typescript/module/src/components/annotations/Callout.d.ts.map +0 -1
- package/lib/typescript/module/src/components/annotations/MarkerView.d.ts +0 -44
- package/lib/typescript/module/src/components/annotations/MarkerView.d.ts.map +0 -1
- package/lib/typescript/module/src/components/annotations/PointAnnotation.d.ts +0 -90
- package/lib/typescript/module/src/components/annotations/PointAnnotation.d.ts.map +0 -1
- package/src/components/annotations/Callout.tsx +0 -139
- package/src/components/annotations/MarkerView.tsx +0 -86
- package/src/components/annotations/PointAnnotation.tsx +0 -240
- /package/ios/components/annotations/{MLRNCallout.h → callout/MLRNCallout.h} +0 -0
- /package/ios/components/annotations/{MLRNCallout.m → callout/MLRNCallout.m} +0 -0
package/android/src/main/java/org/maplibre/reactnative/events/PointAnnotationClickEvent.java
CHANGED
|
@@ -7,7 +7,7 @@ import com.facebook.react.bridge.WritableMap;
|
|
|
7
7
|
import com.facebook.react.bridge.WritableNativeMap;
|
|
8
8
|
|
|
9
9
|
import org.maplibre.android.geometry.LatLng;
|
|
10
|
-
import org.maplibre.reactnative.components.annotations.MLRNPointAnnotation;
|
|
10
|
+
import org.maplibre.reactnative.components.annotations.pointannotation.MLRNPointAnnotation;
|
|
11
11
|
import org.maplibre.reactnative.events.constants.EventKeys;
|
|
12
12
|
import org.maplibre.reactnative.events.constants.EventTypes;
|
|
13
13
|
import org.maplibre.reactnative.utils.GeoJSONUtils;
|
|
@@ -7,7 +7,7 @@ import com.facebook.react.bridge.WritableMap;
|
|
|
7
7
|
import com.facebook.react.bridge.WritableNativeMap;
|
|
8
8
|
|
|
9
9
|
import org.maplibre.android.geometry.LatLng;
|
|
10
|
-
import org.maplibre.reactnative.components.annotations.MLRNPointAnnotation;
|
|
10
|
+
import org.maplibre.reactnative.components.annotations.pointannotation.MLRNPointAnnotation;
|
|
11
11
|
import org.maplibre.reactnative.events.constants.EventKeys;
|
|
12
12
|
import org.maplibre.reactnative.events.constants.EventTypes;
|
|
13
13
|
import org.maplibre.reactnative.utils.GeoJSONUtils;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
package org.maplibre.reactnative.events
|
|
2
|
+
|
|
3
|
+
import android.graphics.PointF
|
|
4
|
+
import com.facebook.react.bridge.Arguments
|
|
5
|
+
import com.facebook.react.bridge.WritableMap
|
|
6
|
+
import com.facebook.react.uimanager.events.Event
|
|
7
|
+
import org.maplibre.android.geometry.LatLng
|
|
8
|
+
import org.maplibre.reactnative.utils.GeoJSONUtils
|
|
9
|
+
|
|
10
|
+
class PointAnnotationEvent(
|
|
11
|
+
surfaceId: Int,
|
|
12
|
+
viewId: Int,
|
|
13
|
+
private val internalEventName: String,
|
|
14
|
+
private val annotationId: String?,
|
|
15
|
+
private val latLng: LatLng,
|
|
16
|
+
private val screenPoint: PointF,
|
|
17
|
+
) : Event<PointAnnotationEvent>(surfaceId, viewId) {
|
|
18
|
+
override fun getEventName() = internalEventName
|
|
19
|
+
|
|
20
|
+
override fun getEventData(): WritableMap {
|
|
21
|
+
return Arguments.createMap().apply {
|
|
22
|
+
putString("id", annotationId ?: "")
|
|
23
|
+
putArray("lngLat", GeoJSONUtils.fromLatLng(latLng))
|
|
24
|
+
putArray("point", Arguments.createArray().apply {
|
|
25
|
+
pushDouble(screenPoint.x.toDouble())
|
|
26
|
+
pushDouble(screenPoint.y.toDouble())
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#import "MLRNCalloutComponentView.h"
|
|
2
|
+
|
|
3
|
+
#import <react/renderer/components/MapLibreReactNativeSpec/ComponentDescriptors.h>
|
|
4
|
+
#import <react/renderer/components/MapLibreReactNativeSpec/EventEmitters.h>
|
|
5
|
+
#import <react/renderer/components/MapLibreReactNativeSpec/Props.h>
|
|
6
|
+
#import <react/renderer/components/MapLibreReactNativeSpec/RCTComponentViewHelpers.h>
|
|
7
|
+
|
|
8
|
+
#import "RCTFabricComponentsPlugins.h"
|
|
9
|
+
|
|
10
|
+
#import <React/RCTConversions.h>
|
|
11
|
+
#import "MLRNCallout.h"
|
|
12
|
+
|
|
13
|
+
using namespace facebook::react;
|
|
14
|
+
|
|
15
|
+
// MARK: - MLRNCalloutComponentView
|
|
16
|
+
|
|
17
|
+
@interface MLRNCalloutComponentView () <RCTMLRNCalloutViewProtocol>
|
|
18
|
+
|
|
19
|
+
@end
|
|
20
|
+
|
|
21
|
+
@implementation MLRNCalloutComponentView {
|
|
22
|
+
MLRNCallout *_view;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
+ (BOOL)shouldBeRecycled {
|
|
26
|
+
return NO;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
- (UIView *)contentView {
|
|
30
|
+
// Return _view so PointAnnotation's mountChildComponentView can detect this as a Callout
|
|
31
|
+
// via: [contentView isKindOfClass:[MLRNCallout class]]
|
|
32
|
+
return _view;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
- (instancetype)initWithFrame:(CGRect)frame {
|
|
36
|
+
if (self = [super initWithFrame:frame]) {
|
|
37
|
+
static const auto defaultProps = std::make_shared<const MLRNCalloutProps>();
|
|
38
|
+
_props = defaultProps;
|
|
39
|
+
[self prepareView];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return self;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
- (void)prepareView {
|
|
46
|
+
_view = [[MLRNCallout alloc] init];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
#pragma mark - Child Mounting
|
|
50
|
+
|
|
51
|
+
- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView
|
|
52
|
+
index:(NSInteger)index {
|
|
53
|
+
// Add children to _view (the MLRNCallout) so they're visible when presented
|
|
54
|
+
// This includes the Animated.View with title/content that React renders
|
|
55
|
+
[_view insertSubview:childComponentView atIndex:index];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView
|
|
59
|
+
index:(NSInteger)index {
|
|
60
|
+
[childComponentView removeFromSuperview];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
- (void)updateLayoutMetrics:(const facebook::react::LayoutMetrics &)layoutMetrics
|
|
64
|
+
oldLayoutMetrics:(const facebook::react::LayoutMetrics &)oldLayoutMetrics {
|
|
65
|
+
[super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics];
|
|
66
|
+
|
|
67
|
+
// Forward layout to _view so the callout has the correct size
|
|
68
|
+
CGRect frame = CGRectMake(
|
|
69
|
+
layoutMetrics.frame.origin.x,
|
|
70
|
+
layoutMetrics.frame.origin.y,
|
|
71
|
+
layoutMetrics.frame.size.width,
|
|
72
|
+
layoutMetrics.frame.size.height
|
|
73
|
+
);
|
|
74
|
+
_view.frame = frame;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
#pragma mark - RCTComponentViewProtocol
|
|
78
|
+
|
|
79
|
+
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps {
|
|
80
|
+
[super updateProps:props oldProps:oldProps];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
+ (ComponentDescriptorProvider)componentDescriptorProvider {
|
|
84
|
+
return concreteComponentDescriptorProvider<MLRNCalloutComponentDescriptor>();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@end
|
|
88
|
+
|
|
89
|
+
Class<RCTComponentViewProtocol> MLRNCalloutCls(void) {
|
|
90
|
+
return MLRNCalloutComponentView.class;
|
|
91
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#import <React/RCTComponent.h>
|
|
2
|
+
#import <React/RCTView.h>
|
|
3
|
+
#import <UIKit/UIKit.h>
|
|
4
|
+
#import "MLRNCallout.h"
|
|
5
|
+
|
|
6
|
+
#import <MapLibre/MapLibre.h>
|
|
7
|
+
|
|
8
|
+
@interface MLRNPointAnnotation : MLNAnnotationView <MLNAnnotation>
|
|
9
|
+
|
|
10
|
+
@property (nonatomic, weak) MLNMapView *map;
|
|
11
|
+
@property (nonatomic, strong) MLRNCallout *calloutView;
|
|
12
|
+
|
|
13
|
+
@property (nonatomic, copy) NSString *id;
|
|
14
|
+
@property (nonatomic, copy) NSString *reactTitle;
|
|
15
|
+
@property (nonatomic, copy) NSString *reactSnippet;
|
|
16
|
+
|
|
17
|
+
@property (nonatomic, copy) NSArray<NSNumber *> *reactLngLat;
|
|
18
|
+
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
|
|
19
|
+
|
|
20
|
+
@property (nonatomic, copy) NSDictionary<NSString *, NSNumber *> *anchor;
|
|
21
|
+
@property (nonatomic, copy) NSDictionary<NSString *, NSNumber *> *offset;
|
|
22
|
+
|
|
23
|
+
@property (nonatomic, copy) void (^reactOnSelected)(NSDictionary *event);
|
|
24
|
+
@property (nonatomic, copy) void (^reactOnDeselected)(NSDictionary *event);
|
|
25
|
+
@property (nonatomic, copy) void (^reactOnDragStart)(NSDictionary *event);
|
|
26
|
+
@property (nonatomic, copy) void (^reactOnDrag)(NSDictionary *event);
|
|
27
|
+
@property (nonatomic, copy) void (^reactOnDragEnd)(NSDictionary *event);
|
|
28
|
+
|
|
29
|
+
@property (nonatomic, assign) BOOL reactSelected;
|
|
30
|
+
@property (nonatomic, assign) BOOL reactDraggable;
|
|
31
|
+
@property (nonatomic, assign) BOOL hasExplicitZIndex;
|
|
32
|
+
@property (nonatomic, assign) CGFloat explicitZIndex;
|
|
33
|
+
|
|
34
|
+
// For Fabric: track custom child count without adding to view hierarchy
|
|
35
|
+
@property (nonatomic, assign) NSInteger customChildCount;
|
|
36
|
+
|
|
37
|
+
- (MLNAnnotationView *)getAnnotationView;
|
|
38
|
+
- (NSDictionary *)makeEventPayload;
|
|
39
|
+
- (void)setZIndex:(CGFloat)zIndex;
|
|
40
|
+
|
|
41
|
+
- (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex;
|
|
42
|
+
- (void)removeReactSubview:(UIView *)subview;
|
|
43
|
+
|
|
44
|
+
@end
|
package/ios/components/annotations/{MLRNPointAnnotation.m → point-annotation/MLRNPointAnnotation.m}
RENAMED
|
@@ -49,6 +49,11 @@ const float CENTER_Y_OFFSET_BASE = -0.5f;
|
|
|
49
49
|
[self _setCenterOffset:self.frame];
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
- (void)setOffset:(NSDictionary<NSString *, NSNumber *> *)offset {
|
|
53
|
+
_offset = offset;
|
|
54
|
+
[self _setCenterOffset:self.frame];
|
|
55
|
+
}
|
|
56
|
+
|
|
52
57
|
- (void)setMap:(MLNMapView *)map {
|
|
53
58
|
if (map == nil) {
|
|
54
59
|
[_map removeAnnotation:self];
|
|
@@ -83,8 +88,8 @@ const float CENTER_Y_OFFSET_BASE = -0.5f;
|
|
|
83
88
|
self.draggable = _reactDraggable;
|
|
84
89
|
}
|
|
85
90
|
|
|
86
|
-
- (void)
|
|
87
|
-
|
|
91
|
+
- (void)setReactLngLat:(NSArray<NSNumber *> *)reactLngLat {
|
|
92
|
+
_reactLngLat = reactLngLat;
|
|
88
93
|
[self _updateCoordinate];
|
|
89
94
|
}
|
|
90
95
|
|
|
@@ -104,16 +109,28 @@ const float CENTER_Y_OFFSET_BASE = -0.5f;
|
|
|
104
109
|
return _reactTitle;
|
|
105
110
|
}
|
|
106
111
|
|
|
112
|
+
- (void)setZIndex:(CGFloat)zIndex {
|
|
113
|
+
_hasExplicitZIndex = YES;
|
|
114
|
+
_explicitZIndex = zIndex;
|
|
115
|
+
self.layer.zPosition = zIndex;
|
|
116
|
+
}
|
|
117
|
+
|
|
107
118
|
- (MLNAnnotationView *)getAnnotationView {
|
|
108
|
-
|
|
119
|
+
// Check both reactSubviews (old arch) and customChildCount (Fabric)
|
|
120
|
+
BOOL hasCustomChildren = (self.reactSubviews.count > 0) || (self.customChildCount > 0);
|
|
121
|
+
|
|
122
|
+
if (!hasCustomChildren) {
|
|
109
123
|
// default pin view
|
|
110
124
|
return nil;
|
|
111
125
|
} else {
|
|
112
126
|
// custom view
|
|
113
127
|
self.enabled = YES;
|
|
114
|
-
|
|
115
|
-
if (
|
|
116
|
-
|
|
128
|
+
// Only use latitude-based zPosition if no explicit zIndex was set
|
|
129
|
+
if (!_hasExplicitZIndex) {
|
|
130
|
+
const CGFloat defaultZPosition = 0.0;
|
|
131
|
+
if (self.layer.zPosition == defaultZPosition) {
|
|
132
|
+
self.layer.zPosition = [self _getZPosition];
|
|
133
|
+
}
|
|
117
134
|
}
|
|
118
135
|
[self addGestureRecognizer:customViewTap];
|
|
119
136
|
return self;
|
|
@@ -130,45 +147,54 @@ const float CENTER_Y_OFFSET_BASE = -0.5f;
|
|
|
130
147
|
}
|
|
131
148
|
|
|
132
149
|
- (void)_setCenterOffset:(CGRect)frame {
|
|
133
|
-
if (frame.size.width == 0 || frame.size.height == 0
|
|
150
|
+
if (frame.size.width == 0 || frame.size.height == 0) {
|
|
134
151
|
return;
|
|
135
152
|
}
|
|
136
153
|
|
|
137
|
-
float
|
|
138
|
-
float
|
|
154
|
+
float dx = 0;
|
|
155
|
+
float dy = 0;
|
|
156
|
+
|
|
157
|
+
// Apply anchor offset (anchor is a percentage of view dimensions)
|
|
158
|
+
if (_anchor != nil) {
|
|
159
|
+
float x = [_anchor[@"x"] floatValue];
|
|
160
|
+
float y = [_anchor[@"y"] floatValue];
|
|
139
161
|
|
|
140
|
-
|
|
141
|
-
|
|
162
|
+
dx = -(x * frame.size.width - (frame.size.width / 2));
|
|
163
|
+
dy = -(y * frame.size.height - (frame.size.height / 2));
|
|
142
164
|
|
|
143
|
-
|
|
165
|
+
// special cases 0 and 1
|
|
166
|
+
if (x == 0) {
|
|
167
|
+
dx = frame.size.width / 2;
|
|
168
|
+
} else if (x == 1) {
|
|
169
|
+
dx = -frame.size.width / 2;
|
|
170
|
+
}
|
|
144
171
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
172
|
+
if (y == 0) {
|
|
173
|
+
dy = frame.size.height / 2;
|
|
174
|
+
} else if (y == 1) {
|
|
175
|
+
dy = -frame.size.height / 2;
|
|
176
|
+
}
|
|
149
177
|
}
|
|
150
178
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
dy
|
|
179
|
+
// Apply pixel offset
|
|
180
|
+
if (_offset != nil) {
|
|
181
|
+
dx += [_offset[@"x"] floatValue];
|
|
182
|
+
dy += [_offset[@"y"] floatValue];
|
|
155
183
|
}
|
|
156
184
|
|
|
157
185
|
self.centerOffset = CGVectorMake(dx, dy);
|
|
158
186
|
}
|
|
159
187
|
|
|
160
188
|
- (void)_updateCoordinate {
|
|
161
|
-
if (
|
|
189
|
+
if (_reactLngLat == nil || _reactLngLat.count < 2) {
|
|
162
190
|
return;
|
|
163
191
|
}
|
|
164
192
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
193
|
+
double lng = [_reactLngLat[0] doubleValue];
|
|
194
|
+
double lat = [_reactLngLat[1] doubleValue];
|
|
169
195
|
|
|
170
196
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
171
|
-
self.coordinate =
|
|
197
|
+
self.coordinate = CLLocationCoordinate2DMake(lat, lng);
|
|
172
198
|
});
|
|
173
199
|
}
|
|
174
200
|
|
|
@@ -187,29 +213,37 @@ const float CENTER_Y_OFFSET_BASE = -0.5f;
|
|
|
187
213
|
return self.frame.size.width > 0 && self.frame.size.height > 0;
|
|
188
214
|
}
|
|
189
215
|
|
|
216
|
+
- (NSDictionary *)makeEventPayload {
|
|
217
|
+
NSMutableDictionary *payload = [NSMutableDictionary dictionary];
|
|
218
|
+
payload[@"id"] = _id ?: @"";
|
|
219
|
+
payload[@"lngLat"] = @[@(self.coordinate.longitude), @(self.coordinate.latitude)];
|
|
220
|
+
|
|
221
|
+
CGPoint screenPoint = [_map convertCoordinate:self.coordinate toPointToView:_map];
|
|
222
|
+
payload[@"point"] = @[@(screenPoint.x), @(screenPoint.y)];
|
|
223
|
+
|
|
224
|
+
return payload;
|
|
225
|
+
}
|
|
226
|
+
|
|
190
227
|
- (void)setDragState:(MLNAnnotationViewDragState)dragState animated:(BOOL)animated {
|
|
191
228
|
[super setDragState:dragState animated:animated];
|
|
192
229
|
switch (dragState) {
|
|
193
230
|
case MLNAnnotationViewDragStateStarting: {
|
|
194
|
-
if (self.
|
|
195
|
-
|
|
196
|
-
self.onDragStart([event toJSON]);
|
|
231
|
+
if (self.reactOnDragStart != nil) {
|
|
232
|
+
self.reactOnDragStart([self makeEventPayload]);
|
|
197
233
|
}
|
|
198
234
|
break;
|
|
199
235
|
}
|
|
200
236
|
|
|
201
237
|
case MLNAnnotationViewDragStateDragging:
|
|
202
|
-
if (self.
|
|
203
|
-
|
|
204
|
-
self.onDrag([event toJSON]);
|
|
238
|
+
if (self.reactOnDrag != nil) {
|
|
239
|
+
self.reactOnDrag([self makeEventPayload]);
|
|
205
240
|
}
|
|
206
241
|
break;
|
|
207
242
|
|
|
208
243
|
case MLNAnnotationViewDragStateEnding:
|
|
209
244
|
case MLNAnnotationViewDragStateCanceling: {
|
|
210
|
-
if (self.
|
|
211
|
-
|
|
212
|
-
self.onDragEnd([event toJSON]);
|
|
245
|
+
if (self.reactOnDragEnd != nil) {
|
|
246
|
+
self.reactOnDragEnd([self makeEventPayload]);
|
|
213
247
|
}
|
|
214
248
|
break;
|
|
215
249
|
}
|