@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.
- package/ios/RNMBX/RNMBXCameraModule.mm +2 -1
- package/lib/commonjs/Mapbox.js +1 -1
- package/lib/commonjs/Mapbox.js.map +1 -1
- package/lib/commonjs/classes/AnimatedPoint.js.map +1 -1
- package/lib/commonjs/classes/AnimatedRouteCoordinatesArray.js +1 -1
- package/lib/commonjs/classes/AnimatedRouteCoordinatesArray.js.map +1 -1
- package/lib/commonjs/components/AbstractLayer.js +1 -1
- package/lib/commonjs/components/AbstractLayer.js.map +1 -1
- package/lib/commonjs/components/AbstractSource.js +1 -1
- package/lib/commonjs/components/AbstractSource.js.map +1 -1
- package/lib/commonjs/components/Annotation.js +1 -1
- package/lib/commonjs/components/Annotation.js.map +1 -1
- package/lib/commonjs/components/Atmosphere.js +1 -1
- package/lib/commonjs/components/Atmosphere.js.map +1 -1
- package/lib/commonjs/components/BackgroundLayer.js +2 -2
- package/lib/commonjs/components/BackgroundLayer.js.map +1 -1
- package/lib/commonjs/components/Callout.js +2 -2
- package/lib/commonjs/components/Callout.js.map +1 -1
- package/lib/commonjs/components/Camera.js +1 -1
- package/lib/commonjs/components/Camera.js.map +1 -1
- package/lib/commonjs/components/CircleLayer.js +2 -2
- package/lib/commonjs/components/CircleLayer.js.map +1 -1
- package/lib/commonjs/components/CustomLocationProvider.js +1 -1
- package/lib/commonjs/components/CustomLocationProvider.js.map +1 -1
- package/lib/commonjs/components/FillExtrusionLayer.js +2 -2
- package/lib/commonjs/components/FillExtrusionLayer.js.map +1 -1
- package/lib/commonjs/components/FillLayer.js +2 -2
- package/lib/commonjs/components/FillLayer.js.map +1 -1
- package/lib/commonjs/components/HeadingIndicator.js +1 -1
- package/lib/commonjs/components/HeadingIndicator.js.map +1 -1
- package/lib/commonjs/components/HeatmapLayer.js +2 -2
- package/lib/commonjs/components/HeatmapLayer.js.map +1 -1
- package/lib/commonjs/components/Image.js +2 -2
- package/lib/commonjs/components/Image.js.map +1 -1
- package/lib/commonjs/components/ImageSource.js +2 -2
- package/lib/commonjs/components/ImageSource.js.map +1 -1
- package/lib/commonjs/components/Images.js +1 -1
- package/lib/commonjs/components/Images.js.map +1 -1
- package/lib/commonjs/components/Light.js +2 -2
- package/lib/commonjs/components/Light.js.map +1 -1
- package/lib/commonjs/components/LineLayer.js +2 -2
- package/lib/commonjs/components/LineLayer.js.map +1 -1
- package/lib/commonjs/components/LocationPuck.js +1 -1
- package/lib/commonjs/components/LocationPuck.js.map +1 -1
- package/lib/commonjs/components/MapView.js +2 -2
- package/lib/commonjs/components/MapView.js.map +1 -1
- package/lib/commonjs/components/MarkerView.js +2 -2
- package/lib/commonjs/components/MarkerView.js.map +1 -1
- package/lib/commonjs/components/ModelLayer.js +2 -2
- package/lib/commonjs/components/ModelLayer.js.map +1 -1
- package/lib/commonjs/components/Models.js +2 -2
- package/lib/commonjs/components/Models.js.map +1 -1
- package/lib/commonjs/components/PointAnnotation.js +1 -1
- package/lib/commonjs/components/PointAnnotation.js.map +1 -1
- package/lib/commonjs/components/RasterDemSource.js +2 -2
- package/lib/commonjs/components/RasterDemSource.js.map +1 -1
- package/lib/commonjs/components/RasterLayer.js +2 -2
- package/lib/commonjs/components/RasterLayer.js.map +1 -1
- package/lib/commonjs/components/RasterSource.js +2 -2
- package/lib/commonjs/components/RasterSource.js.map +1 -1
- package/lib/commonjs/components/ShapeSource.js +1 -1
- package/lib/commonjs/components/ShapeSource.js.map +1 -1
- package/lib/commonjs/components/SkyLayer.js +2 -2
- package/lib/commonjs/components/SkyLayer.js.map +1 -1
- package/lib/commonjs/components/Style.js +2 -2
- package/lib/commonjs/components/Style.js.map +1 -1
- package/lib/commonjs/components/StyleImport.js +1 -1
- package/lib/commonjs/components/StyleImport.js.map +1 -1
- package/lib/commonjs/components/SymbolLayer.js +2 -2
- package/lib/commonjs/components/SymbolLayer.js.map +1 -1
- package/lib/commonjs/components/Terrain.js +1 -1
- package/lib/commonjs/components/Terrain.js.map +1 -1
- package/lib/commonjs/components/UserLocation.js +1 -1
- package/lib/commonjs/components/UserLocation.js.map +1 -1
- package/lib/commonjs/components/VectorSource.js +2 -2
- package/lib/commonjs/components/VectorSource.js.map +1 -1
- package/lib/commonjs/components/Viewport.js +2 -2
- package/lib/commonjs/components/Viewport.js.map +1 -1
- package/lib/commonjs/modules/offline/TileStore.js +1 -1
- package/lib/commonjs/modules/offline/TileStore.js.map +1 -1
- package/lib/commonjs/modules/offline/offlineManager.js +1 -1
- package/lib/commonjs/modules/offline/offlineManager.js.map +1 -1
- package/lib/commonjs/modules/offline/offlineManagerLegacy.js +1 -1
- package/lib/commonjs/modules/offline/offlineManagerLegacy.js.map +1 -1
- package/lib/commonjs/modules/snapshot/snapshotManager.js +1 -1
- package/lib/commonjs/modules/snapshot/snapshotManager.js.map +1 -1
- package/lib/commonjs/shapeAnimators/ChangeLineOffsetsShapeAnimator.js +1 -1
- package/lib/commonjs/shapeAnimators/ChangeLineOffsetsShapeAnimator.js.map +1 -1
- package/lib/commonjs/shapeAnimators/MovePointShapeAnimator.js +1 -1
- package/lib/commonjs/shapeAnimators/MovePointShapeAnimator.js.map +1 -1
- package/lib/commonjs/specs/RNMBXAtmosphereNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXAtmosphereNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXBackgroundLayerNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXBackgroundLayerNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXCalloutNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXCalloutNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXCameraNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXCameraNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXCircleLayerNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXCircleLayerNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXCustomLocationProviderNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXCustomLocationProviderNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXFillExtrusionLayerNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXFillExtrusionLayerNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXFillLayerNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXFillLayerNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXHeatmapLayerNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXHeatmapLayerNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXImageNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXImageNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXImageSourceNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXImageSourceNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXImagesNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXImagesNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXLightNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXLightNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXLineLayerNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXLineLayerNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXMapViewNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXMapViewNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXMarkerViewContentNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXMarkerViewContentNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXMarkerViewNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXMarkerViewNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXModelLayerNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXModelLayerNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXModelsNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXModelsNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXNativeUserLocationNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXNativeUserLocationNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXPointAnnotationNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXPointAnnotationNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXRasterDemSourceNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXRasterDemSourceNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXRasterLayerNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXRasterLayerNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXRasterSourceNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXRasterSourceNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXShapeSourceNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXShapeSourceNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXSkyLayerNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXSkyLayerNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXStyleImportNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXStyleImportNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXSymbolLayerNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXSymbolLayerNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXTerrainNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXTerrainNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXVectorSourceNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXVectorSourceNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNMBXViewportNativeComponent.js +1 -1
- package/lib/commonjs/specs/RNMBXViewportNativeComponent.js.map +1 -1
- package/lib/commonjs/utils/BridgeValue.js.map +1 -1
- package/lib/commonjs/utils/Logger.js.map +1 -1
- package/lib/commonjs/utils/NativeCommands.js.map +1 -1
- package/lib/commonjs/utils/StyleValue.js +1 -1
- package/lib/commonjs/utils/StyleValue.js.map +1 -1
- package/lib/commonjs/utils/animated/Animated.js +1 -1
- package/lib/commonjs/utils/animated/Animated.js.map +1 -1
- package/lib/commonjs/utils/checkRequiredProps.js.map +1 -1
- package/lib/commonjs/utils/deprecation.js.map +1 -1
- package/lib/commonjs/utils/geoUtils.js +1 -1
- package/lib/commonjs/utils/geoUtils.js.map +1 -1
- package/lib/commonjs/utils/index.js +1 -1
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/styleMap.js.map +1 -1
- package/lib/commonjs/web/MapContext.js +1 -1
- package/lib/commonjs/web/MapContext.js.map +1 -1
- package/lib/commonjs/web/MapboxModule.js +1 -1
- package/lib/commonjs/web/MapboxModule.js.map +1 -1
- package/lib/commonjs/web/UnimplementedComponent.js +1 -1
- package/lib/commonjs/web/UnimplementedComponent.js.map +1 -1
- package/lib/commonjs/web/components/Camera.js +101 -10
- package/lib/commonjs/web/components/Camera.js.map +1 -1
- package/lib/commonjs/web/components/MapView.js +1 -1
- package/lib/commonjs/web/components/MapView.js.map +1 -1
- package/lib/commonjs/web/components/MarkerView.js +63 -0
- package/lib/commonjs/web/components/MarkerView.js.map +1 -0
- package/lib/commonjs/web/index.js +10 -2
- package/lib/commonjs/web/index.js.map +1 -1
- package/lib/commonjs/web/utils/Logger.js.map +1 -1
- package/lib/module/classes/AnimatedPoint.js.map +1 -1
- package/lib/module/components/Annotation.js.map +1 -1
- package/lib/module/components/BackgroundLayer.js +1 -1
- package/lib/module/components/Callout.js +1 -1
- package/lib/module/components/CircleLayer.js +1 -1
- package/lib/module/components/FillExtrusionLayer.js +1 -1
- package/lib/module/components/FillLayer.js +1 -1
- package/lib/module/components/HeatmapLayer.js +1 -1
- package/lib/module/components/Image.js +1 -1
- package/lib/module/components/ImageSource.js +1 -1
- package/lib/module/components/Images.js.map +1 -1
- package/lib/module/components/Light.js +1 -1
- package/lib/module/components/LineLayer.js +1 -1
- package/lib/module/components/MapView.js +1 -1
- package/lib/module/components/MapView.js.map +1 -1
- package/lib/module/components/MarkerView.js +1 -1
- package/lib/module/components/MarkerView.js.map +1 -1
- package/lib/module/components/ModelLayer.js +1 -1
- package/lib/module/components/Models.js +1 -1
- package/lib/module/components/Models.js.map +1 -1
- package/lib/module/components/RasterDemSource.js +1 -1
- package/lib/module/components/RasterDemSource.js.map +1 -1
- package/lib/module/components/RasterLayer.js +1 -1
- package/lib/module/components/RasterSource.js +1 -1
- package/lib/module/components/RasterSource.js.map +1 -1
- package/lib/module/components/ShapeSource.js.map +1 -1
- package/lib/module/components/SkyLayer.js +1 -1
- package/lib/module/components/Style.js +1 -1
- package/lib/module/components/Style.js.map +1 -1
- package/lib/module/components/SymbolLayer.js +1 -1
- package/lib/module/components/Terrain.js.map +1 -1
- package/lib/module/components/VectorSource.js +1 -1
- package/lib/module/components/VectorSource.js.map +1 -1
- package/lib/module/components/Viewport.js +1 -1
- package/lib/module/modules/offline/offlineManager.js.map +1 -1
- package/lib/module/modules/offline/offlineManagerLegacy.js.map +1 -1
- package/lib/module/utils/BridgeValue.js.map +1 -1
- package/lib/module/utils/Logger.js.map +1 -1
- package/lib/module/utils/NativeCommands.js.map +1 -1
- package/lib/module/utils/StyleValue.js.map +1 -1
- package/lib/module/utils/checkRequiredProps.js.map +1 -1
- package/lib/module/utils/deprecation.js.map +1 -1
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/styleMap.js.map +1 -1
- package/lib/module/web/components/Camera.js +99 -8
- package/lib/module/web/components/Camera.js.map +1 -1
- package/lib/module/web/components/MarkerView.js +56 -0
- package/lib/module/web/components/MarkerView.js.map +1 -0
- package/lib/module/web/index.js +4 -2
- package/lib/module/web/index.js.map +1 -1
- package/lib/module/web/utils/Logger.js.map +1 -1
- package/lib/typescript/src/web/components/Camera.d.ts +11 -8
- package/lib/typescript/src/web/components/Camera.d.ts.map +1 -1
- package/lib/typescript/src/web/components/MarkerView.d.ts +9 -0
- package/lib/typescript/src/web/components/MarkerView.d.ts.map +1 -0
- package/package.json +6 -2
- package/rnmapbox-maps.podspec +1 -1
- package/setup-jest.js +0 -6
- package/src/web/components/Camera.tsx +123 -13
- package/src/web/components/MarkerView.tsx +77 -0
- package/src/web/index.js +3 -1
|
@@ -1,32 +1,142 @@
|
|
|
1
|
-
import
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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:
|
|
23
|
-
southWestCoordinates:
|
|
24
|
-
padding = 0,
|
|
25
|
-
animationDuration = 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(
|
|
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;
|