@rnmapbox/maps 10.1.23 → 10.1.25

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 (242) hide show
  1. package/ios/RNMBX/RNMBXCameraModule.mm +2 -1
  2. package/lib/commonjs/Mapbox.js +1 -1
  3. package/lib/commonjs/Mapbox.js.map +1 -1
  4. package/lib/commonjs/classes/AnimatedPoint.js.map +1 -1
  5. package/lib/commonjs/classes/AnimatedRouteCoordinatesArray.js +1 -1
  6. package/lib/commonjs/classes/AnimatedRouteCoordinatesArray.js.map +1 -1
  7. package/lib/commonjs/components/AbstractLayer.js +1 -1
  8. package/lib/commonjs/components/AbstractLayer.js.map +1 -1
  9. package/lib/commonjs/components/AbstractSource.js +1 -1
  10. package/lib/commonjs/components/AbstractSource.js.map +1 -1
  11. package/lib/commonjs/components/Annotation.js +1 -1
  12. package/lib/commonjs/components/Annotation.js.map +1 -1
  13. package/lib/commonjs/components/Atmosphere.js +1 -1
  14. package/lib/commonjs/components/Atmosphere.js.map +1 -1
  15. package/lib/commonjs/components/BackgroundLayer.js +2 -2
  16. package/lib/commonjs/components/BackgroundLayer.js.map +1 -1
  17. package/lib/commonjs/components/Callout.js +2 -2
  18. package/lib/commonjs/components/Callout.js.map +1 -1
  19. package/lib/commonjs/components/Camera.js +1 -1
  20. package/lib/commonjs/components/Camera.js.map +1 -1
  21. package/lib/commonjs/components/CircleLayer.js +2 -2
  22. package/lib/commonjs/components/CircleLayer.js.map +1 -1
  23. package/lib/commonjs/components/CustomLocationProvider.js +1 -1
  24. package/lib/commonjs/components/CustomLocationProvider.js.map +1 -1
  25. package/lib/commonjs/components/FillExtrusionLayer.js +2 -2
  26. package/lib/commonjs/components/FillExtrusionLayer.js.map +1 -1
  27. package/lib/commonjs/components/FillLayer.js +2 -2
  28. package/lib/commonjs/components/FillLayer.js.map +1 -1
  29. package/lib/commonjs/components/HeadingIndicator.js +1 -1
  30. package/lib/commonjs/components/HeadingIndicator.js.map +1 -1
  31. package/lib/commonjs/components/HeatmapLayer.js +2 -2
  32. package/lib/commonjs/components/HeatmapLayer.js.map +1 -1
  33. package/lib/commonjs/components/Image.js +2 -2
  34. package/lib/commonjs/components/Image.js.map +1 -1
  35. package/lib/commonjs/components/ImageSource.js +2 -2
  36. package/lib/commonjs/components/ImageSource.js.map +1 -1
  37. package/lib/commonjs/components/Images.js +1 -1
  38. package/lib/commonjs/components/Images.js.map +1 -1
  39. package/lib/commonjs/components/Light.js +2 -2
  40. package/lib/commonjs/components/Light.js.map +1 -1
  41. package/lib/commonjs/components/LineLayer.js +2 -2
  42. package/lib/commonjs/components/LineLayer.js.map +1 -1
  43. package/lib/commonjs/components/LocationPuck.js +1 -1
  44. package/lib/commonjs/components/LocationPuck.js.map +1 -1
  45. package/lib/commonjs/components/MapView.js +2 -2
  46. package/lib/commonjs/components/MapView.js.map +1 -1
  47. package/lib/commonjs/components/MarkerView.js +2 -2
  48. package/lib/commonjs/components/MarkerView.js.map +1 -1
  49. package/lib/commonjs/components/ModelLayer.js +2 -2
  50. package/lib/commonjs/components/ModelLayer.js.map +1 -1
  51. package/lib/commonjs/components/Models.js +2 -2
  52. package/lib/commonjs/components/Models.js.map +1 -1
  53. package/lib/commonjs/components/PointAnnotation.js +1 -1
  54. package/lib/commonjs/components/PointAnnotation.js.map +1 -1
  55. package/lib/commonjs/components/RasterDemSource.js +2 -2
  56. package/lib/commonjs/components/RasterDemSource.js.map +1 -1
  57. package/lib/commonjs/components/RasterLayer.js +2 -2
  58. package/lib/commonjs/components/RasterLayer.js.map +1 -1
  59. package/lib/commonjs/components/RasterSource.js +2 -2
  60. package/lib/commonjs/components/RasterSource.js.map +1 -1
  61. package/lib/commonjs/components/ShapeSource.js +1 -1
  62. package/lib/commonjs/components/ShapeSource.js.map +1 -1
  63. package/lib/commonjs/components/SkyLayer.js +2 -2
  64. package/lib/commonjs/components/SkyLayer.js.map +1 -1
  65. package/lib/commonjs/components/Style.js +2 -2
  66. package/lib/commonjs/components/Style.js.map +1 -1
  67. package/lib/commonjs/components/StyleImport.js +1 -1
  68. package/lib/commonjs/components/StyleImport.js.map +1 -1
  69. package/lib/commonjs/components/SymbolLayer.js +2 -2
  70. package/lib/commonjs/components/SymbolLayer.js.map +1 -1
  71. package/lib/commonjs/components/Terrain.js +1 -1
  72. package/lib/commonjs/components/Terrain.js.map +1 -1
  73. package/lib/commonjs/components/UserLocation.js +1 -1
  74. package/lib/commonjs/components/UserLocation.js.map +1 -1
  75. package/lib/commonjs/components/VectorSource.js +2 -2
  76. package/lib/commonjs/components/VectorSource.js.map +1 -1
  77. package/lib/commonjs/components/Viewport.js +2 -2
  78. package/lib/commonjs/components/Viewport.js.map +1 -1
  79. package/lib/commonjs/modules/offline/TileStore.js +1 -1
  80. package/lib/commonjs/modules/offline/TileStore.js.map +1 -1
  81. package/lib/commonjs/modules/offline/offlineManager.js +1 -1
  82. package/lib/commonjs/modules/offline/offlineManager.js.map +1 -1
  83. package/lib/commonjs/modules/offline/offlineManagerLegacy.js +1 -1
  84. package/lib/commonjs/modules/offline/offlineManagerLegacy.js.map +1 -1
  85. package/lib/commonjs/modules/snapshot/snapshotManager.js +1 -1
  86. package/lib/commonjs/modules/snapshot/snapshotManager.js.map +1 -1
  87. package/lib/commonjs/shapeAnimators/ChangeLineOffsetsShapeAnimator.js +1 -1
  88. package/lib/commonjs/shapeAnimators/ChangeLineOffsetsShapeAnimator.js.map +1 -1
  89. package/lib/commonjs/shapeAnimators/MovePointShapeAnimator.js +1 -1
  90. package/lib/commonjs/shapeAnimators/MovePointShapeAnimator.js.map +1 -1
  91. package/lib/commonjs/specs/RNMBXAtmosphereNativeComponent.js +1 -1
  92. package/lib/commonjs/specs/RNMBXAtmosphereNativeComponent.js.map +1 -1
  93. package/lib/commonjs/specs/RNMBXBackgroundLayerNativeComponent.js +1 -1
  94. package/lib/commonjs/specs/RNMBXBackgroundLayerNativeComponent.js.map +1 -1
  95. package/lib/commonjs/specs/RNMBXCalloutNativeComponent.js +1 -1
  96. package/lib/commonjs/specs/RNMBXCalloutNativeComponent.js.map +1 -1
  97. package/lib/commonjs/specs/RNMBXCameraNativeComponent.js +1 -1
  98. package/lib/commonjs/specs/RNMBXCameraNativeComponent.js.map +1 -1
  99. package/lib/commonjs/specs/RNMBXCircleLayerNativeComponent.js +1 -1
  100. package/lib/commonjs/specs/RNMBXCircleLayerNativeComponent.js.map +1 -1
  101. package/lib/commonjs/specs/RNMBXCustomLocationProviderNativeComponent.js +1 -1
  102. package/lib/commonjs/specs/RNMBXCustomLocationProviderNativeComponent.js.map +1 -1
  103. package/lib/commonjs/specs/RNMBXFillExtrusionLayerNativeComponent.js +1 -1
  104. package/lib/commonjs/specs/RNMBXFillExtrusionLayerNativeComponent.js.map +1 -1
  105. package/lib/commonjs/specs/RNMBXFillLayerNativeComponent.js +1 -1
  106. package/lib/commonjs/specs/RNMBXFillLayerNativeComponent.js.map +1 -1
  107. package/lib/commonjs/specs/RNMBXHeatmapLayerNativeComponent.js +1 -1
  108. package/lib/commonjs/specs/RNMBXHeatmapLayerNativeComponent.js.map +1 -1
  109. package/lib/commonjs/specs/RNMBXImageNativeComponent.js +1 -1
  110. package/lib/commonjs/specs/RNMBXImageNativeComponent.js.map +1 -1
  111. package/lib/commonjs/specs/RNMBXImageSourceNativeComponent.js +1 -1
  112. package/lib/commonjs/specs/RNMBXImageSourceNativeComponent.js.map +1 -1
  113. package/lib/commonjs/specs/RNMBXImagesNativeComponent.js +1 -1
  114. package/lib/commonjs/specs/RNMBXImagesNativeComponent.js.map +1 -1
  115. package/lib/commonjs/specs/RNMBXLightNativeComponent.js +1 -1
  116. package/lib/commonjs/specs/RNMBXLightNativeComponent.js.map +1 -1
  117. package/lib/commonjs/specs/RNMBXLineLayerNativeComponent.js +1 -1
  118. package/lib/commonjs/specs/RNMBXLineLayerNativeComponent.js.map +1 -1
  119. package/lib/commonjs/specs/RNMBXMapViewNativeComponent.js +1 -1
  120. package/lib/commonjs/specs/RNMBXMapViewNativeComponent.js.map +1 -1
  121. package/lib/commonjs/specs/RNMBXMarkerViewContentNativeComponent.js +1 -1
  122. package/lib/commonjs/specs/RNMBXMarkerViewContentNativeComponent.js.map +1 -1
  123. package/lib/commonjs/specs/RNMBXMarkerViewNativeComponent.js +1 -1
  124. package/lib/commonjs/specs/RNMBXMarkerViewNativeComponent.js.map +1 -1
  125. package/lib/commonjs/specs/RNMBXModelLayerNativeComponent.js +1 -1
  126. package/lib/commonjs/specs/RNMBXModelLayerNativeComponent.js.map +1 -1
  127. package/lib/commonjs/specs/RNMBXModelsNativeComponent.js +1 -1
  128. package/lib/commonjs/specs/RNMBXModelsNativeComponent.js.map +1 -1
  129. package/lib/commonjs/specs/RNMBXNativeUserLocationNativeComponent.js +1 -1
  130. package/lib/commonjs/specs/RNMBXNativeUserLocationNativeComponent.js.map +1 -1
  131. package/lib/commonjs/specs/RNMBXPointAnnotationNativeComponent.js +1 -1
  132. package/lib/commonjs/specs/RNMBXPointAnnotationNativeComponent.js.map +1 -1
  133. package/lib/commonjs/specs/RNMBXRasterDemSourceNativeComponent.js +1 -1
  134. package/lib/commonjs/specs/RNMBXRasterDemSourceNativeComponent.js.map +1 -1
  135. package/lib/commonjs/specs/RNMBXRasterLayerNativeComponent.js +1 -1
  136. package/lib/commonjs/specs/RNMBXRasterLayerNativeComponent.js.map +1 -1
  137. package/lib/commonjs/specs/RNMBXRasterSourceNativeComponent.js +1 -1
  138. package/lib/commonjs/specs/RNMBXRasterSourceNativeComponent.js.map +1 -1
  139. package/lib/commonjs/specs/RNMBXShapeSourceNativeComponent.js +1 -1
  140. package/lib/commonjs/specs/RNMBXShapeSourceNativeComponent.js.map +1 -1
  141. package/lib/commonjs/specs/RNMBXSkyLayerNativeComponent.js +1 -1
  142. package/lib/commonjs/specs/RNMBXSkyLayerNativeComponent.js.map +1 -1
  143. package/lib/commonjs/specs/RNMBXStyleImportNativeComponent.js +1 -1
  144. package/lib/commonjs/specs/RNMBXStyleImportNativeComponent.js.map +1 -1
  145. package/lib/commonjs/specs/RNMBXSymbolLayerNativeComponent.js +1 -1
  146. package/lib/commonjs/specs/RNMBXSymbolLayerNativeComponent.js.map +1 -1
  147. package/lib/commonjs/specs/RNMBXTerrainNativeComponent.js +1 -1
  148. package/lib/commonjs/specs/RNMBXTerrainNativeComponent.js.map +1 -1
  149. package/lib/commonjs/specs/RNMBXVectorSourceNativeComponent.js +1 -1
  150. package/lib/commonjs/specs/RNMBXVectorSourceNativeComponent.js.map +1 -1
  151. package/lib/commonjs/specs/RNMBXViewportNativeComponent.js +1 -1
  152. package/lib/commonjs/specs/RNMBXViewportNativeComponent.js.map +1 -1
  153. package/lib/commonjs/utils/BridgeValue.js.map +1 -1
  154. package/lib/commonjs/utils/Logger.js.map +1 -1
  155. package/lib/commonjs/utils/NativeCommands.js.map +1 -1
  156. package/lib/commonjs/utils/StyleValue.js +1 -1
  157. package/lib/commonjs/utils/StyleValue.js.map +1 -1
  158. package/lib/commonjs/utils/animated/Animated.js +1 -1
  159. package/lib/commonjs/utils/animated/Animated.js.map +1 -1
  160. package/lib/commonjs/utils/checkRequiredProps.js.map +1 -1
  161. package/lib/commonjs/utils/deprecation.js.map +1 -1
  162. package/lib/commonjs/utils/geoUtils.js +1 -1
  163. package/lib/commonjs/utils/geoUtils.js.map +1 -1
  164. package/lib/commonjs/utils/index.js +1 -1
  165. package/lib/commonjs/utils/index.js.map +1 -1
  166. package/lib/commonjs/utils/styleMap.js.map +1 -1
  167. package/lib/commonjs/web/MapContext.js +1 -1
  168. package/lib/commonjs/web/MapContext.js.map +1 -1
  169. package/lib/commonjs/web/MapboxModule.js +1 -1
  170. package/lib/commonjs/web/MapboxModule.js.map +1 -1
  171. package/lib/commonjs/web/UnimplementedComponent.js +1 -1
  172. package/lib/commonjs/web/UnimplementedComponent.js.map +1 -1
  173. package/lib/commonjs/web/components/Camera.js +101 -10
  174. package/lib/commonjs/web/components/Camera.js.map +1 -1
  175. package/lib/commonjs/web/components/MapView.js +1 -1
  176. package/lib/commonjs/web/components/MapView.js.map +1 -1
  177. package/lib/commonjs/web/components/MarkerView.js +63 -0
  178. package/lib/commonjs/web/components/MarkerView.js.map +1 -0
  179. package/lib/commonjs/web/index.js +10 -2
  180. package/lib/commonjs/web/index.js.map +1 -1
  181. package/lib/commonjs/web/utils/Logger.js.map +1 -1
  182. package/lib/module/classes/AnimatedPoint.js.map +1 -1
  183. package/lib/module/components/Annotation.js.map +1 -1
  184. package/lib/module/components/BackgroundLayer.js +1 -1
  185. package/lib/module/components/Callout.js +1 -1
  186. package/lib/module/components/CircleLayer.js +1 -1
  187. package/lib/module/components/FillExtrusionLayer.js +1 -1
  188. package/lib/module/components/FillLayer.js +1 -1
  189. package/lib/module/components/HeatmapLayer.js +1 -1
  190. package/lib/module/components/Image.js +1 -1
  191. package/lib/module/components/ImageSource.js +1 -1
  192. package/lib/module/components/Images.js.map +1 -1
  193. package/lib/module/components/Light.js +1 -1
  194. package/lib/module/components/LineLayer.js +1 -1
  195. package/lib/module/components/MapView.js +1 -1
  196. package/lib/module/components/MapView.js.map +1 -1
  197. package/lib/module/components/MarkerView.js +1 -1
  198. package/lib/module/components/MarkerView.js.map +1 -1
  199. package/lib/module/components/ModelLayer.js +1 -1
  200. package/lib/module/components/Models.js +1 -1
  201. package/lib/module/components/Models.js.map +1 -1
  202. package/lib/module/components/RasterDemSource.js +1 -1
  203. package/lib/module/components/RasterDemSource.js.map +1 -1
  204. package/lib/module/components/RasterLayer.js +1 -1
  205. package/lib/module/components/RasterSource.js +1 -1
  206. package/lib/module/components/RasterSource.js.map +1 -1
  207. package/lib/module/components/ShapeSource.js.map +1 -1
  208. package/lib/module/components/SkyLayer.js +1 -1
  209. package/lib/module/components/Style.js +1 -1
  210. package/lib/module/components/Style.js.map +1 -1
  211. package/lib/module/components/SymbolLayer.js +1 -1
  212. package/lib/module/components/Terrain.js.map +1 -1
  213. package/lib/module/components/VectorSource.js +1 -1
  214. package/lib/module/components/VectorSource.js.map +1 -1
  215. package/lib/module/components/Viewport.js +1 -1
  216. package/lib/module/modules/offline/offlineManager.js.map +1 -1
  217. package/lib/module/modules/offline/offlineManagerLegacy.js.map +1 -1
  218. package/lib/module/utils/BridgeValue.js.map +1 -1
  219. package/lib/module/utils/Logger.js.map +1 -1
  220. package/lib/module/utils/NativeCommands.js.map +1 -1
  221. package/lib/module/utils/StyleValue.js.map +1 -1
  222. package/lib/module/utils/checkRequiredProps.js.map +1 -1
  223. package/lib/module/utils/deprecation.js.map +1 -1
  224. package/lib/module/utils/index.js.map +1 -1
  225. package/lib/module/utils/styleMap.js.map +1 -1
  226. package/lib/module/web/components/Camera.js +99 -8
  227. package/lib/module/web/components/Camera.js.map +1 -1
  228. package/lib/module/web/components/MarkerView.js +56 -0
  229. package/lib/module/web/components/MarkerView.js.map +1 -0
  230. package/lib/module/web/index.js +4 -2
  231. package/lib/module/web/index.js.map +1 -1
  232. package/lib/module/web/utils/Logger.js.map +1 -1
  233. package/lib/typescript/src/web/components/Camera.d.ts +11 -8
  234. package/lib/typescript/src/web/components/Camera.d.ts.map +1 -1
  235. package/lib/typescript/src/web/components/MarkerView.d.ts +9 -0
  236. package/lib/typescript/src/web/components/MarkerView.d.ts.map +1 -0
  237. package/package.json +6 -2
  238. package/rnmapbox-maps.podspec +1 -1
  239. package/setup-jest.js +0 -6
  240. package/src/web/components/Camera.tsx +123 -13
  241. package/src/web/components/MarkerView.tsx +77 -0
  242. package/src/web/index.js +3 -1
@@ -1,32 +1,142 @@
1
- import React from 'react';
1
+ import { Component, ContextType } from 'react';
2
2
 
3
+ import { CameraProps, CameraRef } from '../../components/Camera';
4
+ import { Position } from '../../types/Position';
3
5
  import MapContext from '../MapContext';
4
6
 
5
- class Camera extends React.Component<{
6
- centerCoordinate: [number, number] | null;
7
- }> {
8
- context!: React.ContextType<typeof MapContext>;
7
+ function isArray<T>(value: T | ArrayLike<T>): value is ArrayLike<T> {
8
+ return (value as ArrayLike<T>).length !== undefined;
9
+ }
10
+
11
+ function buildMapboxGlPadding(
12
+ padding?: number | number[],
13
+ ): number | mapboxgl.PaddingOptions | undefined {
14
+ if (padding === undefined) {
15
+ // undefined
16
+ return undefined;
17
+ } else if (!isArray(padding)) {
18
+ // padding
19
+ return padding;
20
+ } else {
21
+ // Array
22
+ if (padding.length === 0) {
23
+ // []
24
+ return undefined;
25
+ } else if (padding.length < 2) {
26
+ // [padding]
27
+ return padding[0];
28
+ } else if (padding.length < 4) {
29
+ // [vertical, horizontal]
30
+ return {
31
+ left: padding[0],
32
+ right: padding[0],
33
+ top: padding[1],
34
+ bottom: padding[1],
35
+ };
36
+ } else {
37
+ // [top, right, bottom, left]
38
+ return {
39
+ top: padding[0],
40
+ right: padding[1],
41
+ bottom: padding[2],
42
+ left: padding[3],
43
+ };
44
+ }
45
+ }
46
+ }
47
+
48
+ class Camera
49
+ extends Component<
50
+ Pick<
51
+ CameraProps,
52
+ 'centerCoordinate' | 'zoomLevel' | 'minZoomLevel' | 'maxZoomLevel'
53
+ >
54
+ >
55
+ implements Omit<CameraRef, 'setCamera'>
56
+ {
57
+ context!: ContextType<typeof MapContext>;
9
58
 
10
59
  static contextType = MapContext;
11
60
  static UserTrackingModes = [];
12
61
 
13
62
  componentDidMount() {
14
63
  const { map } = this.context;
15
- const { centerCoordinate } = this.props;
16
- if (map && centerCoordinate) {
17
- map.flyTo({ center: centerCoordinate });
64
+ if (!map) {
65
+ return;
66
+ }
67
+
68
+ // minZoomLevel
69
+ if (this.props.minZoomLevel !== undefined) {
70
+ map.setMinZoom(this.props.minZoomLevel);
71
+ }
72
+
73
+ // maxZoomLevel
74
+ if (this.props.maxZoomLevel !== undefined) {
75
+ map.setMaxZoom(this.props.maxZoomLevel);
76
+ }
77
+
78
+ // zoomLevel
79
+ if (this.props.zoomLevel !== undefined) {
80
+ map.setZoom(this.props.zoomLevel);
81
+ }
82
+
83
+ // centerCoordinate
84
+ if (this.props.centerCoordinate !== undefined) {
85
+ map.flyTo({
86
+ center: this.props.centerCoordinate.slice(0, 2) as [number, number],
87
+ duration: 0,
88
+ });
18
89
  }
19
90
  }
20
91
 
21
92
  fitBounds(
22
- northEastCoordinates: [number, number],
23
- southWestCoordinates: [number, number],
24
- padding = 0,
25
- animationDuration = 0.0,
93
+ northEastCoordinates: Position,
94
+ southWestCoordinates: Position,
95
+ padding: number | number[] = 0,
96
+ animationDuration = 0,
26
97
  ) {
27
98
  const { map } = this.context;
28
99
  if (map) {
29
- map.fitBounds([northEastCoordinates, southWestCoordinates]);
100
+ map.fitBounds(
101
+ [
102
+ northEastCoordinates.slice(0, 2) as [number, number],
103
+ southWestCoordinates.slice(0, 2) as [number, number],
104
+ ],
105
+ {
106
+ padding: buildMapboxGlPadding(padding),
107
+ duration: animationDuration,
108
+ },
109
+ );
110
+ }
111
+ }
112
+
113
+ flyTo(centerCoordinate: Position, animationDuration = 2000) {
114
+ const { map } = this.context;
115
+ if (map) {
116
+ map.flyTo({
117
+ center: centerCoordinate.slice(0, 2) as [number, number],
118
+ duration: animationDuration,
119
+ });
120
+ }
121
+ }
122
+
123
+ moveTo(centerCoordinate: Position, animationDuration = 0) {
124
+ const { map } = this.context;
125
+ if (map) {
126
+ map.easeTo({
127
+ center: centerCoordinate.slice(0, 2) as [number, number],
128
+ duration: animationDuration,
129
+ });
130
+ }
131
+ }
132
+
133
+ zoomTo(zoomLevel: number, animationDuration = 2000) {
134
+ const { map } = this.context;
135
+ if (map) {
136
+ map.flyTo({
137
+ zoom: zoomLevel,
138
+ duration: animationDuration,
139
+ });
30
140
  }
31
141
  }
32
142
 
@@ -0,0 +1,77 @@
1
+ import { Marker } from 'mapbox-gl';
2
+ import {
3
+ forwardRef,
4
+ isValidElement,
5
+ memo,
6
+ ReactElement,
7
+ Ref,
8
+ useContext,
9
+ useEffect,
10
+ useImperativeHandle,
11
+ useMemo,
12
+ } from 'react';
13
+ import { createPortal } from 'react-dom';
14
+
15
+ import MapContext from '../MapContext';
16
+
17
+ type MarkerViewProps = {
18
+ coordinate: [number, number];
19
+ children?: ReactElement;
20
+ };
21
+
22
+ function MarkerView(props: MarkerViewProps, ref: Ref<Marker>) {
23
+ const { map } = useContext(MapContext);
24
+
25
+ // Create marker instance
26
+ const marker: Marker = useMemo(() => {
27
+ const _marker = new Marker({
28
+ element: isValidElement(props.children)
29
+ ? document.createElement('div')
30
+ : undefined,
31
+ });
32
+
33
+ // Set marker coordinates
34
+ _marker.setLngLat(props.coordinate);
35
+
36
+ // Fix marker position
37
+ const { style } = _marker.getElement();
38
+ style.position = 'absolute';
39
+ style.top = '0';
40
+ style.left = '0';
41
+
42
+ return _marker;
43
+ // eslint-disable-next-line react-hooks/exhaustive-deps
44
+ }, []);
45
+
46
+ // Add marker to map
47
+ useEffect(() => {
48
+ if (map === undefined) {
49
+ return;
50
+ }
51
+
52
+ marker.addTo(map);
53
+
54
+ return () => {
55
+ marker.remove();
56
+ };
57
+ // eslint-disable-next-line react-hooks/exhaustive-deps
58
+ }, [map]);
59
+
60
+ // Expose marker instance
61
+ // eslint-disable-next-line react-hooks/exhaustive-deps
62
+ useImperativeHandle(ref, () => marker, []);
63
+
64
+ // Update marker coordinates
65
+ const markerCoordinate = marker.getLngLat();
66
+ if (
67
+ markerCoordinate.lng !== props.coordinate[0] ||
68
+ markerCoordinate.lat !== props.coordinate[1]
69
+ ) {
70
+ marker.setLngLat([props.coordinate[0], props.coordinate[1]]);
71
+ }
72
+
73
+ // Inject children into marker element
74
+ return createPortal(props.children, marker.getElement());
75
+ }
76
+
77
+ export default memo(forwardRef(MarkerView));
package/src/web/index.js CHANGED
@@ -1,12 +1,14 @@
1
1
  import MapboxModule from './MapboxModule';
2
2
  import Camera from './components/Camera';
3
3
  import MapView from './components/MapView';
4
+ import MarkerView from './components/MarkerView';
4
5
  import Logger from './utils/Logger';
5
6
 
6
7
  const ExportedComponents = {
7
8
  Camera,
8
9
  MapView,
9
10
  Logger,
11
+ MarkerView,
10
12
  };
11
13
 
12
14
  const Mapbox = {
@@ -14,5 +16,5 @@ const Mapbox = {
14
16
  ...ExportedComponents,
15
17
  };
16
18
 
17
- export { Camera, MapView, Logger };
19
+ export { Camera, MapView, Logger, MarkerView };
18
20
  export default Mapbox;