@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.
Files changed (137) hide show
  1. package/android/build.gradle +1 -3
  2. package/android/src/main/java/org/maplibre/reactnative/MLRNPackage.kt +3 -3
  3. package/android/src/main/java/org/maplibre/reactnative/components/annotations/callout/MLRNCallout.kt +7 -0
  4. package/android/src/main/java/org/maplibre/reactnative/components/annotations/callout/MLRNCalloutManager.kt +29 -0
  5. package/android/src/main/java/org/maplibre/reactnative/components/annotations/markerview/MLRNMarkerView.kt +220 -0
  6. package/android/src/main/java/org/maplibre/reactnative/components/annotations/markerview/MLRNMarkerViewContent.kt +50 -0
  7. package/android/src/main/java/org/maplibre/reactnative/components/annotations/markerview/MLRNMarkerViewManager.kt +81 -0
  8. package/android/src/main/java/org/maplibre/reactnative/components/annotations/markerview/MarkerViewManager.kt +127 -0
  9. package/android/src/main/java/org/maplibre/reactnative/components/annotations/pointannotation/MLRNPointAnnotation.kt +407 -0
  10. package/android/src/main/java/org/maplibre/reactnative/components/annotations/pointannotation/MLRNPointAnnotationManager.kt +105 -0
  11. package/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapView.kt +38 -37
  12. package/android/src/main/java/org/maplibre/reactnative/events/PointAnnotationClickEvent.java +1 -1
  13. package/android/src/main/java/org/maplibre/reactnative/events/PointAnnotationDragEvent.java +1 -1
  14. package/android/src/main/java/org/maplibre/reactnative/events/PointAnnotationEvent.kt +30 -0
  15. package/ios/components/annotations/callout/MLRNCalloutComponentView.h +10 -0
  16. package/ios/components/annotations/callout/MLRNCalloutComponentView.mm +91 -0
  17. package/ios/components/annotations/point-annotation/MLRNPointAnnotation.h +44 -0
  18. package/ios/components/annotations/{MLRNPointAnnotation.m → point-annotation/MLRNPointAnnotation.m} +69 -35
  19. package/ios/components/annotations/point-annotation/MLRNPointAnnotationComponentView.h +10 -0
  20. package/ios/components/annotations/point-annotation/MLRNPointAnnotationComponentView.mm +331 -0
  21. package/ios/components/map-view/MLRNMapView.m +4 -5
  22. package/lib/commonjs/components/annotations/callout/Callout.js +94 -0
  23. package/lib/commonjs/components/annotations/callout/Callout.js.map +1 -0
  24. package/lib/commonjs/components/annotations/callout/CalloutNativeComponent.ts +11 -0
  25. package/lib/commonjs/components/annotations/marker-view/MarkerView.js +70 -0
  26. package/lib/commonjs/components/annotations/marker-view/MarkerView.js.map +1 -0
  27. package/lib/commonjs/components/annotations/marker-view/MarkerViewNativeComponent.ts +30 -0
  28. package/lib/commonjs/components/annotations/point-annotation/PointAnnotation.js +88 -0
  29. package/lib/commonjs/components/annotations/point-annotation/PointAnnotation.js.map +1 -0
  30. package/lib/commonjs/components/annotations/point-annotation/PointAnnotationNativeComponent.ts +58 -0
  31. package/lib/commonjs/index.js +3 -3
  32. package/lib/commonjs/index.js.map +1 -1
  33. package/lib/commonjs/types/Anchor.js +68 -0
  34. package/lib/commonjs/types/Anchor.js.map +1 -0
  35. package/lib/commonjs/utils/animated/Animated.js +4 -0
  36. package/lib/commonjs/utils/animated/Animated.js.map +1 -1
  37. package/lib/module/components/annotations/callout/Callout.js +88 -0
  38. package/lib/module/components/annotations/callout/Callout.js.map +1 -0
  39. package/lib/module/components/annotations/callout/CalloutNativeComponent.ts +11 -0
  40. package/lib/module/components/annotations/marker-view/MarkerView.js +64 -0
  41. package/lib/module/components/annotations/marker-view/MarkerView.js.map +1 -0
  42. package/lib/module/components/annotations/marker-view/MarkerViewNativeComponent.ts +30 -0
  43. package/lib/module/components/annotations/point-annotation/PointAnnotation.js +83 -0
  44. package/lib/module/components/annotations/point-annotation/PointAnnotation.js.map +1 -0
  45. package/lib/module/components/annotations/point-annotation/PointAnnotationNativeComponent.ts +58 -0
  46. package/lib/module/index.js +3 -3
  47. package/lib/module/index.js.map +1 -1
  48. package/lib/module/types/Anchor.js +64 -0
  49. package/lib/module/types/Anchor.js.map +1 -0
  50. package/lib/module/utils/animated/Animated.js +4 -0
  51. package/lib/module/utils/animated/Animated.js.map +1 -1
  52. package/lib/typescript/{module/src/components/annotations → commonjs/src/components/annotations/callout}/Callout.d.ts +9 -9
  53. package/lib/typescript/commonjs/src/components/annotations/callout/Callout.d.ts.map +1 -0
  54. package/lib/typescript/commonjs/src/components/annotations/callout/CalloutNativeComponent.d.ts +6 -0
  55. package/lib/typescript/commonjs/src/components/annotations/callout/CalloutNativeComponent.d.ts.map +1 -0
  56. package/lib/typescript/commonjs/src/components/annotations/marker-view/MarkerView.d.ts +52 -0
  57. package/lib/typescript/commonjs/src/components/annotations/marker-view/MarkerView.d.ts.map +1 -0
  58. package/lib/typescript/commonjs/src/components/annotations/marker-view/MarkerViewNativeComponent.d.ts +21 -0
  59. package/lib/typescript/commonjs/src/components/annotations/marker-view/MarkerViewNativeComponent.d.ts.map +1 -0
  60. package/lib/typescript/commonjs/src/components/annotations/point-annotation/PointAnnotation.d.ts +95 -0
  61. package/lib/typescript/commonjs/src/components/annotations/point-annotation/PointAnnotation.d.ts.map +1 -0
  62. package/lib/typescript/commonjs/src/components/annotations/point-annotation/PointAnnotationNativeComponent.d.ts +43 -0
  63. package/lib/typescript/commonjs/src/components/annotations/point-annotation/PointAnnotationNativeComponent.d.ts.map +1 -0
  64. package/lib/typescript/commonjs/src/index.d.ts +4 -4
  65. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  66. package/lib/typescript/commonjs/src/types/Anchor.d.ts +17 -0
  67. package/lib/typescript/commonjs/src/types/Anchor.d.ts.map +1 -0
  68. package/lib/typescript/commonjs/src/utils/animated/Animated.d.ts +1 -0
  69. package/lib/typescript/commonjs/src/utils/animated/Animated.d.ts.map +1 -1
  70. package/lib/typescript/{commonjs/src/components/annotations → module/src/components/annotations/callout}/Callout.d.ts +9 -9
  71. package/lib/typescript/module/src/components/annotations/callout/Callout.d.ts.map +1 -0
  72. package/lib/typescript/module/src/components/annotations/callout/CalloutNativeComponent.d.ts +6 -0
  73. package/lib/typescript/module/src/components/annotations/callout/CalloutNativeComponent.d.ts.map +1 -0
  74. package/lib/typescript/module/src/components/annotations/marker-view/MarkerView.d.ts +52 -0
  75. package/lib/typescript/module/src/components/annotations/marker-view/MarkerView.d.ts.map +1 -0
  76. package/lib/typescript/module/src/components/annotations/marker-view/MarkerViewNativeComponent.d.ts +21 -0
  77. package/lib/typescript/module/src/components/annotations/marker-view/MarkerViewNativeComponent.d.ts.map +1 -0
  78. package/lib/typescript/module/src/components/annotations/point-annotation/PointAnnotation.d.ts +95 -0
  79. package/lib/typescript/module/src/components/annotations/point-annotation/PointAnnotation.d.ts.map +1 -0
  80. package/lib/typescript/module/src/components/annotations/point-annotation/PointAnnotationNativeComponent.d.ts +43 -0
  81. package/lib/typescript/module/src/components/annotations/point-annotation/PointAnnotationNativeComponent.d.ts.map +1 -0
  82. package/lib/typescript/module/src/index.d.ts +4 -4
  83. package/lib/typescript/module/src/index.d.ts.map +1 -1
  84. package/lib/typescript/module/src/types/Anchor.d.ts +17 -0
  85. package/lib/typescript/module/src/types/Anchor.d.ts.map +1 -0
  86. package/lib/typescript/module/src/utils/animated/Animated.d.ts +1 -0
  87. package/lib/typescript/module/src/utils/animated/Animated.d.ts.map +1 -1
  88. package/package.json +3 -1
  89. package/src/components/annotations/callout/Callout.tsx +145 -0
  90. package/src/components/annotations/callout/CalloutNativeComponent.ts +11 -0
  91. package/src/components/annotations/marker-view/MarkerView.tsx +124 -0
  92. package/src/components/annotations/marker-view/MarkerViewNativeComponent.ts +30 -0
  93. package/src/components/annotations/point-annotation/PointAnnotation.tsx +219 -0
  94. package/src/components/annotations/point-annotation/PointAnnotationNativeComponent.ts +58 -0
  95. package/src/index.ts +15 -4
  96. package/src/types/Anchor.ts +44 -0
  97. package/src/utils/animated/Animated.tsx +6 -0
  98. package/android/src/main/java/org/maplibre/reactnative/components/annotations/MLRNCallout.java +0 -11
  99. package/android/src/main/java/org/maplibre/reactnative/components/annotations/MLRNCalloutManager.java +0 -18
  100. package/android/src/main/java/org/maplibre/reactnative/components/annotations/MLRNMarkerView.java +0 -112
  101. package/android/src/main/java/org/maplibre/reactnative/components/annotations/MLRNMarkerViewManager.java +0 -45
  102. package/android/src/main/java/org/maplibre/reactnative/components/annotations/MLRNPointAnnotation.java +0 -361
  103. package/android/src/main/java/org/maplibre/reactnative/components/annotations/MLRNPointAnnotationManager.java +0 -84
  104. package/android/src/main/java/org/maplibre/reactnative/components/annotations/MarkerView.java +0 -23
  105. package/android/src/main/java/org/maplibre/reactnative/components/annotations/MarkerViewManager.java +0 -69
  106. package/ios/components/annotations/MLRNCalloutManager.h +0 -5
  107. package/ios/components/annotations/MLRNCalloutManager.m +0 -12
  108. package/ios/components/annotations/MLRNPointAnnotation.h +0 -33
  109. package/ios/components/annotations/MLRNPointAnnotationManager.h +0 -5
  110. package/ios/components/annotations/MLRNPointAnnotationManager.m +0 -27
  111. package/lib/commonjs/components/annotations/Callout.js +0 -101
  112. package/lib/commonjs/components/annotations/Callout.js.map +0 -1
  113. package/lib/commonjs/components/annotations/MarkerView.js +0 -60
  114. package/lib/commonjs/components/annotations/MarkerView.js.map +0 -1
  115. package/lib/commonjs/components/annotations/PointAnnotation.js +0 -114
  116. package/lib/commonjs/components/annotations/PointAnnotation.js.map +0 -1
  117. package/lib/module/components/annotations/Callout.js +0 -96
  118. package/lib/module/components/annotations/Callout.js.map +0 -1
  119. package/lib/module/components/annotations/MarkerView.js +0 -55
  120. package/lib/module/components/annotations/MarkerView.js.map +0 -1
  121. package/lib/module/components/annotations/PointAnnotation.js +0 -110
  122. package/lib/module/components/annotations/PointAnnotation.js.map +0 -1
  123. package/lib/typescript/commonjs/src/components/annotations/Callout.d.ts.map +0 -1
  124. package/lib/typescript/commonjs/src/components/annotations/MarkerView.d.ts +0 -44
  125. package/lib/typescript/commonjs/src/components/annotations/MarkerView.d.ts.map +0 -1
  126. package/lib/typescript/commonjs/src/components/annotations/PointAnnotation.d.ts +0 -90
  127. package/lib/typescript/commonjs/src/components/annotations/PointAnnotation.d.ts.map +0 -1
  128. package/lib/typescript/module/src/components/annotations/Callout.d.ts.map +0 -1
  129. package/lib/typescript/module/src/components/annotations/MarkerView.d.ts +0 -44
  130. package/lib/typescript/module/src/components/annotations/MarkerView.d.ts.map +0 -1
  131. package/lib/typescript/module/src/components/annotations/PointAnnotation.d.ts +0 -90
  132. package/lib/typescript/module/src/components/annotations/PointAnnotation.d.ts.map +0 -1
  133. package/src/components/annotations/Callout.tsx +0 -139
  134. package/src/components/annotations/MarkerView.tsx +0 -86
  135. package/src/components/annotations/PointAnnotation.tsx +0 -240
  136. /package/ios/components/annotations/{MLRNCallout.h → callout/MLRNCallout.h} +0 -0
  137. /package/ios/components/annotations/{MLRNCallout.m → callout/MLRNCallout.m} +0 -0
@@ -0,0 +1,219 @@
1
+ import {
2
+ Children,
3
+ Component,
4
+ type ComponentProps,
5
+ forwardRef,
6
+ isValidElement,
7
+ type ReactElement,
8
+ useImperativeHandle,
9
+ useRef,
10
+ } from "react";
11
+ import {
12
+ type NativeMethods,
13
+ type NativeSyntheticEvent,
14
+ Platform,
15
+ StyleSheet,
16
+ View,
17
+ type ViewProps,
18
+ } from "react-native";
19
+
20
+ import PointAnnotationNativeComponent, {
21
+ Commands,
22
+ } from "./PointAnnotationNativeComponent";
23
+ import { useFrozenId } from "../../../hooks/useFrozenId";
24
+ import { type Anchor, anchorToNative } from "../../../types/Anchor";
25
+ import type { LngLat } from "../../../types/LngLat";
26
+ import type { PixelPoint } from "../../../types/PixelPoint";
27
+ import type { PressEvent } from "../../../types/PressEvent";
28
+ import { Callout } from "../callout/Callout";
29
+
30
+ const styles = StyleSheet.create({
31
+ container: {
32
+ alignItems: "center",
33
+ justifyContent: "center",
34
+ position: "absolute",
35
+ },
36
+ });
37
+
38
+ export type AnnotationEvent = PressEvent & {
39
+ id: string;
40
+ };
41
+
42
+ export interface PointAnnotationProps {
43
+ /**
44
+ * A string that uniquely identifies the annotation.
45
+ * If not provided, a unique ID will be generated automatically.
46
+ */
47
+ id?: string;
48
+
49
+ /**
50
+ * The string containing the annotation's title. Note this is required to be set if you want to see a callout appear on iOS.
51
+ */
52
+ title?: string;
53
+
54
+ /**
55
+ * The string containing the annotation's snippet(subtitle). Not displayed in the default callout.
56
+ */
57
+ snippet?: string;
58
+
59
+ /**
60
+ * Manually selects/deselects annotation
61
+ */
62
+ selected?: boolean;
63
+
64
+ /**
65
+ * Enable or disable dragging. Defaults to false.
66
+ */
67
+ draggable?: boolean;
68
+
69
+ /**
70
+ * The center point (specified as a map coordinate) of the annotation.
71
+ */
72
+ lngLat: LngLat;
73
+
74
+ /**
75
+ * Specifies the anchor being set on a particular point of the annotation.
76
+ * The anchor indicates which part of the marker should be placed closest to the coordinate.
77
+ * Defaults to "center".
78
+ *
79
+ * @see https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/PositionAnchor/
80
+ */
81
+ anchor?: Anchor;
82
+
83
+ /**
84
+ * The offset in pixels to apply relative to the anchor.
85
+ * Negative values indicate left and up.
86
+ *
87
+ * @see https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MarkerOptions/#offset
88
+ */
89
+ offset?: PixelPoint;
90
+
91
+ /**
92
+ * This callback is fired once this annotation is selected.
93
+ */
94
+ onSelected?: (event: NativeSyntheticEvent<AnnotationEvent>) => void;
95
+
96
+ /**
97
+ * This callback is fired once this annotation is deselected.
98
+ */
99
+ onDeselected?: (event: NativeSyntheticEvent<AnnotationEvent>) => void;
100
+
101
+ /**
102
+ * This callback is fired once this annotation has started being dragged.
103
+ */
104
+ onDragStart?: (event: NativeSyntheticEvent<AnnotationEvent>) => void;
105
+
106
+ /**
107
+ * This callback is fired once this annotation has stopped being dragged.
108
+ */
109
+ onDragEnd?: (event: NativeSyntheticEvent<AnnotationEvent>) => void;
110
+
111
+ /**
112
+ * This callback is fired while this annotation is being dragged.
113
+ */
114
+ onDrag?: (event: NativeSyntheticEvent<AnnotationEvent>) => void;
115
+
116
+ /**
117
+ * Expects one child, and an optional callout can be added as well
118
+ */
119
+ children: ReactElement | [ReactElement, ReactElement];
120
+
121
+ style?: ViewProps["style"];
122
+ }
123
+
124
+ export interface PointAnnotationRef {
125
+ /**
126
+ * On android point annotation is rendered offscreen with a canvas into an image.
127
+ * To rerender the image from the current state of the view call refresh.
128
+ * Call this for example from Image#onLoad.
129
+ */
130
+ refresh(): void;
131
+ }
132
+
133
+ /**
134
+ * PointAnnotation represents a one-dimensional shape located at a single geographical coordinate.
135
+ *
136
+ * Consider using GeoJSONSource and SymbolLayer instead, if you have many points, and you have static images,
137
+ * they'll offer much better performance.
138
+ *
139
+ * If you need interactive views please use MarkerView,
140
+ * as with PointAnnotation on Android child views are rendered onto a bitmap for better performance.
141
+ */
142
+ export const PointAnnotation = forwardRef<
143
+ PointAnnotationRef,
144
+ PointAnnotationProps
145
+ >(
146
+ (
147
+ {
148
+ id,
149
+ anchor = "center",
150
+ draggable = false,
151
+ offset,
152
+ ...props
153
+ }: PointAnnotationProps,
154
+ ref,
155
+ ) => {
156
+ const frozenId = useFrozenId(id);
157
+ const nativeAnchor = anchorToNative(anchor);
158
+ const nativeOffset = offset ? { x: offset[0], y: offset[1] } : undefined;
159
+ const nativeRef = useRef<
160
+ Component<ComponentProps<typeof PointAnnotationNativeComponent>> &
161
+ Readonly<NativeMethods>
162
+ >(null);
163
+
164
+ useImperativeHandle(
165
+ ref,
166
+ (): PointAnnotationRef => ({
167
+ refresh,
168
+ }),
169
+ );
170
+
171
+ function refresh(): void {
172
+ if (Platform.OS === "android" && nativeRef.current) {
173
+ Commands.refresh(nativeRef.current);
174
+ }
175
+ }
176
+
177
+ // On Android, wrap children in a non-collapsable View to prevent Fabric
178
+ // from flattening the view hierarchy. Without this, Fabric may flatten
179
+ // intermediate Views, causing their backgrounds to disappear.
180
+ // We need to keep Callout separate so native code can identify it.
181
+ const wrappedChildren = (() => {
182
+ if (Platform.OS !== "android") {
183
+ return props.children;
184
+ }
185
+
186
+ // Separate Callout from other children so native can identify it
187
+ const childArray = Children.toArray(props.children);
188
+ const callout = childArray.find(
189
+ (child) => isValidElement(child) && child.type === Callout,
190
+ );
191
+ const otherChildren = childArray.filter(
192
+ (child) => !isValidElement(child) || child.type !== Callout,
193
+ );
194
+
195
+ return (
196
+ <>
197
+ <View collapsable={false} style={{ overflow: "visible" }}>
198
+ {otherChildren}
199
+ </View>
200
+ {callout}
201
+ </>
202
+ );
203
+ })();
204
+
205
+ return (
206
+ <PointAnnotationNativeComponent
207
+ ref={nativeRef}
208
+ {...props}
209
+ id={frozenId}
210
+ anchor={nativeAnchor}
211
+ offset={nativeOffset}
212
+ draggable={draggable}
213
+ style={[props.style, styles.container]}
214
+ >
215
+ {wrappedChildren}
216
+ </PointAnnotationNativeComponent>
217
+ );
218
+ },
219
+ );
@@ -0,0 +1,58 @@
1
+ import {
2
+ codegenNativeCommands,
3
+ codegenNativeComponent,
4
+ type CodegenTypes,
5
+ type HostComponent,
6
+ type ViewProps,
7
+ } from "react-native";
8
+
9
+ import type { UnsafeMixed } from "../../../types/codegen/UnsafeMixed";
10
+
11
+ type NativeAnchor = {
12
+ x: CodegenTypes.Double;
13
+ y: CodegenTypes.Double;
14
+ };
15
+
16
+ type NativeOffset = {
17
+ x: CodegenTypes.Double;
18
+ y: CodegenTypes.Double;
19
+ };
20
+
21
+ type NativeAnnotationEvent = {
22
+ id: string;
23
+ lngLat: UnsafeMixed<
24
+ [longitude: CodegenTypes.Double, latitude: CodegenTypes.Double]
25
+ >;
26
+ point: UnsafeMixed<[x: CodegenTypes.Double, y: CodegenTypes.Double]>;
27
+ };
28
+
29
+ export interface NativeProps extends ViewProps {
30
+ id: string;
31
+ title?: string;
32
+ snippet?: string;
33
+ selected?: CodegenTypes.WithDefault<boolean, false>;
34
+ draggable?: CodegenTypes.WithDefault<boolean, false>;
35
+ lngLat: UnsafeMixed<
36
+ [longitude: CodegenTypes.Double, latitude: CodegenTypes.Double]
37
+ >;
38
+ anchor?: NativeAnchor;
39
+ offset?: NativeOffset;
40
+
41
+ onSelected?: CodegenTypes.DirectEventHandler<NativeAnnotationEvent>;
42
+ onDeselected?: CodegenTypes.DirectEventHandler<NativeAnnotationEvent>;
43
+ onDragStart?: CodegenTypes.DirectEventHandler<NativeAnnotationEvent>;
44
+ onDrag?: CodegenTypes.DirectEventHandler<NativeAnnotationEvent>;
45
+ onDragEnd?: CodegenTypes.DirectEventHandler<NativeAnnotationEvent>;
46
+ }
47
+
48
+ interface NativeCommands {
49
+ refresh: (viewRef: React.ElementRef<HostComponent<NativeProps>>) => void;
50
+ }
51
+
52
+ export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
53
+ supportedCommands: ["refresh"],
54
+ });
55
+
56
+ export default codegenNativeComponent<NativeProps>(
57
+ "MLRNPointAnnotation",
58
+ ) as HostComponent<NativeProps>;
package/src/index.ts CHANGED
@@ -23,10 +23,17 @@ export {
23
23
  MapView,
24
24
  } from "./components/map-view/MapView";
25
25
 
26
- export { PointAnnotation } from "./components/annotations/PointAnnotation";
27
- export type { PointAnnotationRef } from "./components/annotations/PointAnnotation";
26
+ export {
27
+ PointAnnotation,
28
+ type PointAnnotationProps,
29
+ type PointAnnotationRef,
30
+ type AnnotationEvent,
31
+ } from "./components/annotations/point-annotation/PointAnnotation";
28
32
  export { GeoJSONSourceAnnotation } from "./components/annotations/GeoJSONSourceAnnotation";
29
- export { Callout } from "./components/annotations/Callout";
33
+ export {
34
+ Callout,
35
+ type CalloutProps,
36
+ } from "./components/annotations/callout/Callout";
30
37
 
31
38
  export { UserLocation } from "./components/user-location/UserLocation";
32
39
  export { NativeUserLocation } from "./components/user-location/NativeUserLocation";
@@ -76,7 +83,10 @@ export {
76
83
  Images,
77
84
  } from "./components/images/Images";
78
85
 
79
- export { MarkerView } from "./components/annotations/MarkerView";
86
+ export {
87
+ MarkerView,
88
+ type MarkerViewProps,
89
+ } from "./components/annotations/marker-view/MarkerView";
80
90
 
81
91
  export {
82
92
  LocationManager,
@@ -108,6 +118,7 @@ export {
108
118
  type StaticMapCreateOptions,
109
119
  } from "./modules/static-map/StaticMapManager";
110
120
 
121
+ export type { Anchor } from "./types/Anchor";
111
122
  export type { LngLat } from "./types/LngLat";
112
123
  export type { LngLatBounds } from "./types/LngLatBounds";
113
124
  export type {
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Position anchor for markers and annotations.
3
+ * Follows MapLibre GL JS PositionAnchor format.
4
+ *
5
+ * @see https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/PositionAnchor/
6
+ */
7
+ export type Anchor =
8
+ | "center"
9
+ | "top"
10
+ | "bottom"
11
+ | "left"
12
+ | "right"
13
+ | "top-left"
14
+ | "top-right"
15
+ | "bottom-left"
16
+ | "bottom-right";
17
+
18
+ /**
19
+ * Converts an Anchor string to native {x, y} format.
20
+ * x: 0 = left, 0.5 = center, 1 = right
21
+ * y: 0 = top, 0.5 = center, 1 = bottom
22
+ */
23
+ export function anchorToNative(anchor: Anchor): { x: number; y: number } {
24
+ switch (anchor) {
25
+ case "center":
26
+ return { x: 0.5, y: 0.5 };
27
+ case "top":
28
+ return { x: 0.5, y: 0 };
29
+ case "bottom":
30
+ return { x: 0.5, y: 1 };
31
+ case "left":
32
+ return { x: 0, y: 0.5 };
33
+ case "right":
34
+ return { x: 1, y: 0.5 };
35
+ case "top-left":
36
+ return { x: 0, y: 0 };
37
+ case "top-right":
38
+ return { x: 1, y: 0 };
39
+ case "bottom-left":
40
+ return { x: 0, y: 1 };
41
+ case "bottom-right":
42
+ return { x: 1, y: 1 };
43
+ }
44
+ }
@@ -5,12 +5,14 @@ import { AnimatedCoordinatesArray } from "./AnimatedCoordinatesArray";
5
5
  import { AnimatedExtractCoordinateFromArray } from "./AnimatedExtractCoordinateFromArray";
6
6
  import { AnimatedGeoJSON } from "./AnimatedGeoJSON";
7
7
  import { AnimatedRouteCoordinatesArray } from "./AnimatedRouteCoordinatesArray";
8
+ import { MarkerView } from "../../components/annotations/marker-view/MarkerView";
8
9
  import { Layer } from "../../components/layers/Layer";
9
10
  import { GeoJSONSource } from "../../components/sources/geojson-source/GeoJSONSource";
10
11
  import { ImageSource } from "../../components/sources/image-source/ImageSource";
11
12
 
12
13
  export const Animated = {
13
14
  // Components
15
+
14
16
  GeoJSONSource: RNAnimated.createAnimatedComponent(
15
17
  GeoJSONSource as unknown as ComponentType<
16
18
  Omit<ComponentProps<typeof GeoJSONSource>, "data"> & {
@@ -19,9 +21,13 @@ export const Animated = {
19
21
  >,
20
22
  ),
21
23
  ImageSource: RNAnimated.createAnimatedComponent(ImageSource),
24
+
25
+ MarkerView: RNAnimated.createAnimatedComponent(MarkerView),
26
+
22
27
  Layer: RNAnimated.createAnimatedComponent(Layer),
23
28
 
24
29
  // Values
30
+
25
31
  CoordinatesArray: AnimatedCoordinatesArray,
26
32
  RouteCoordinatesArray: AnimatedRouteCoordinatesArray,
27
33
  GeoJSON: AnimatedGeoJSON,
@@ -1,11 +0,0 @@
1
- package org.maplibre.reactnative.components.annotations;
2
-
3
- import android.content.Context;
4
-
5
- import com.facebook.react.views.view.ReactViewGroup;
6
-
7
- public class MLRNCallout extends ReactViewGroup {
8
- public MLRNCallout(Context context) {
9
- super(context);
10
- }
11
- }
@@ -1,18 +0,0 @@
1
- package org.maplibre.reactnative.components.annotations;
2
-
3
- import com.facebook.react.uimanager.ThemedReactContext;
4
- import com.facebook.react.uimanager.ViewGroupManager;
5
-
6
- public class MLRNCalloutManager extends ViewGroupManager<MLRNCallout> {
7
- public static final String REACT_CLASS = "MLRNCallout";
8
-
9
- @Override
10
- public String getName() {
11
- return REACT_CLASS;
12
- }
13
-
14
- @Override
15
- protected MLRNCallout createViewInstance(ThemedReactContext reactContext) {
16
- return new MLRNCallout(reactContext);
17
- }
18
- }
@@ -1,112 +0,0 @@
1
- package org.maplibre.reactnative.components.annotations;
2
-
3
- import android.content.Context;
4
- import android.graphics.PointF;
5
- import android.view.View;
6
-
7
- import androidx.annotation.NonNull;
8
-
9
- import org.maplibre.geojson.Point;
10
- import org.maplibre.android.maps.MapLibreMap;
11
- import org.maplibre.android.maps.OnMapReadyCallback;
12
- import org.maplibre.reactnative.components.AbstractMapFeature;
13
- import org.maplibre.reactnative.components.mapview.MLRNMapView;
14
- import org.maplibre.reactnative.utils.GeoJSONUtils;
15
-
16
- public class MLRNMarkerView extends AbstractMapFeature implements MarkerView.OnPositionUpdateListener, View.OnLayoutChangeListener {
17
- private MLRNMarkerViewManager mManager;
18
- private MLRNMapView mMapView;
19
-
20
- private View mChildView;
21
-
22
- private MarkerViewManager mMarkerViewManager;
23
-
24
- private MarkerView mMarkerView;
25
- private Point mCoordinate;
26
- private Float[] mAnchor;
27
-
28
-
29
- public MLRNMarkerView(Context context, MLRNMarkerViewManager manager) {
30
- super(context);
31
- mManager = manager;
32
- }
33
-
34
- @Override
35
- public void addView(View childView, int childPosition) {
36
- mChildView = childView;
37
- }
38
-
39
- public void setCoordinate(Point point) {
40
- mCoordinate = point;
41
-
42
- if (mMarkerView != null) {
43
- mMarkerView.setLatLng(GeoJSONUtils.toLatLng(point));
44
- }
45
- }
46
-
47
- public void setAnchor(float x, float y) {
48
- mAnchor = new Float[]{x, y};
49
- refresh();
50
- }
51
-
52
- public void refresh() {
53
- // this will cause position to be recalculated
54
- if (mMarkerView != null) {
55
- mMarkerView.setLatLng(GeoJSONUtils.toLatLng(mCoordinate));
56
- }
57
- }
58
-
59
- @Override
60
- public void addToMap(MLRNMapView mapView) {
61
- mMapView = mapView;
62
-
63
- final MLRNMarkerView mlrnMarkerView = this;
64
-
65
- mMapView.getMapAsync(
66
- new OnMapReadyCallback() {
67
- @Override
68
- public void onMapReady(@NonNull MapLibreMap mapLibreMap) {
69
- mMarkerViewManager = mMapView.getMarkerViewManager(mapLibreMap);
70
-
71
- if (mChildView != null) {
72
- mMarkerView = new MarkerView(GeoJSONUtils.toLatLng(mCoordinate), mChildView);
73
- mMarkerView.setOnPositionUpdateListener(mlrnMarkerView);
74
- mChildView.addOnLayoutChangeListener(mlrnMarkerView);
75
- mMarkerViewManager.addMarker(mMarkerView);
76
- }
77
- }
78
- }
79
- );
80
- }
81
-
82
- @Override
83
- public PointF onUpdate(PointF pointF) {
84
- if (mAnchor != null) {
85
- return new PointF(
86
- pointF.x - mChildView.getWidth() * mAnchor[0],
87
- pointF.y - mChildView.getHeight() * mAnchor[1]
88
- );
89
- }
90
- return pointF;
91
- }
92
-
93
- @Override
94
- public void removeFromMap(MLRNMapView mapView) {
95
- if (mMarkerView != null) {
96
- mMarkerViewManager.removeMarker(mMarkerView);
97
- mChildView.removeOnLayoutChangeListener(this);
98
- mMarkerView.setOnPositionUpdateListener(null);
99
- mMarkerView = null;
100
- mMarkerViewManager = null;
101
- }
102
- }
103
-
104
- @Override
105
- public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
106
- int oldRight, int oldBottom) {
107
- if (left != oldLeft || right != oldRight || top != oldTop || bottom != oldBottom) {
108
- refresh();
109
- }
110
- }
111
- }
112
-
@@ -1,45 +0,0 @@
1
- package org.maplibre.reactnative.components.annotations;
2
-
3
- import com.facebook.react.bridge.ReactApplicationContext;
4
- import com.facebook.react.bridge.ReadableMap;
5
- import com.facebook.react.common.MapBuilder;
6
- import com.facebook.react.uimanager.ThemedReactContext;
7
- import com.facebook.react.uimanager.annotations.ReactProp;
8
- import org.maplibre.reactnative.components.AbstractEventEmitter;
9
- import org.maplibre.reactnative.utils.GeoJSONUtils;
10
-
11
- import java.util.Map;
12
-
13
- public class MLRNMarkerViewManager extends AbstractEventEmitter<MLRNMarkerView> {
14
- public static final String REACT_CLASS = "MLRNMarkerView";
15
-
16
- public MLRNMarkerViewManager(ReactApplicationContext reactApplicationContext) {
17
- super(reactApplicationContext);
18
- }
19
-
20
- @Override
21
- public String getName() {
22
- return REACT_CLASS;
23
- }
24
-
25
- @ReactProp(name="coordinate")
26
- public void setCoordinate(MLRNMarkerView markerView, String geoJSONStr) {
27
- markerView.setCoordinate(GeoJSONUtils.toPointGeometry(geoJSONStr));
28
- }
29
-
30
- @ReactProp(name="anchor")
31
- public void setAnchor(MLRNMarkerView markerView, ReadableMap map) {
32
- markerView.setAnchor((float) map.getDouble("x"), (float) map.getDouble("y"));
33
- }
34
-
35
- @Override
36
- protected MLRNMarkerView createViewInstance(ThemedReactContext reactContext) {
37
- return new MLRNMarkerView(reactContext, this);
38
- }
39
-
40
- @Override
41
- public Map<String, String> customEvents() {
42
- return MapBuilder.<String, String>builder()
43
- .build();
44
- }
45
- }