react-bkoi-gl 1.0.6 → 2.0.0
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/README.md +163 -18
- package/dist/components/attribution-control.d.ts +4 -6
- package/dist/components/attribution-control.js +6 -5
- package/dist/components/attribution-control.js.map +1 -1
- package/dist/components/fullscreen-control.d.ts +4 -6
- package/dist/components/fullscreen-control.js +4 -4
- package/dist/components/fullscreen-control.js.map +1 -1
- package/dist/components/geolocate-control.d.ts +10 -26
- package/dist/components/geolocate-control.js +11 -11
- package/dist/components/geolocate-control.js.map +1 -1
- package/dist/components/layer.d.ts +7 -6
- package/dist/components/layer.js +8 -9
- package/dist/components/layer.js.map +1 -1
- package/dist/components/logo-control.d.ts +9 -0
- package/dist/components/logo-control.js +28 -0
- package/dist/components/logo-control.js.map +1 -0
- package/dist/components/map.d.ts +20 -16
- package/dist/components/map.js +38 -32
- package/dist/components/map.js.map +1 -1
- package/dist/components/marker.d.ts +10 -33
- package/dist/components/marker.js +22 -15
- package/dist/components/marker.js.map +1 -1
- package/dist/components/navigation-control.d.ts +4 -6
- package/dist/components/navigation-control.js +4 -4
- package/dist/components/navigation-control.js.map +1 -1
- package/dist/components/popup.d.ts +7 -25
- package/dist/components/popup.js +17 -28
- package/dist/components/popup.js.map +1 -1
- package/dist/components/scale-control.d.ts +4 -6
- package/dist/components/scale-control.js +4 -4
- package/dist/components/scale-control.js.map +1 -1
- package/dist/components/source.d.ts +3 -4
- package/dist/components/source.js +20 -22
- package/dist/components/source.js.map +1 -1
- package/dist/components/terrain-control.d.ts +10 -0
- package/dist/components/terrain-control.js +19 -0
- package/dist/components/terrain-control.js.map +1 -0
- package/dist/components/use-control.d.ts +6 -6
- package/dist/components/use-control.js +4 -5
- package/dist/components/use-control.js.map +1 -1
- package/dist/components/use-map.d.ts +8 -9
- package/dist/components/use-map.js +5 -5
- package/dist/components/use-map.js.map +1 -1
- package/dist/exports-maplibre-gl.d.ts +33 -0
- package/dist/exports-maplibre-gl.js +21 -0
- package/dist/exports-maplibre-gl.js.map +1 -0
- package/dist/index.cjs +590 -681
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/{mapbox → maplibre}/create-ref.d.ts +6 -6
- package/dist/maplibre/create-ref.js +30 -0
- package/dist/maplibre/create-ref.js.map +1 -0
- package/dist/maplibre/maplibre.d.ts +81 -0
- package/dist/maplibre/maplibre.js +387 -0
- package/dist/maplibre/maplibre.js.map +1 -0
- package/dist/styles/index.d.ts +4 -0
- package/dist/styles/react-bkoi-gl.css +1 -1
- package/dist/styles.d.js +2 -0
- package/dist/styles.d.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/common.d.ts +2 -60
- package/dist/types/common.js.map +1 -1
- package/dist/types/events.d.ts +64 -23
- package/dist/types/events.js.map +1 -1
- package/dist/types/internal.d.ts +14 -0
- package/dist/types/internal.js +2 -0
- package/dist/types/internal.js.map +1 -0
- package/dist/types/lib.d.ts +16 -200
- package/dist/types/lib.js.map +1 -1
- package/dist/types/style-spec.d.ts +1 -0
- package/dist/types/style-spec.js +2 -0
- package/dist/types/style-spec.js.map +1 -0
- package/dist/utils/apply-react-style.d.ts +1 -1
- package/dist/utils/apply-react-style.js.map +1 -1
- package/dist/utils/compare-class-names.d.ts +2 -0
- package/dist/utils/compare-class-names.js +23 -0
- package/dist/utils/compare-class-names.js.map +1 -0
- package/dist/utils/deep-equal.d.ts +1 -1
- package/dist/utils/deep-equal.js +1 -1
- package/dist/utils/deep-equal.js.map +1 -1
- package/dist/utils/set-globals.d.ts +6 -8
- package/dist/utils/set-globals.js +22 -10
- package/dist/utils/set-globals.js.map +1 -1
- package/dist/utils/style-utils.d.ts +3 -2
- package/dist/utils/style-utils.js +4 -4
- package/dist/utils/style-utils.js.map +1 -1
- package/dist/utils/transform.d.ts +11 -19
- package/dist/utils/transform.js +13 -36
- package/dist/utils/transform.js.map +1 -1
- package/dist/utils/use-isomorphic-layout-effect.d.ts +1 -1
- package/dist/utils/use-isomorphic-layout-effect.js +2 -2
- package/dist/utils/use-isomorphic-layout-effect.js.map +1 -1
- package/package.json +42 -26
- package/src/components/attribution-control.ts +40 -16
- package/src/components/fullscreen-control.ts +40 -0
- package/src/components/geolocate-control.ts +45 -39
- package/src/components/layer.ts +37 -29
- package/src/components/logo-control.ts +44 -0
- package/src/components/map.tsx +86 -75
- package/src/components/marker.ts +141 -123
- package/src/components/navigation-control.ts +11 -12
- package/src/components/popup.ts +94 -97
- package/src/components/scale-control.ts +12 -14
- package/src/components/source.ts +58 -57
- package/src/components/terrain-control.ts +29 -0
- package/src/components/use-control.ts +21 -17
- package/src/components/use-map.tsx +26 -24
- package/src/exports-maplibre-gl.ts +37 -0
- package/src/index.ts +3 -2
- package/src/maplibre/create-ref.ts +70 -0
- package/src/maplibre/maplibre.ts +624 -0
- package/src/styles.d.ts +4 -0
- package/src/types/common.ts +12 -72
- package/src/types/events.ts +102 -42
- package/src/types/internal.ts +26 -0
- package/src/types/lib.ts +65 -260
- package/src/types/style-spec.ts +34 -0
- package/src/utils/apply-react-style.ts +7 -3
- package/src/utils/compare-class-names.ts +29 -0
- package/src/utils/deep-equal.ts +2 -2
- package/src/utils/set-globals.ts +22 -28
- package/src/utils/style-utils.ts +18 -9
- package/src/utils/transform.ts +32 -60
- package/src/utils/use-isomorphic-layout-effect.ts +3 -2
- package/bkoi-gl/package.json +0 -6
- package/dist/exports-bkoi-gl.cjs +0 -1512
- package/dist/exports-bkoi-gl.d.ts +0 -89
- package/dist/exports-bkoi-gl.js +0 -36
- package/dist/exports-bkoi-gl.js.map +0 -1
- package/dist/exports-mapbox.d.ts +0 -139
- package/dist/exports-mapbox.js +0 -36
- package/dist/exports-mapbox.js.map +0 -1
- package/dist/mapbox/create-ref.js +0 -64
- package/dist/mapbox/create-ref.js.map +0 -1
- package/dist/mapbox/mapbox.d.ts +0 -81
- package/dist/mapbox/mapbox.js +0 -476
- package/dist/mapbox/mapbox.js.map +0 -1
- package/dist/types/events-bkoi-gl.d.ts +0 -49
- package/dist/types/events-bkoi-gl.js +0 -2
- package/dist/types/events-bkoi-gl.js.map +0 -1
- package/dist/types/events-mapbox.d.ts +0 -49
- package/dist/types/events-mapbox.js +0 -2
- package/dist/types/events-mapbox.js.map +0 -1
- package/dist/types/index.d.ts +0 -70
- package/dist/types/index.js +0 -5
- package/dist/types/index.js.map +0 -1
- package/dist/types/public.d.ts +0 -2
- package/dist/types/public.js +0 -2
- package/dist/types/public.js.map +0 -1
- package/dist/types/style-spec-bkoi-gl.d.ts +0 -9
- package/dist/types/style-spec-bkoi-gl.js +0 -2
- package/dist/types/style-spec-bkoi-gl.js.map +0 -1
- package/dist/types/style-spec-mapbox.d.ts +0 -7
- package/dist/types/style-spec-mapbox.js +0 -2
- package/dist/types/style-spec-mapbox.js.map +0 -1
- package/src/components/fullscreen-control.tsx +0 -37
- package/src/exports-bkoi-gl.ts +0 -156
- package/src/exports-mapbox.ts +0 -159
- package/src/mapbox/create-ref.ts +0 -118
- package/src/mapbox/mapbox.ts +0 -742
- package/src/types/events-bkoi-gl.ts +0 -78
- package/src/types/events-mapbox.ts +0 -76
- package/src/types/index.ts +0 -93
- package/src/types/public.ts +0 -9
- package/src/types/style-spec-bkoi-gl.ts +0 -81
- package/src/types/style-spec-mapbox.ts +0 -80
package/src/components/map.tsx
CHANGED
|
@@ -1,105 +1,111 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
/* eslint-disable react/display-name */
|
|
2
|
+
/* eslint-disable react/no-unknown-property */
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import {
|
|
5
|
+
useState,
|
|
6
|
+
useRef,
|
|
7
|
+
useEffect,
|
|
8
|
+
useContext,
|
|
9
|
+
useMemo,
|
|
10
|
+
useImperativeHandle,
|
|
11
|
+
} from "react";
|
|
12
|
+
|
|
13
|
+
import { MountedMapsContext } from "./use-map";
|
|
14
|
+
import Maplibre, { MaplibreProps } from "../maplibre/maplibre";
|
|
15
|
+
import createRef, { MapRef } from "../maplibre/create-ref";
|
|
16
|
+
|
|
17
|
+
import type { CSSProperties } from "react";
|
|
18
|
+
import useIsomorphicLayoutEffect from "../utils/use-isomorphic-layout-effect";
|
|
19
|
+
import setGlobals, { GlobalSettings } from "../utils/set-globals";
|
|
20
|
+
import type { MapLib, MapOptions } from "../types/lib";
|
|
21
|
+
import { LogoControl } from "./logo-control";
|
|
22
|
+
import { AttributionControl } from "./attribution-control";
|
|
23
|
+
|
|
24
|
+
export type MapContextValue = {
|
|
25
|
+
mapLib: MapLib;
|
|
26
|
+
map: MapRef;
|
|
16
27
|
};
|
|
17
28
|
|
|
18
29
|
export const MapContext = React.createContext<MapContextValue>(null);
|
|
19
30
|
|
|
20
|
-
type MapInitOptions
|
|
31
|
+
type MapInitOptions = Omit<
|
|
21
32
|
MapOptions,
|
|
22
|
-
|
|
33
|
+
"style" | "container" | "bounds" | "fitBoundsOptions" | "center"
|
|
23
34
|
>;
|
|
24
35
|
|
|
25
|
-
export type MapProps
|
|
26
|
-
|
|
27
|
-
StyleT extends MapStyle,
|
|
28
|
-
CallbacksT extends Callbacks,
|
|
29
|
-
MapT extends MapInstance
|
|
30
|
-
> = MapInitOptions<MapOptions> &
|
|
31
|
-
MapboxProps<StyleT, CallbacksT> &
|
|
36
|
+
export type MapProps = MapInitOptions &
|
|
37
|
+
MaplibreProps &
|
|
32
38
|
GlobalSettings & {
|
|
33
|
-
mapLib?: MapLib
|
|
39
|
+
mapLib?: MapLib | Promise<MapLib>;
|
|
34
40
|
reuseMaps?: boolean;
|
|
35
41
|
/** Map container id */
|
|
36
42
|
id?: string;
|
|
37
43
|
/** Map container CSS style */
|
|
38
44
|
style?: CSSProperties;
|
|
39
|
-
children?:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
>(
|
|
48
|
-
props: MapProps<MapOptions, StyleT, CallbacksT, MapT>,
|
|
49
|
-
ref: React.Ref<MapRef<MapT>>,
|
|
50
|
-
defaultLib: MapLib<MapT> | Promise<MapLib<MapT>>
|
|
51
|
-
) {
|
|
45
|
+
children?: React.ReactNode;
|
|
46
|
+
/** Show Barikoi logo (default: true) */
|
|
47
|
+
showBarikoiLogo?: boolean;
|
|
48
|
+
/** Show Attribution (default: true) */
|
|
49
|
+
showAttribution?: boolean;
|
|
50
|
+
} & React.RefAttributes<MapRef>;
|
|
51
|
+
|
|
52
|
+
function _Map(props: MapProps, ref: React.Ref<MapRef>) {
|
|
52
53
|
const mountedMapsContext = useContext(MountedMapsContext);
|
|
53
|
-
const [mapInstance, setMapInstance] = useState<
|
|
54
|
+
const [mapInstance, setMapInstance] = useState<Maplibre>(null);
|
|
54
55
|
const containerRef = useRef();
|
|
55
56
|
|
|
56
|
-
const {current: contextValue} = useRef<MapContextValue
|
|
57
|
+
const { current: contextValue } = useRef<MapContextValue>({
|
|
58
|
+
mapLib: null,
|
|
59
|
+
map: null,
|
|
60
|
+
});
|
|
57
61
|
|
|
58
62
|
useEffect(() => {
|
|
59
63
|
const mapLib = props.mapLib;
|
|
60
64
|
let isMounted = true;
|
|
61
|
-
let
|
|
65
|
+
let maplibre: Maplibre;
|
|
62
66
|
|
|
63
|
-
Promise.resolve(mapLib ||
|
|
64
|
-
.then((module: MapLib
|
|
67
|
+
Promise.resolve(mapLib || import("maplibre-gl"))
|
|
68
|
+
.then((module: MapLib | { default: MapLib }) => {
|
|
65
69
|
if (!isMounted) {
|
|
66
70
|
return;
|
|
67
71
|
}
|
|
68
72
|
if (!module) {
|
|
69
|
-
throw new Error(
|
|
73
|
+
throw new Error("Invalid mapLib");
|
|
70
74
|
}
|
|
71
|
-
const mapboxgl =
|
|
75
|
+
const mapboxgl = "Map" in module ? module : module.default;
|
|
72
76
|
if (!mapboxgl.Map) {
|
|
73
|
-
throw new Error(
|
|
77
|
+
throw new Error("Invalid mapLib");
|
|
74
78
|
}
|
|
75
79
|
|
|
76
|
-
// workerUrl & workerClass may change the result of supported()
|
|
77
|
-
// https://github.com/visgl/react-map-gl/discussions/2027
|
|
78
80
|
setGlobals(mapboxgl, props);
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
mapbox = Mapbox.reuse(props, containerRef.current);
|
|
82
|
-
}
|
|
83
|
-
if (!mapbox) {
|
|
84
|
-
mapbox = new Mapbox(mapboxgl.Map, props, containerRef.current);
|
|
85
|
-
}
|
|
86
|
-
contextValue.map = createRef(mapbox);
|
|
87
|
-
contextValue.mapLib = mapboxgl;
|
|
88
|
-
|
|
89
|
-
setMapInstance(mapbox);
|
|
90
|
-
mountedMapsContext?.onMapMount(contextValue.map, props.id);
|
|
91
|
-
} else {
|
|
92
|
-
throw new Error('Map is not supported by this browser');
|
|
81
|
+
if (props.reuseMaps) {
|
|
82
|
+
maplibre = Maplibre.reuse(props, containerRef.current);
|
|
93
83
|
}
|
|
84
|
+
if (!maplibre) {
|
|
85
|
+
maplibre = new Maplibre(
|
|
86
|
+
mapboxgl.Map,
|
|
87
|
+
{
|
|
88
|
+
...props,
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
attributionControl: false,
|
|
91
|
+
},
|
|
92
|
+
containerRef.current,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
contextValue.map = createRef(maplibre);
|
|
96
|
+
contextValue.mapLib = mapboxgl;
|
|
97
|
+
|
|
98
|
+
setMapInstance(maplibre);
|
|
99
|
+
mountedMapsContext?.onMapMount(contextValue.map, props.id);
|
|
94
100
|
})
|
|
95
|
-
.catch(error => {
|
|
96
|
-
const {onError} = props;
|
|
101
|
+
.catch((error) => {
|
|
102
|
+
const { onError } = props;
|
|
97
103
|
if (onError) {
|
|
98
104
|
onError({
|
|
99
|
-
type:
|
|
105
|
+
type: "error",
|
|
100
106
|
target: null,
|
|
101
107
|
originalEvent: null,
|
|
102
|
-
error
|
|
108
|
+
error,
|
|
103
109
|
});
|
|
104
110
|
} else {
|
|
105
111
|
console.error(error); // eslint-disable-line
|
|
@@ -108,12 +114,12 @@ export default function Map<
|
|
|
108
114
|
|
|
109
115
|
return () => {
|
|
110
116
|
isMounted = false;
|
|
111
|
-
if (
|
|
117
|
+
if (maplibre) {
|
|
112
118
|
mountedMapsContext?.onMapUnmount(props.id);
|
|
113
119
|
if (props.reuseMaps) {
|
|
114
|
-
|
|
120
|
+
maplibre.recycle();
|
|
115
121
|
} else {
|
|
116
|
-
|
|
122
|
+
maplibre.destroy();
|
|
117
123
|
}
|
|
118
124
|
}
|
|
119
125
|
};
|
|
@@ -129,16 +135,16 @@ export default function Map<
|
|
|
129
135
|
|
|
130
136
|
const style: CSSProperties = useMemo(
|
|
131
137
|
() => ({
|
|
132
|
-
position:
|
|
133
|
-
width:
|
|
134
|
-
height:
|
|
135
|
-
...props.style
|
|
138
|
+
position: "relative",
|
|
139
|
+
width: "100%",
|
|
140
|
+
height: "100%",
|
|
141
|
+
...props.style,
|
|
136
142
|
}),
|
|
137
|
-
[props.style]
|
|
143
|
+
[props.style],
|
|
138
144
|
);
|
|
139
145
|
|
|
140
146
|
const CHILD_CONTAINER_STYLE = {
|
|
141
|
-
height:
|
|
147
|
+
height: "100%",
|
|
142
148
|
};
|
|
143
149
|
|
|
144
150
|
return (
|
|
@@ -146,6 +152,9 @@ export default function Map<
|
|
|
146
152
|
{mapInstance && (
|
|
147
153
|
<MapContext.Provider value={contextValue}>
|
|
148
154
|
<div mapboxgl-children="" style={CHILD_CONTAINER_STYLE}>
|
|
155
|
+
{/* Automatically include Barikoi Logo and Attribution controls */}
|
|
156
|
+
<LogoControl position="bottom-left" />
|
|
157
|
+
<AttributionControl position="bottom-right" />
|
|
149
158
|
{props.children}
|
|
150
159
|
</div>
|
|
151
160
|
</MapContext.Provider>
|
|
@@ -153,3 +162,5 @@ export default function Map<
|
|
|
153
162
|
</div>
|
|
154
163
|
);
|
|
155
164
|
}
|
|
165
|
+
|
|
166
|
+
export const Map: React.FC<MapProps> = React.forwardRef(_Map);
|
package/src/components/marker.ts
CHANGED
|
@@ -1,137 +1,155 @@
|
|
|
1
1
|
/* global document */
|
|
2
|
-
import * as React from
|
|
3
|
-
import {createPortal} from
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { createPortal } from "react-dom";
|
|
4
|
+
import {
|
|
5
|
+
useImperativeHandle,
|
|
6
|
+
useEffect,
|
|
7
|
+
useMemo,
|
|
8
|
+
useRef,
|
|
9
|
+
useContext,
|
|
10
|
+
forwardRef,
|
|
11
|
+
memo,
|
|
12
|
+
} from "react";
|
|
13
|
+
import { applyReactStyle } from "../utils/apply-react-style";
|
|
14
|
+
|
|
15
|
+
import type {
|
|
16
|
+
Popup as PopupInstance,
|
|
17
|
+
Marker as MarkerInstance,
|
|
18
|
+
MarkerOptions,
|
|
19
|
+
} from "../types/lib";
|
|
20
|
+
import type { MarkerEvent, MarkerDragEvent } from "../types/events";
|
|
21
|
+
|
|
22
|
+
import { MapContext } from "./map";
|
|
23
|
+
import { arePointsEqual } from "../utils/deep-equal";
|
|
24
|
+
import { compareClassNames } from "../utils/compare-class-names";
|
|
25
|
+
|
|
26
|
+
export type MarkerProps = MarkerOptions & {
|
|
13
27
|
/** Longitude of the anchor location */
|
|
14
28
|
longitude: number;
|
|
15
29
|
/** Latitude of the anchor location */
|
|
16
30
|
latitude: number;
|
|
17
31
|
|
|
18
|
-
|
|
19
|
-
draggable?: boolean;
|
|
20
|
-
offset?: PointLike;
|
|
21
|
-
pitchAlignment?: string;
|
|
22
|
-
rotation?: number;
|
|
23
|
-
rotationAlignment?: string;
|
|
24
|
-
popup?: any;
|
|
32
|
+
popup?: PopupInstance;
|
|
25
33
|
|
|
26
34
|
/** CSS style override, applied to the control's container */
|
|
27
35
|
style?: React.CSSProperties;
|
|
28
|
-
onClick?: (e: MarkerEvent<
|
|
29
|
-
onDragStart?: (e: MarkerDragEvent
|
|
30
|
-
onDrag?: (e: MarkerDragEvent
|
|
31
|
-
onDragEnd?: (e: MarkerDragEvent
|
|
36
|
+
onClick?: (e: MarkerEvent<MouseEvent>) => void;
|
|
37
|
+
onDragStart?: (e: MarkerDragEvent) => void;
|
|
38
|
+
onDrag?: (e: MarkerDragEvent) => void;
|
|
39
|
+
onDragEnd?: (e: MarkerDragEvent) => void;
|
|
32
40
|
children?: React.ReactNode;
|
|
33
41
|
};
|
|
34
42
|
|
|
35
43
|
/* eslint-disable complexity,max-statements */
|
|
36
|
-
|
|
37
|
-
props: MarkerProps
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
44
|
+
export const Marker: React.FC<MarkerProps> = memo(
|
|
45
|
+
forwardRef((props: MarkerProps, ref: React.Ref<MarkerInstance>) => {
|
|
46
|
+
const { map, mapLib } = useContext(MapContext);
|
|
47
|
+
const thisRef = useRef({ props });
|
|
48
|
+
|
|
49
|
+
const marker: MarkerInstance = useMemo(() => {
|
|
50
|
+
let hasChildren = false;
|
|
51
|
+
React.Children.forEach(props.children, (el) => {
|
|
52
|
+
if (el) {
|
|
53
|
+
hasChildren = true;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
const options = {
|
|
57
|
+
...props,
|
|
58
|
+
element: hasChildren ? document.createElement("div") : undefined,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const mk = new mapLib.Marker(options);
|
|
62
|
+
mk.setLngLat([props.longitude, props.latitude]);
|
|
63
|
+
|
|
64
|
+
mk.getElement().addEventListener("click", (e: MouseEvent) => {
|
|
65
|
+
thisRef.current.props.onClick?.({
|
|
66
|
+
type: "click",
|
|
67
|
+
target: mk,
|
|
68
|
+
originalEvent: e,
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
mk.on("dragstart", (e) => {
|
|
73
|
+
const evt = e as MarkerDragEvent;
|
|
74
|
+
evt.lngLat = marker.getLngLat();
|
|
75
|
+
thisRef.current.props.onDragStart?.(evt);
|
|
76
|
+
});
|
|
77
|
+
mk.on("drag", (e) => {
|
|
78
|
+
const evt = e as MarkerDragEvent;
|
|
79
|
+
evt.lngLat = marker.getLngLat();
|
|
80
|
+
thisRef.current.props.onDrag?.(evt);
|
|
81
|
+
});
|
|
82
|
+
mk.on("dragend", (e) => {
|
|
83
|
+
const evt = e as MarkerDragEvent;
|
|
84
|
+
evt.lngLat = marker.getLngLat();
|
|
85
|
+
thisRef.current.props.onDragEnd?.(evt);
|
|
64
86
|
});
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
marker.
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
marker.
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return createPortal(props.children, marker.getElement());
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export default memo(forwardRef(Marker));
|
|
87
|
+
|
|
88
|
+
return mk;
|
|
89
|
+
}, []);
|
|
90
|
+
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
marker.addTo(map.getMap());
|
|
93
|
+
|
|
94
|
+
return () => {
|
|
95
|
+
marker.remove();
|
|
96
|
+
};
|
|
97
|
+
}, []);
|
|
98
|
+
|
|
99
|
+
const {
|
|
100
|
+
longitude,
|
|
101
|
+
latitude,
|
|
102
|
+
offset,
|
|
103
|
+
style,
|
|
104
|
+
draggable = false,
|
|
105
|
+
popup = null,
|
|
106
|
+
rotation = 0,
|
|
107
|
+
rotationAlignment = "auto",
|
|
108
|
+
pitchAlignment = "auto",
|
|
109
|
+
} = props;
|
|
110
|
+
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
applyReactStyle(marker.getElement(), style);
|
|
113
|
+
}, [style]);
|
|
114
|
+
|
|
115
|
+
useImperativeHandle(ref, () => marker, []);
|
|
116
|
+
|
|
117
|
+
const oldProps = thisRef.current.props;
|
|
118
|
+
if (
|
|
119
|
+
marker.getLngLat().lng !== longitude ||
|
|
120
|
+
marker.getLngLat().lat !== latitude
|
|
121
|
+
) {
|
|
122
|
+
marker.setLngLat([longitude, latitude]);
|
|
123
|
+
}
|
|
124
|
+
if (offset && !arePointsEqual(marker.getOffset(), offset)) {
|
|
125
|
+
marker.setOffset(offset);
|
|
126
|
+
}
|
|
127
|
+
if (marker.isDraggable() !== draggable) {
|
|
128
|
+
marker.setDraggable(draggable);
|
|
129
|
+
}
|
|
130
|
+
if (marker.getRotation() !== rotation) {
|
|
131
|
+
marker.setRotation(rotation);
|
|
132
|
+
}
|
|
133
|
+
if (marker.getRotationAlignment() !== rotationAlignment) {
|
|
134
|
+
marker.setRotationAlignment(rotationAlignment);
|
|
135
|
+
}
|
|
136
|
+
if (marker.getPitchAlignment() !== pitchAlignment) {
|
|
137
|
+
marker.setPitchAlignment(pitchAlignment);
|
|
138
|
+
}
|
|
139
|
+
if (marker.getPopup() !== popup) {
|
|
140
|
+
marker.setPopup(popup);
|
|
141
|
+
}
|
|
142
|
+
const classNameDiff = compareClassNames(
|
|
143
|
+
oldProps.className,
|
|
144
|
+
props.className,
|
|
145
|
+
);
|
|
146
|
+
if (classNameDiff) {
|
|
147
|
+
for (const c of classNameDiff) {
|
|
148
|
+
marker.toggleClassName(c);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
thisRef.current.props = props;
|
|
153
|
+
return createPortal(props.children, marker.getElement());
|
|
154
|
+
}),
|
|
155
|
+
);
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import {useEffect, memo} from
|
|
3
|
-
import {applyReactStyle} from
|
|
4
|
-
import useControl from
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useEffect, memo } from "react";
|
|
3
|
+
import { applyReactStyle } from "../utils/apply-react-style";
|
|
4
|
+
import { useControl } from "./use-control";
|
|
5
5
|
|
|
6
|
-
import type {ControlPosition,
|
|
6
|
+
import type { ControlPosition, NavigationControlOptions } from "../types/lib";
|
|
7
7
|
|
|
8
|
-
export type NavigationControlProps
|
|
8
|
+
export type NavigationControlProps = NavigationControlOptions & {
|
|
9
9
|
/** Placement of the control relative to the map. */
|
|
10
10
|
position?: ControlPosition;
|
|
11
11
|
/** CSS style override, applied to the control's container */
|
|
12
12
|
style?: React.CSSProperties;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
function
|
|
16
|
-
props
|
|
17
|
-
|
|
18
|
-
const ctrl = useControl<ControlT>(({mapLib}) => new mapLib.NavigationControl(props) as ControlT, {
|
|
19
|
-
position: props.position
|
|
15
|
+
function _NavigationControl(props: NavigationControlProps) {
|
|
16
|
+
const ctrl = useControl(({ mapLib }) => new mapLib.NavigationControl(props), {
|
|
17
|
+
position: props.position,
|
|
20
18
|
});
|
|
21
19
|
|
|
22
20
|
useEffect(() => {
|
|
@@ -26,4 +24,5 @@ function NavigationControl<NavigationControlOptions, ControlT extends Navigation
|
|
|
26
24
|
return null;
|
|
27
25
|
}
|
|
28
26
|
|
|
29
|
-
export
|
|
27
|
+
export const NavigationControl: React.FC<NavigationControlProps> =
|
|
28
|
+
memo(_NavigationControl);
|