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
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useEffect, memo } from "react";
|
|
2
|
+
import { applyReactStyle } from "../utils/apply-react-style.js";
|
|
3
|
+
import { useControl } from "./use-control.js";
|
|
4
|
+
function _LogoControl(props) {
|
|
5
|
+
const ctrl = useControl(_ref => {
|
|
6
|
+
let {
|
|
7
|
+
mapLib
|
|
8
|
+
} = _ref;
|
|
9
|
+
return new mapLib.LogoControl(props);
|
|
10
|
+
}, {
|
|
11
|
+
position: props.position
|
|
12
|
+
});
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
applyReactStyle(ctrl._container, props.style);
|
|
15
|
+
const logoElement = ctrl._container?.querySelector(".maplibregl-ctrl-logo");
|
|
16
|
+
if (logoElement) {
|
|
17
|
+
logoElement.href = "https://barikoi.com/";
|
|
18
|
+
logoElement.setAttribute("aria-label", "Barikoi logo");
|
|
19
|
+
logoElement.target = "_blank";
|
|
20
|
+
logoElement.rel = "noopener nofollow";
|
|
21
|
+
logoElement.style.cursor = "pointer";
|
|
22
|
+
logoElement.replaceWith(logoElement.cloneNode(true));
|
|
23
|
+
}
|
|
24
|
+
}, [props.style, ctrl._container]);
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
export const LogoControl = memo(_LogoControl);
|
|
28
|
+
//# sourceMappingURL=logo-control.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logo-control.js","names":["useEffect","memo","applyReactStyle","useControl","_LogoControl","props","ctrl","_ref","mapLib","LogoControl","position","_container","style","logoElement","querySelector","href","setAttribute","target","rel","cursor","replaceWith","cloneNode"],"sources":["../../src/components/logo-control.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */\nimport * as React from \"react\";\nimport { useEffect, memo } from \"react\";\nimport { applyReactStyle } from \"../utils/apply-react-style\";\nimport { useControl } from \"./use-control\";\n\nimport type { ControlPosition, LogoControlOptions } from \"../types/lib\";\n\nexport type LogoControlProps = LogoControlOptions & {\n /** Placement of the control relative to the map. */\n position?: ControlPosition;\n /** CSS style override, applied to the control's container */\n style?: React.CSSProperties;\n};\n\nfunction _LogoControl(props: LogoControlProps) {\n const ctrl = useControl(({ mapLib }) => new mapLib.LogoControl(props), {\n position: props.position,\n });\n\n useEffect(() => {\n applyReactStyle(ctrl._container, props.style);\n\n // Update the DOM structure and attributes directly\n const logoElement = ctrl._container?.querySelector(\n \".maplibregl-ctrl-logo\",\n ) as HTMLAnchorElement | null;\n if (logoElement) {\n // Update the link attributes\n logoElement.href = \"https://barikoi.com/\";\n logoElement.setAttribute(\"aria-label\", \"Barikoi logo\");\n logoElement.target = \"_blank\";\n logoElement.rel = \"noopener nofollow\";\n logoElement.style.cursor = \"pointer\";\n\n // Remove any existing click handlers\n logoElement.replaceWith(logoElement.cloneNode(true));\n }\n }, [props.style, ctrl._container]);\n\n return null;\n}\n\nexport const LogoControl: React.FC<LogoControlProps> = memo(_LogoControl);\n"],"mappings":"AAEA,SAASA,SAAS,EAAEC,IAAI,QAAQ,OAAO;AAAC,SAC/BC,eAAe;AAAA,SACfC,UAAU;AAWnB,SAASC,YAAYA,CAACC,KAAuB,EAAE;EAC7C,MAAMC,IAAI,GAAGH,UAAU,CAACI,IAAA;IAAA,IAAC;MAAEC;IAAO,CAAC,GAAAD,IAAA;IAAA,OAAK,IAAIC,MAAM,CAACC,WAAW,CAACJ,KAAK,CAAC;EAAA,GAAE;IACrEK,QAAQ,EAAEL,KAAK,CAACK;EAClB,CAAC,CAAC;EAEFV,SAAS,CAAC,MAAM;IACdE,eAAe,CAACI,IAAI,CAACK,UAAU,EAAEN,KAAK,CAACO,KAAK,CAAC;IAG7C,MAAMC,WAAW,GAAGP,IAAI,CAACK,UAAU,EAAEG,aAAa,CAChD,uBACF,CAA6B;IAC7B,IAAID,WAAW,EAAE;MAEfA,WAAW,CAACE,IAAI,GAAG,sBAAsB;MACzCF,WAAW,CAACG,YAAY,CAAC,YAAY,EAAE,cAAc,CAAC;MACtDH,WAAW,CAACI,MAAM,GAAG,QAAQ;MAC7BJ,WAAW,CAACK,GAAG,GAAG,mBAAmB;MACrCL,WAAW,CAACD,KAAK,CAACO,MAAM,GAAG,SAAS;MAGpCN,WAAW,CAACO,WAAW,CAACP,WAAW,CAACQ,SAAS,CAAC,IAAI,CAAC,CAAC;IACtD;EACF,CAAC,EAAE,CAAChB,KAAK,CAACO,KAAK,EAAEN,IAAI,CAACK,UAAU,CAAC,CAAC;EAElC,OAAO,IAAI;AACb;AAEA,OAAO,MAAMF,WAAuC,GAAGR,IAAI,CAACG,YAAY,CAAC","ignoreList":[]}
|
package/dist/components/map.d.ts
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import {
|
|
3
|
-
import { MapRef } from
|
|
4
|
-
import type { CSSProperties } from
|
|
5
|
-
import { GlobalSettings } from
|
|
6
|
-
import type { MapLib,
|
|
7
|
-
export type MapContextValue
|
|
8
|
-
mapLib: MapLib
|
|
9
|
-
map: MapRef
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { MaplibreProps } from "../maplibre/maplibre";
|
|
3
|
+
import { MapRef } from "../maplibre/create-ref";
|
|
4
|
+
import type { CSSProperties } from "react";
|
|
5
|
+
import { GlobalSettings } from "../utils/set-globals";
|
|
6
|
+
import type { MapLib, MapOptions } from "../types/lib";
|
|
7
|
+
export type MapContextValue = {
|
|
8
|
+
mapLib: MapLib;
|
|
9
|
+
map: MapRef;
|
|
10
10
|
};
|
|
11
|
-
export declare const MapContext: React.Context<MapContextValue
|
|
12
|
-
type MapInitOptions
|
|
13
|
-
export type MapProps
|
|
14
|
-
mapLib?: MapLib
|
|
11
|
+
export declare const MapContext: React.Context<MapContextValue>;
|
|
12
|
+
type MapInitOptions = Omit<MapOptions, "style" | "container" | "bounds" | "fitBoundsOptions" | "center">;
|
|
13
|
+
export type MapProps = MapInitOptions & MaplibreProps & GlobalSettings & {
|
|
14
|
+
mapLib?: MapLib | Promise<MapLib>;
|
|
15
15
|
reuseMaps?: boolean;
|
|
16
16
|
/** Map container id */
|
|
17
17
|
id?: string;
|
|
18
18
|
/** Map container CSS style */
|
|
19
19
|
style?: CSSProperties;
|
|
20
|
-
children?:
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
children?: React.ReactNode;
|
|
21
|
+
/** Show Barikoi logo (default: true) */
|
|
22
|
+
showBarikoiLogo?: boolean;
|
|
23
|
+
/** Show Attribution (default: true) */
|
|
24
|
+
showAttribution?: boolean;
|
|
25
|
+
} & React.RefAttributes<MapRef>;
|
|
26
|
+
export declare const Map: React.FC<MapProps>;
|
|
23
27
|
export {};
|
package/dist/components/map.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { useState, useRef, useEffect, useContext, useMemo, useImperativeHandle } from
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useState, useRef, useEffect, useContext, useMemo, useImperativeHandle } from "react";
|
|
3
3
|
import { MountedMapsContext } from "./use-map.js";
|
|
4
|
-
import
|
|
5
|
-
import createRef from "../
|
|
4
|
+
import Maplibre from "../maplibre/maplibre.js";
|
|
5
|
+
import createRef from "../maplibre/create-ref.js";
|
|
6
6
|
import useIsomorphicLayoutEffect from "../utils/use-isomorphic-layout-effect.js";
|
|
7
7
|
import setGlobals from "../utils/set-globals.js";
|
|
8
|
+
import { LogoControl } from "./logo-control.js";
|
|
9
|
+
import { AttributionControl } from "./attribution-control.js";
|
|
8
10
|
export const MapContext = React.createContext(null);
|
|
9
|
-
|
|
11
|
+
function _Map(props, ref) {
|
|
10
12
|
const mountedMapsContext = useContext(MountedMapsContext);
|
|
11
13
|
const [mapInstance, setMapInstance] = useState(null);
|
|
12
14
|
const containerRef = useRef();
|
|
@@ -19,40 +21,39 @@ export default function Map(props, ref, defaultLib) {
|
|
|
19
21
|
useEffect(() => {
|
|
20
22
|
const mapLib = props.mapLib;
|
|
21
23
|
let isMounted = true;
|
|
22
|
-
let
|
|
23
|
-
Promise.resolve(mapLib ||
|
|
24
|
+
let maplibre;
|
|
25
|
+
Promise.resolve(mapLib || import("maplibre-gl")).then(module => {
|
|
24
26
|
if (!isMounted) {
|
|
25
27
|
return;
|
|
26
28
|
}
|
|
27
29
|
if (!module) {
|
|
28
|
-
throw new Error(
|
|
30
|
+
throw new Error("Invalid mapLib");
|
|
29
31
|
}
|
|
30
|
-
const mapboxgl =
|
|
32
|
+
const mapboxgl = "Map" in module ? module : module.default;
|
|
31
33
|
if (!mapboxgl.Map) {
|
|
32
|
-
throw new Error(
|
|
34
|
+
throw new Error("Invalid mapLib");
|
|
33
35
|
}
|
|
34
36
|
setGlobals(mapboxgl, props);
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
contextValue.mapLib = mapboxgl;
|
|
44
|
-
setMapInstance(mapbox);
|
|
45
|
-
mountedMapsContext?.onMapMount(contextValue.map, props.id);
|
|
46
|
-
} else {
|
|
47
|
-
throw new Error('Map is not supported by this browser');
|
|
37
|
+
if (props.reuseMaps) {
|
|
38
|
+
maplibre = Maplibre.reuse(props, containerRef.current);
|
|
39
|
+
}
|
|
40
|
+
if (!maplibre) {
|
|
41
|
+
maplibre = new Maplibre(mapboxgl.Map, {
|
|
42
|
+
...props,
|
|
43
|
+
attributionControl: false
|
|
44
|
+
}, containerRef.current);
|
|
48
45
|
}
|
|
46
|
+
contextValue.map = createRef(maplibre);
|
|
47
|
+
contextValue.mapLib = mapboxgl;
|
|
48
|
+
setMapInstance(maplibre);
|
|
49
|
+
mountedMapsContext?.onMapMount(contextValue.map, props.id);
|
|
49
50
|
}).catch(error => {
|
|
50
51
|
const {
|
|
51
52
|
onError
|
|
52
53
|
} = props;
|
|
53
54
|
if (onError) {
|
|
54
55
|
onError({
|
|
55
|
-
type:
|
|
56
|
+
type: "error",
|
|
56
57
|
target: null,
|
|
57
58
|
originalEvent: null,
|
|
58
59
|
error
|
|
@@ -63,12 +64,12 @@ export default function Map(props, ref, defaultLib) {
|
|
|
63
64
|
});
|
|
64
65
|
return () => {
|
|
65
66
|
isMounted = false;
|
|
66
|
-
if (
|
|
67
|
+
if (maplibre) {
|
|
67
68
|
mountedMapsContext?.onMapUnmount(props.id);
|
|
68
69
|
if (props.reuseMaps) {
|
|
69
|
-
|
|
70
|
+
maplibre.recycle();
|
|
70
71
|
} else {
|
|
71
|
-
|
|
72
|
+
maplibre.destroy();
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
};
|
|
@@ -80,13 +81,13 @@ export default function Map(props, ref, defaultLib) {
|
|
|
80
81
|
});
|
|
81
82
|
useImperativeHandle(ref, () => contextValue.map, [mapInstance]);
|
|
82
83
|
const style = useMemo(() => ({
|
|
83
|
-
position:
|
|
84
|
-
width:
|
|
85
|
-
height:
|
|
84
|
+
position: "relative",
|
|
85
|
+
width: "100%",
|
|
86
|
+
height: "100%",
|
|
86
87
|
...props.style
|
|
87
88
|
}), [props.style]);
|
|
88
89
|
const CHILD_CONTAINER_STYLE = {
|
|
89
|
-
height:
|
|
90
|
+
height: "100%"
|
|
90
91
|
};
|
|
91
92
|
return React.createElement("div", {
|
|
92
93
|
id: props.id,
|
|
@@ -97,6 +98,11 @@ export default function Map(props, ref, defaultLib) {
|
|
|
97
98
|
}, React.createElement("div", {
|
|
98
99
|
"mapboxgl-children": "",
|
|
99
100
|
style: CHILD_CONTAINER_STYLE
|
|
100
|
-
},
|
|
101
|
+
}, React.createElement(LogoControl, {
|
|
102
|
+
position: "bottom-left"
|
|
103
|
+
}), React.createElement(AttributionControl, {
|
|
104
|
+
position: "bottom-right"
|
|
105
|
+
}), props.children)));
|
|
101
106
|
}
|
|
107
|
+
export const Map = React.forwardRef(_Map);
|
|
102
108
|
//# sourceMappingURL=map.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.js","names":["React","useState","useRef","useEffect","useContext","useMemo","useImperativeHandle","MountedMapsContext","
|
|
1
|
+
{"version":3,"file":"map.js","names":["React","useState","useRef","useEffect","useContext","useMemo","useImperativeHandle","MountedMapsContext","Maplibre","createRef","useIsomorphicLayoutEffect","setGlobals","LogoControl","AttributionControl","MapContext","createContext","_Map","props","ref","mountedMapsContext","mapInstance","setMapInstance","containerRef","current","contextValue","mapLib","map","isMounted","maplibre","Promise","resolve","then","module","Error","mapboxgl","default","Map","reuseMaps","reuse","attributionControl","onMapMount","id","catch","error","onError","type","target","originalEvent","console","onMapUnmount","recycle","destroy","setProps","style","position","width","height","CHILD_CONTAINER_STYLE","createElement","Provider","value","children","forwardRef"],"sources":["../../src/components/map.tsx"],"sourcesContent":["/* eslint-disable react/display-name */\n/* eslint-disable react/no-unknown-property */\nimport * as React from \"react\";\nimport {\n useState,\n useRef,\n useEffect,\n useContext,\n useMemo,\n useImperativeHandle,\n} from \"react\";\n\nimport { MountedMapsContext } from \"./use-map\";\nimport Maplibre, { MaplibreProps } from \"../maplibre/maplibre\";\nimport createRef, { MapRef } from \"../maplibre/create-ref\";\n\nimport type { CSSProperties } from \"react\";\nimport useIsomorphicLayoutEffect from \"../utils/use-isomorphic-layout-effect\";\nimport setGlobals, { GlobalSettings } from \"../utils/set-globals\";\nimport type { MapLib, MapOptions } from \"../types/lib\";\nimport { LogoControl } from \"./logo-control\";\nimport { AttributionControl } from \"./attribution-control\";\n\nexport type MapContextValue = {\n mapLib: MapLib;\n map: MapRef;\n};\n\nexport const MapContext = React.createContext<MapContextValue>(null);\n\ntype MapInitOptions = Omit<\n MapOptions,\n \"style\" | \"container\" | \"bounds\" | \"fitBoundsOptions\" | \"center\"\n>;\n\nexport type MapProps = MapInitOptions &\n MaplibreProps &\n GlobalSettings & {\n mapLib?: MapLib | Promise<MapLib>;\n reuseMaps?: boolean;\n /** Map container id */\n id?: string;\n /** Map container CSS style */\n style?: CSSProperties;\n children?: React.ReactNode;\n /** Show Barikoi logo (default: true) */\n showBarikoiLogo?: boolean;\n /** Show Attribution (default: true) */\n showAttribution?: boolean;\n } & React.RefAttributes<MapRef>;\n\nfunction _Map(props: MapProps, ref: React.Ref<MapRef>) {\n const mountedMapsContext = useContext(MountedMapsContext);\n const [mapInstance, setMapInstance] = useState<Maplibre>(null);\n const containerRef = useRef();\n\n const { current: contextValue } = useRef<MapContextValue>({\n mapLib: null,\n map: null,\n });\n\n useEffect(() => {\n const mapLib = props.mapLib;\n let isMounted = true;\n let maplibre: Maplibre;\n\n Promise.resolve(mapLib || import(\"maplibre-gl\"))\n .then((module: MapLib | { default: MapLib }) => {\n if (!isMounted) {\n return;\n }\n if (!module) {\n throw new Error(\"Invalid mapLib\");\n }\n const mapboxgl = \"Map\" in module ? module : module.default;\n if (!mapboxgl.Map) {\n throw new Error(\"Invalid mapLib\");\n }\n\n setGlobals(mapboxgl, props);\n if (props.reuseMaps) {\n maplibre = Maplibre.reuse(props, containerRef.current);\n }\n if (!maplibre) {\n maplibre = new Maplibre(\n mapboxgl.Map,\n {\n ...props,\n // @ts-ignore\n attributionControl: false,\n },\n containerRef.current,\n );\n }\n contextValue.map = createRef(maplibre);\n contextValue.mapLib = mapboxgl;\n\n setMapInstance(maplibre);\n mountedMapsContext?.onMapMount(contextValue.map, props.id);\n })\n .catch((error) => {\n const { onError } = props;\n if (onError) {\n onError({\n type: \"error\",\n target: null,\n originalEvent: null,\n error,\n });\n } else {\n console.error(error); // eslint-disable-line\n }\n });\n\n return () => {\n isMounted = false;\n if (maplibre) {\n mountedMapsContext?.onMapUnmount(props.id);\n if (props.reuseMaps) {\n maplibre.recycle();\n } else {\n maplibre.destroy();\n }\n }\n };\n }, []);\n\n useIsomorphicLayoutEffect(() => {\n if (mapInstance) {\n mapInstance.setProps(props);\n }\n });\n\n useImperativeHandle(ref, () => contextValue.map, [mapInstance]);\n\n const style: CSSProperties = useMemo(\n () => ({\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n ...props.style,\n }),\n [props.style],\n );\n\n const CHILD_CONTAINER_STYLE = {\n height: \"100%\",\n };\n\n return (\n <div id={props.id} ref={containerRef} style={style}>\n {mapInstance && (\n <MapContext.Provider value={contextValue}>\n <div mapboxgl-children=\"\" style={CHILD_CONTAINER_STYLE}>\n {/* Automatically include Barikoi Logo and Attribution controls */}\n <LogoControl position=\"bottom-left\" />\n <AttributionControl position=\"bottom-right\" />\n {props.children}\n </div>\n </MapContext.Provider>\n )}\n </div>\n );\n}\n\nexport const Map: React.FC<MapProps> = React.forwardRef(_Map);\n"],"mappings":"AAEA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SACEC,QAAQ,EACRC,MAAM,EACNC,SAAS,EACTC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AQ,CAACnC,KAAK,CAAC;IAC7B;EACF,CAAC,CAAC;EAEFX,mBAAmB,CAACY,GAAG,EAAE,MAAMM,YAAY,CAACE,GAAG,EAAE,CAACN,WAAW,CAAC,CAAC;EAE/D,MAAMiC,KAAoB,GAAGhD,OAAO,CAClC,OAAO;IACLiD,QAAQ,EAAE,UAAU;IACpBC,KAAK,EAAE,MAAM;IACbC,MAAM,EAAE,MAAM;IACd,GAAGvC,KAAK,CAACoC;EACX,CAAC,CAAC,EACF,CAACpC,KAAK,CAACoC,KAAK,CACd,CAAC;EAED,MAAMI,qBAAqB,GAAG;IAC5BD,MAAM,EAAE;EACV,CAAC;EAED,OACExD,KAAA,CAAA0D,aAAA;IAAKjB,EAAE,EAAExB,KAAK,CAACwB,EAAG;IAACvB,GAAG,EAAEI,YAAa;IAAC+B,KAAK,EAAEA;EAAM,GAChDjC,WAAW,IACVpB,KAAA,CAAA0D,aAAA,CAAC5C,UAAU,CAAC6C,QAAQ;IAACC,KAAK,EAAEpC;EAAa,GACvCxB,KAAA,CAAA0D,aAAA;IAAK,qBAAkB,EAAE;IAACL,KAAK,EAAEI;EAAsB,GAErDzD,KAAA,CAAA0D,aAAA,CAAC9C,WAAW;IAAC0C,QAAQ,EAAC;EAAa,CAAE,CAAC,EACtCtD,KAAA,CAAA0D,aAAA,CAAC7C,kBAAkB;IAACyC,QAAQ,EAAC;EAAc,CAAE,CAAC,EAC7CrC,KAAK,CAAC4C,QACJ,CACc,CAEpB,CAAC;AAEV;AAEA,OAAO,MAAMzB,GAAuB,GAAGpC,KAAK,CAAC8D,UAAU,CAAC9C,IAAI,CAAC","ignoreList":[]}
|
|
@@ -1,41 +1,18 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import type {
|
|
3
|
-
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { Popup as PopupInstance, MarkerOptions } from "../types/lib";
|
|
3
|
+
import type { MarkerEvent, MarkerDragEvent } from "../types/events";
|
|
4
|
+
export type MarkerProps = MarkerOptions & {
|
|
4
5
|
/** Longitude of the anchor location */
|
|
5
6
|
longitude: number;
|
|
6
7
|
/** Latitude of the anchor location */
|
|
7
8
|
latitude: number;
|
|
8
|
-
|
|
9
|
-
offset?: PointLike;
|
|
10
|
-
pitchAlignment?: string;
|
|
11
|
-
rotation?: number;
|
|
12
|
-
rotationAlignment?: string;
|
|
13
|
-
popup?: any;
|
|
9
|
+
popup?: PopupInstance;
|
|
14
10
|
/** CSS style override, applied to the control's container */
|
|
15
11
|
style?: React.CSSProperties;
|
|
16
|
-
onClick?: (e: MarkerEvent<
|
|
17
|
-
onDragStart?: (e: MarkerDragEvent
|
|
18
|
-
onDrag?: (e: MarkerDragEvent
|
|
19
|
-
onDragEnd?: (e: MarkerDragEvent
|
|
12
|
+
onClick?: (e: MarkerEvent<MouseEvent>) => void;
|
|
13
|
+
onDragStart?: (e: MarkerDragEvent) => void;
|
|
14
|
+
onDrag?: (e: MarkerDragEvent) => void;
|
|
15
|
+
onDragEnd?: (e: MarkerDragEvent) => void;
|
|
20
16
|
children?: React.ReactNode;
|
|
21
17
|
};
|
|
22
|
-
declare const
|
|
23
|
-
/** Longitude of the anchor location */
|
|
24
|
-
longitude: number;
|
|
25
|
-
/** Latitude of the anchor location */
|
|
26
|
-
latitude: number;
|
|
27
|
-
draggable?: boolean;
|
|
28
|
-
offset?: PointLike;
|
|
29
|
-
pitchAlignment?: string;
|
|
30
|
-
rotation?: number;
|
|
31
|
-
rotationAlignment?: string;
|
|
32
|
-
popup?: any;
|
|
33
|
-
/** CSS style override, applied to the control's container */
|
|
34
|
-
style?: React.CSSProperties;
|
|
35
|
-
onClick?: (e: MarkerEvent<MarkerInstance, MouseEvent>) => void;
|
|
36
|
-
onDragStart?: (e: MarkerDragEvent<MarkerInstance>) => void;
|
|
37
|
-
onDrag?: (e: MarkerDragEvent<MarkerInstance>) => void;
|
|
38
|
-
onDragEnd?: (e: MarkerDragEvent<MarkerInstance>) => void;
|
|
39
|
-
children?: React.ReactNode;
|
|
40
|
-
} & React.RefAttributes<MarkerInstance>>>;
|
|
41
|
-
export default _default;
|
|
18
|
+
export declare const Marker: React.FC<MarkerProps>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { createPortal } from
|
|
3
|
-
import { useImperativeHandle, useEffect, useMemo, useRef, useContext, forwardRef, memo } from
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { createPortal } from "react-dom";
|
|
3
|
+
import { useImperativeHandle, useEffect, useMemo, useRef, useContext, forwardRef, memo } from "react";
|
|
4
4
|
import { applyReactStyle } from "../utils/apply-react-style.js";
|
|
5
5
|
import { MapContext } from "./map.js";
|
|
6
6
|
import { arePointsEqual } from "../utils/deep-equal.js";
|
|
7
|
-
|
|
7
|
+
import { compareClassNames } from "../utils/compare-class-names.js";
|
|
8
|
+
export const Marker = memo(forwardRef((props, ref) => {
|
|
8
9
|
const {
|
|
9
10
|
map,
|
|
10
11
|
mapLib
|
|
@@ -12,7 +13,6 @@ function Marker(props, ref) {
|
|
|
12
13
|
const thisRef = useRef({
|
|
13
14
|
props
|
|
14
15
|
});
|
|
15
|
-
thisRef.current.props = props;
|
|
16
16
|
const marker = useMemo(() => {
|
|
17
17
|
let hasChildren = false;
|
|
18
18
|
React.Children.forEach(props.children, el => {
|
|
@@ -22,28 +22,28 @@ function Marker(props, ref) {
|
|
|
22
22
|
});
|
|
23
23
|
const options = {
|
|
24
24
|
...props,
|
|
25
|
-
element: hasChildren ? document.createElement(
|
|
25
|
+
element: hasChildren ? document.createElement("div") : undefined
|
|
26
26
|
};
|
|
27
27
|
const mk = new mapLib.Marker(options);
|
|
28
28
|
mk.setLngLat([props.longitude, props.latitude]);
|
|
29
|
-
mk.getElement().addEventListener(
|
|
29
|
+
mk.getElement().addEventListener("click", e => {
|
|
30
30
|
thisRef.current.props.onClick?.({
|
|
31
|
-
type:
|
|
31
|
+
type: "click",
|
|
32
32
|
target: mk,
|
|
33
33
|
originalEvent: e
|
|
34
34
|
});
|
|
35
35
|
});
|
|
36
|
-
mk.on(
|
|
36
|
+
mk.on("dragstart", e => {
|
|
37
37
|
const evt = e;
|
|
38
38
|
evt.lngLat = marker.getLngLat();
|
|
39
39
|
thisRef.current.props.onDragStart?.(evt);
|
|
40
40
|
});
|
|
41
|
-
mk.on(
|
|
41
|
+
mk.on("drag", e => {
|
|
42
42
|
const evt = e;
|
|
43
43
|
evt.lngLat = marker.getLngLat();
|
|
44
44
|
thisRef.current.props.onDrag?.(evt);
|
|
45
45
|
});
|
|
46
|
-
mk.on(
|
|
46
|
+
mk.on("dragend", e => {
|
|
47
47
|
const evt = e;
|
|
48
48
|
evt.lngLat = marker.getLngLat();
|
|
49
49
|
thisRef.current.props.onDragEnd?.(evt);
|
|
@@ -64,13 +64,14 @@ function Marker(props, ref) {
|
|
|
64
64
|
draggable = false,
|
|
65
65
|
popup = null,
|
|
66
66
|
rotation = 0,
|
|
67
|
-
rotationAlignment =
|
|
68
|
-
pitchAlignment =
|
|
67
|
+
rotationAlignment = "auto",
|
|
68
|
+
pitchAlignment = "auto"
|
|
69
69
|
} = props;
|
|
70
70
|
useEffect(() => {
|
|
71
71
|
applyReactStyle(marker.getElement(), style);
|
|
72
72
|
}, [style]);
|
|
73
73
|
useImperativeHandle(ref, () => marker, []);
|
|
74
|
+
const oldProps = thisRef.current.props;
|
|
74
75
|
if (marker.getLngLat().lng !== longitude || marker.getLngLat().lat !== latitude) {
|
|
75
76
|
marker.setLngLat([longitude, latitude]);
|
|
76
77
|
}
|
|
@@ -92,7 +93,13 @@ function Marker(props, ref) {
|
|
|
92
93
|
if (marker.getPopup() !== popup) {
|
|
93
94
|
marker.setPopup(popup);
|
|
94
95
|
}
|
|
96
|
+
const classNameDiff = compareClassNames(oldProps.className, props.className);
|
|
97
|
+
if (classNameDiff) {
|
|
98
|
+
for (const c of classNameDiff) {
|
|
99
|
+
marker.toggleClassName(c);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
thisRef.current.props = props;
|
|
95
103
|
return createPortal(props.children, marker.getElement());
|
|
96
|
-
}
|
|
97
|
-
export default memo(forwardRef(Marker));
|
|
104
|
+
}));
|
|
98
105
|
//# sourceMappingURL=marker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marker.js","names":["React","createPortal","useImperativeHandle","useEffect","useMemo","useRef","useContext","forwardRef","memo","applyReactStyle","MapContext","arePointsEqual","Marker","props","ref","map","mapLib","thisRef","
|
|
1
|
+
{"version":3,"file":"marker.js","names":["React","createPortal","useImperativeHandle","useEffect","useMemo","useRef","useContext","forwardRef","memo","applyReactStyle","MapContext","arePointsEqual","compareClassNames","Marker","props","ref","map","mapLib","thisRef","marker","hasChildren","Children","forEach","children","el","options","element","document","createElement","undefined","mk","setLngLat","longitude","latitude","getElement","addEventListener","e","current","onClick","type","target","originalEvent","on","evt","lngLat","getLngLat","onDragStart","onDrag","onDragEnd","addTo","getMap","remove","offset","style","draggable","popup","rotation","rotationAlignment","pitchAlignment","oldProps","lng","lat","getOffset","setOffset","isDraggable","setDraggable","getRotation","setRotation","getRotationAlignment","setRotationAlignment","getPitchAlignment","setPitchAlignment","getPopup","setPopup","classNameDiff","className","c","toggleClassName"],"sources":["../../src/components/marker.ts"],"sourcesContent":["/* global document */\nimport * as React from \"react\";\nimport { createPortal } from \"react-dom\";\nimport {\n useImperativeHandle,\n useEffect,\n useMemo,\n useRef,\n useContext,\n forwardRef,\n memo,\n} from \"react\";\nimport { applyReactStyle } from \"../utils/apply-react-style\";\n\nimport type {\n Popup as PopupInstance,\n Marker as MarkerInstance,\n MarkerOptions,\n} from \"../types/lib\";\nimport type { MarkerEvent, MarkerDragEvent } from \"../types/events\";\n\nimport { MapContext } from \"./map\";\nimport { arePointsEqual } from \"../utils/deep-equal\";\nimport { compareClassNames } from \"../utils/compare-class-names\";\n\nexport type MarkerProps = MarkerOptions & {\n /** Longitude of the anchor location */\n longitude: number;\n /** Latitude of the anchor location */\n latitude: number;\n\n popup?: PopupInstance;\n\n /** CSS style override, applied to the control's container */\n style?: React.CSSProperties;\n onClick?: (e: MarkerEvent<MouseEvent>) => void;\n onDragStart?: (e: MarkerDragEvent) => void;\n onDrag?: (e: MarkerDragEvent) => void;\n onDragEnd?: (e: MarkerDragEvent) => void;\n children?: React.ReactNode;\n};\n\n/* eslint-disable complexity,max-statements */\nexport const Marker: React.FC<MarkerProps> = memo(\n forwardRef((props: MarkerProps, ref: React.Ref<MarkerInstance>) => {\n const { map, mapLib } = useContext(MapContext);\n const thisRef = useRef({ props });\n\n const marker: MarkerInstance = useMemo(() => {\n let hasChildren = false;\n React.Children.forEach(props.children, (el) => {\n if (el) {\n hasChildren = true;\n }\n });\n const options = {\n ...props,\n element: hasChildren ? document.createElement(\"div\") : undefined,\n };\n\n const mk = new mapLib.Marker(options);\n mk.setLngLat([props.longitude, props.latitude]);\n\n mk.getElement().addEventListener(\"click\", (e: MouseEvent) => {\n thisRef.current.props.onClick?.({\n type: \"click\",\n target: mk,\n originalEvent: e,\n });\n });\n\n mk.on(\"dragstart\", (e) => {\n const evt = e as MarkerDragEvent;\n evt.lngLat = marker.getLngLat();\n thisRef.current.props.onDragStart?.(evt);\n });\n mk.on(\"drag\", (e) => {\n const evt = e as MarkerDragEvent;\n evt.lngLat = marker.getLngLat();\n thisRef.current.props.onDrag?.(evt);\n });\n mk.on(\"dragend\", (e) => {\n const evt = e as MarkerDragEvent;\n evt.lngLat = marker.getLngLat();\n thisRef.current.props.onDragEnd?.(evt);\n });\n\n return mk;\n }, []);\n\n useEffect(() => {\n marker.addTo(map.getMap());\n\n return () => {\n marker.remove();\n };\n }, []);\n\n const {\n longitude,\n latitude,\n offset,\n style,\n draggable = false,\n popup = null,\n rotation = 0,\n rotationAlignment = \"auto\",\n pitchAlignment = \"auto\",\n } = props;\n\n useEffect(() => {\n applyReactStyle(marker.getElement(), style);\n }, [style]);\n\n useImperativeHandle(ref, () => marker, []);\n\n const oldProps = thisRef.current.props;\n if (\n marker.getLngLat().lng !== longitude ||\n marker.getLngLat().lat !== latitude\n ) {\n marker.setLngLat([longitude, latitude]);\n }\n if (offset && !arePointsEqual(marker.getOffset(), offset)) {\n marker.setOffset(offset);\n }\n if (marker.isDraggable() !== draggable) {\n marker.setDraggable(draggable);\n }\n if (marker.getRotation() !== rotation) {\n marker.setRotation(rotation);\n }\n if (marker.getRotationAlignment() !== rotationAlignment) {\n marker.setRotationAlignment(rotationAlignment);\n }\n if (marker.getPitchAlignment() !== pitchAlignment) {\n marker.setPitchAlignment(pitchAlignment);\n }\n if (marker.getPopup() !== popup) {\n marker.setPopup(popup);\n }\n const classNameDiff = compareClassNames(\n oldProps.className,\n props.className,\n );\n if (classNameDiff) {\n for (const c of classNameDiff) {\n marker.toggleClassName(c);\n }\n }\n\n thisRef.current.props = props;\n return createPortal(props.children, marker.getElement());\n }),\n);\n"],"mappings":"AACA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,YAAY,QAAQ,WAAW;AACxC,SACEC,mBAAmB,EACnBC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,UAAU,EACVC,UAAU,EACVC,IAAI,QACC,OAAO;AAAC,SACNC,eAAe;AAAA,SASfC,UAAU;AAAA,SACVC,cAAc;AAAA,SACdC,iBAAiB;AAoB1B,OAAO,MAAMC,MAA6B,GAAGL,IAAI,CAC/CD,UAAU,CAAC,CAACO,KAAkB,EAAEC,GAA8B,KAAK;EACjE,MAAM;IAAEC,GAAG;IAAEC;EAAO,CAAC,GAAGX,UAAU,CAACI,UAAU,CAAC;EAC9C,MAAMQ,OAAO,GAAGb,MAAM,CAAC;IAAES;EAAM,CAAC,CAAC;EAEjC,MAAMK,MAAsB,GAAGf,OAAO,CAAC,MAAM;IAC3C,IAAIgB,WAAW,GAAG,KAAK;IACvBpB,KAAK,CAACqB,QAAQ,CAACC,OAAO,CAACR,KAAK,CAACS,QAAQ,EAAGC,EAAE,IAAK;MAC7C,IAAIA,EAAE,EAAE;QACNJ,WAAW,GA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AAC,CAAC,KAAKV,SAAS,EAAE;IACtCnC,MAAM,CAAC8C,YAAY,CAACX,SAAS,CAAC;EAChC;EACA,IAAInC,MAAM,CAAC+C,WAAW,CAAC,CAAC,KAAKV,QAAQ,EAAE;IACrCrC,MAAM,CAACgD,WAAW,CAACX,QAAQ,CAAC;EAC9B;EACA,IAAIrC,MAAM,CAACiD,oBAAoB,CAAC,CAAC,KAAKX,iBAAiB,EAAE;IACvDtC,MAAM,CAACkD,oBAAoB,CAACZ,iBAAiB,CAAC;EAChD;EACA,IAAItC,MAAM,CAACmD,iBAAiB,CAAC,CAAC,KAAKZ,cAAc,EAAE;IACjDvC,MAAM,CAACoD,iBAAiB,CAACb,cAAc,CAAC;EAC1C;EACA,IAAIvC,MAAM,CAACqD,QAAQ,CAAC,CAAC,KAAKjB,KAAK,EAAE;IAC/BpC,MAAM,CAACsD,QAAQ,CAAClB,KAAK,CAAC;EACxB;EACA,MAAMmB,aAAa,GAAG9D,iBAAiB,CACrC+C,QAAQ,CAACgB,SAAS,EAClB7D,KAAK,CAAC6D,SACR,CAAC;EACD,IAAID,aAAa,EAAE;IACjB,KAAK,MAAME,CAAC,IAAIF,aAAa,EAAE;MAC7BvD,MAAM,CAAC0D,eAAe,CAACD,CAAC,CAAC;IAC3B;EACF;EAEA1D,OAAO,CAACmB,OAAO,CAACvB,KAAK,GAAGA,KAAK;EAC7B,OAAOb,YAAY,CAACa,KAAK,CAACS,QAAQ,EAAEJ,MAAM,CAACe,UAAU,CAAC,CAAC,CAAC;AAC1D,CAAC,CACH,CAAC","ignoreList":[]}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import type { ControlPosition,
|
|
3
|
-
export type NavigationControlProps
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { ControlPosition, NavigationControlOptions } from "../types/lib";
|
|
3
|
+
export type NavigationControlProps = NavigationControlOptions & {
|
|
4
4
|
/** Placement of the control relative to the map. */
|
|
5
5
|
position?: ControlPosition;
|
|
6
6
|
/** CSS style override, applied to the control's container */
|
|
7
7
|
style?: React.CSSProperties;
|
|
8
8
|
};
|
|
9
|
-
declare
|
|
10
|
-
declare const _default: React.MemoExoticComponent<typeof NavigationControl>;
|
|
11
|
-
export default _default;
|
|
9
|
+
export declare const NavigationControl: React.FC<NavigationControlProps>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { useEffect, memo } from
|
|
1
|
+
import { useEffect, memo } from "react";
|
|
2
2
|
import { applyReactStyle } from "../utils/apply-react-style.js";
|
|
3
|
-
import useControl from "./use-control.js";
|
|
4
|
-
function
|
|
3
|
+
import { useControl } from "./use-control.js";
|
|
4
|
+
function _NavigationControl(props) {
|
|
5
5
|
const ctrl = useControl(_ref => {
|
|
6
6
|
let {
|
|
7
7
|
mapLib
|
|
@@ -15,5 +15,5 @@ function NavigationControl(props) {
|
|
|
15
15
|
}, [props.style]);
|
|
16
16
|
return null;
|
|
17
17
|
}
|
|
18
|
-
export
|
|
18
|
+
export const NavigationControl = memo(_NavigationControl);
|
|
19
19
|
//# sourceMappingURL=navigation-control.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation-control.js","names":["useEffect","memo","applyReactStyle","useControl","
|
|
1
|
+
{"version":3,"file":"navigation-control.js","names":["useEffect","memo","applyReactStyle","useControl","_NavigationControl","props","ctrl","_ref","mapLib","NavigationControl","position","_container","style"],"sources":["../../src/components/navigation-control.ts"],"sourcesContent":["import * as React from \"react\";\nimport { useEffect, memo } from \"react\";\nimport { applyReactStyle } from \"../utils/apply-react-style\";\nimport { useControl } from \"./use-control\";\n\nimport type { ControlPosition, NavigationControlOptions } from \"../types/lib\";\n\nexport type NavigationControlProps = NavigationControlOptions & {\n /** Placement of the control relative to the map. */\n position?: ControlPosition;\n /** CSS style override, applied to the control's container */\n style?: React.CSSProperties;\n};\n\nfunction _NavigationControl(props: NavigationControlProps) {\n const ctrl = useControl(({ mapLib }) => new mapLib.NavigationControl(props), {\n position: props.position,\n });\n\n useEffect(() => {\n applyReactStyle(ctrl._container, props.style);\n }, [props.style]);\n\n return null;\n}\n\nexport const NavigationControl: React.FC<NavigationControlProps> =\n memo(_NavigationControl);\n"],"mappings":"AACA,SAASA,SAAS,EAAEC,IAAI,QAAQ,OAAO;AAAC,SAC/BC,eAAe;AAAA,SACfC,UAAU;AAWnB,SAASC,kBAAkBA,CAACC,KAA6B,EAAE;EACzD,MAAMC,IAAI,GAAGH,UAAU,CAACI,IAAA;IAAA,IAAC;MAAEC;IAAO,CAAC,GAAAD,IAAA;IAAA,OAAK,IAAIC,MAAM,CAACC,iBAAiB,CAACJ,KAAK,CAAC;EAAA,GAAE;IAC3EK,QAAQ,EAAEL,KAAK,CAACK;EAClB,CAAC,CAAC;EAEFV,SAAS,CAAC,MAAM;IACdE,eAAe,CAACI,IAAI,CAACK,UAAU,EAAEN,KAAK,CAACO,KAAK,CAAC;EAC/C,CAAC,EAAE,CAACP,KAAK,CAACO,KAAK,CAAC,CAAC;EAEjB,OAAO,IAAI;AACb;AAEA,OAAO,MAAMH,iBAAmD,GAC9DR,IAAI,CAACG,kBAAkB,CAAC","ignoreList":[]}
|
|
@@ -1,33 +1,15 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import type {
|
|
3
|
-
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { PopupOptions } from "../types/lib";
|
|
3
|
+
import type { PopupEvent } from "../types/events";
|
|
4
|
+
export type PopupProps = PopupOptions & {
|
|
4
5
|
/** Longitude of the anchor location */
|
|
5
6
|
longitude: number;
|
|
6
7
|
/** Latitude of the anchor location */
|
|
7
8
|
latitude: number;
|
|
8
|
-
anchor?: string;
|
|
9
|
-
offset?: any;
|
|
10
|
-
className?: string;
|
|
11
|
-
maxWidth?: string;
|
|
12
9
|
/** CSS style override, applied to the control's container */
|
|
13
10
|
style?: React.CSSProperties;
|
|
14
|
-
onOpen?: (e: PopupEvent
|
|
15
|
-
onClose?: (e: PopupEvent
|
|
11
|
+
onOpen?: (e: PopupEvent) => void;
|
|
12
|
+
onClose?: (e: PopupEvent) => void;
|
|
16
13
|
children?: React.ReactNode;
|
|
17
14
|
};
|
|
18
|
-
declare const
|
|
19
|
-
/** Longitude of the anchor location */
|
|
20
|
-
longitude: number;
|
|
21
|
-
/** Latitude of the anchor location */
|
|
22
|
-
latitude: number;
|
|
23
|
-
anchor?: string;
|
|
24
|
-
offset?: any;
|
|
25
|
-
className?: string;
|
|
26
|
-
maxWidth?: string;
|
|
27
|
-
/** CSS style override, applied to the control's container */
|
|
28
|
-
style?: React.CSSProperties;
|
|
29
|
-
onOpen?: (e: PopupEvent<PopupInstance>) => void;
|
|
30
|
-
onClose?: (e: PopupEvent<PopupInstance>) => void;
|
|
31
|
-
children?: React.ReactNode;
|
|
32
|
-
} & React.RefAttributes<PopupInstance>>>;
|
|
33
|
-
export default _default;
|
|
15
|
+
export declare const Popup: React.FC<PopupProps>;
|