react-bkoi-gl 2.0.0 → 2.0.1
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/LICENSE +21 -0
- package/README.md +9 -0
- package/dist/index.cjs +137 -111
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +370 -0
- package/dist/index.d.ts +370 -2
- package/dist/index.js +1434 -2
- package/dist/index.js.map +1 -1
- package/dist/styles/react-bkoi-gl.css +1 -1
- package/package.json +62 -30
- package/dist/components/attribution-control.d.ts +0 -9
- package/dist/components/attribution-control.js +0 -20
- package/dist/components/attribution-control.js.map +0 -1
- package/dist/components/fullscreen-control.d.ts +0 -12
- package/dist/components/fullscreen-control.js +0 -21
- package/dist/components/fullscreen-control.js.map +0 -1
- package/dist/components/geolocate-control.d.ts +0 -21
- package/dist/components/geolocate-control.js +0 -46
- package/dist/components/geolocate-control.js.map +0 -1
- package/dist/components/layer.d.ts +0 -18
- package/dist/components/layer.js +0 -98
- package/dist/components/layer.js.map +0 -1
- package/dist/components/logo-control.d.ts +0 -9
- package/dist/components/logo-control.js +0 -28
- package/dist/components/logo-control.js.map +0 -1
- package/dist/components/map.d.ts +0 -27
- package/dist/components/map.js +0 -108
- package/dist/components/map.js.map +0 -1
- package/dist/components/marker.d.ts +0 -18
- package/dist/components/marker.js +0 -105
- package/dist/components/marker.js.map +0 -1
- package/dist/components/navigation-control.d.ts +0 -9
- package/dist/components/navigation-control.js +0 -19
- package/dist/components/navigation-control.js.map +0 -1
- package/dist/components/popup.d.ts +0 -15
- package/dist/components/popup.js +0 -68
- package/dist/components/popup.js.map +0 -1
- package/dist/components/scale-control.d.ts +0 -11
- package/dist/components/scale-control.js +0 -31
- package/dist/components/scale-control.js.map +0 -1
- package/dist/components/source.d.ts +0 -6
- package/dist/components/source.js +0 -95
- package/dist/components/source.js.map +0 -1
- package/dist/components/terrain-control.d.ts +0 -10
- package/dist/components/terrain-control.js +0 -19
- package/dist/components/terrain-control.js.map +0 -1
- package/dist/components/use-control.d.ts +0 -9
- package/dist/components/use-control.js +0 -30
- package/dist/components/use-control.js.map +0 -1
- package/dist/components/use-map.d.ts +0 -19
- package/dist/components/use-map.js +0 -54
- package/dist/components/use-map.js.map +0 -1
- package/dist/exports-maplibre-gl.d.ts +0 -33
- package/dist/exports-maplibre-gl.js +0 -21
- package/dist/exports-maplibre-gl.js.map +0 -1
- package/dist/maplibre/create-ref.d.ts +0 -9
- package/dist/maplibre/create-ref.js +0 -30
- package/dist/maplibre/create-ref.js.map +0 -1
- package/dist/maplibre/maplibre.d.ts +0 -81
- package/dist/maplibre/maplibre.js +0 -387
- package/dist/maplibre/maplibre.js.map +0 -1
- package/dist/styles.d.js +0 -2
- package/dist/styles.d.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types/common.d.ts +0 -20
- package/dist/types/common.js +0 -2
- package/dist/types/common.js.map +0 -1
- package/dist/types/events.d.ts +0 -80
- package/dist/types/events.js +0 -2
- package/dist/types/events.js.map +0 -1
- package/dist/types/internal.d.ts +0 -14
- package/dist/types/internal.js +0 -2
- package/dist/types/internal.js.map +0 -1
- package/dist/types/lib.d.ts +0 -40
- package/dist/types/lib.js +0 -2
- package/dist/types/lib.js.map +0 -1
- package/dist/types/style-spec.d.ts +0 -1
- package/dist/types/style-spec.js +0 -2
- package/dist/types/style-spec.js.map +0 -1
- package/dist/utils/apply-react-style.d.ts +0 -2
- package/dist/utils/apply-react-style.js +0 -16
- package/dist/utils/apply-react-style.js.map +0 -1
- package/dist/utils/assert.d.ts +0 -1
- package/dist/utils/assert.js +0 -6
- package/dist/utils/assert.js.map +0 -1
- package/dist/utils/compare-class-names.d.ts +0 -2
- package/dist/utils/compare-class-names.js +0 -23
- package/dist/utils/compare-class-names.js.map +0 -1
- package/dist/utils/deep-equal.d.ts +0 -15
- package/dist/utils/deep-equal.js +0 -46
- package/dist/utils/deep-equal.js.map +0 -1
- package/dist/utils/set-globals.d.ts +0 -20
- package/dist/utils/set-globals.js +0 -31
- package/dist/utils/set-globals.js.map +0 -1
- package/dist/utils/style-utils.d.ts +0 -3
- package/dist/utils/style-utils.js +0 -42
- package/dist/utils/style-utils.js.map +0 -1
- package/dist/utils/transform.d.ts +0 -18
- package/dist/utils/transform.js +0 -33
- package/dist/utils/transform.js.map +0 -1
- package/dist/utils/use-isomorphic-layout-effect.d.ts +0 -3
- package/dist/utils/use-isomorphic-layout-effect.js +0 -4
- package/dist/utils/use-isomorphic-layout-effect.js.map +0 -1
- package/src/components/attribution-control.ts +0 -56
- package/src/components/fullscreen-control.ts +0 -40
- package/src/components/geolocate-control.ts +0 -96
- package/src/components/layer.ts +0 -141
- package/src/components/logo-control.ts +0 -44
- package/src/components/map.tsx +0 -166
- package/src/components/marker.ts +0 -155
- package/src/components/navigation-control.ts +0 -28
- package/src/components/popup.ts +0 -113
- package/src/components/scale-control.ts +0 -44
- package/src/components/source.ts +0 -159
- package/src/components/terrain-control.ts +0 -29
- package/src/components/use-control.ts +0 -68
- package/src/components/use-map.tsx +0 -71
- package/src/exports-maplibre-gl.ts +0 -37
- package/src/index.ts +0 -3
- package/src/maplibre/create-ref.ts +0 -70
- package/src/maplibre/maplibre.ts +0 -624
- package/src/styles.d.ts +0 -4
- package/src/types/common.ts +0 -34
- package/src/types/events.ts +0 -133
- package/src/types/internal.ts +0 -26
- package/src/types/lib.ts +0 -84
- package/src/types/style-spec.ts +0 -34
- package/src/utils/apply-react-style.ts +0 -24
- package/src/utils/assert.ts +0 -5
- package/src/utils/compare-class-names.ts +0 -29
- package/src/utils/deep-equal.ts +0 -61
- package/src/utils/set-globals.ts +0 -51
- package/src/utils/style-utils.ts +0 -68
- package/src/utils/transform.ts +0 -58
- package/src/utils/use-isomorphic-layout-effect.ts +0 -8
|
@@ -1,15 +0,0 @@
|
|
|
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 & {
|
|
5
|
-
/** Longitude of the anchor location */
|
|
6
|
-
longitude: number;
|
|
7
|
-
/** Latitude of the anchor location */
|
|
8
|
-
latitude: number;
|
|
9
|
-
/** CSS style override, applied to the control's container */
|
|
10
|
-
style?: React.CSSProperties;
|
|
11
|
-
onOpen?: (e: PopupEvent) => void;
|
|
12
|
-
onClose?: (e: PopupEvent) => void;
|
|
13
|
-
children?: React.ReactNode;
|
|
14
|
-
};
|
|
15
|
-
export declare const Popup: React.FC<PopupProps>;
|
package/dist/components/popup.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { createPortal } from "react-dom";
|
|
2
|
-
import { useImperativeHandle, useEffect, useMemo, useRef, useContext, forwardRef, memo } from "react";
|
|
3
|
-
import { applyReactStyle } from "../utils/apply-react-style.js";
|
|
4
|
-
import { MapContext } from "./map.js";
|
|
5
|
-
import { deepEqual } from "../utils/deep-equal.js";
|
|
6
|
-
import { compareClassNames } from "../utils/compare-class-names.js";
|
|
7
|
-
export const Popup = memo(forwardRef((props, ref) => {
|
|
8
|
-
const {
|
|
9
|
-
map,
|
|
10
|
-
mapLib
|
|
11
|
-
} = useContext(MapContext);
|
|
12
|
-
const container = useMemo(() => {
|
|
13
|
-
return document.createElement("div");
|
|
14
|
-
}, []);
|
|
15
|
-
const thisRef = useRef({
|
|
16
|
-
props
|
|
17
|
-
});
|
|
18
|
-
const popup = useMemo(() => {
|
|
19
|
-
const options = {
|
|
20
|
-
...props
|
|
21
|
-
};
|
|
22
|
-
const pp = new mapLib.Popup(options);
|
|
23
|
-
pp.setLngLat([props.longitude, props.latitude]);
|
|
24
|
-
pp.once("open", e => {
|
|
25
|
-
thisRef.current.props.onOpen?.(e);
|
|
26
|
-
});
|
|
27
|
-
return pp;
|
|
28
|
-
}, []);
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
const onClose = e => {
|
|
31
|
-
thisRef.current.props.onClose?.(e);
|
|
32
|
-
};
|
|
33
|
-
popup.on("close", onClose);
|
|
34
|
-
popup.setDOMContent(container).addTo(map.getMap());
|
|
35
|
-
return () => {
|
|
36
|
-
popup.off("close", onClose);
|
|
37
|
-
if (popup.isOpen()) {
|
|
38
|
-
popup.remove();
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
}, []);
|
|
42
|
-
useEffect(() => {
|
|
43
|
-
applyReactStyle(popup.getElement(), props.style);
|
|
44
|
-
}, [props.style]);
|
|
45
|
-
useImperativeHandle(ref, () => popup, []);
|
|
46
|
-
if (popup.isOpen()) {
|
|
47
|
-
const oldProps = thisRef.current.props;
|
|
48
|
-
if (popup.getLngLat().lng !== props.longitude || popup.getLngLat().lat !== props.latitude) {
|
|
49
|
-
popup.setLngLat([props.longitude, props.latitude]);
|
|
50
|
-
}
|
|
51
|
-
if (props.offset && !deepEqual(oldProps.offset, props.offset)) {
|
|
52
|
-
popup.setOffset(props.offset);
|
|
53
|
-
}
|
|
54
|
-
if (oldProps.anchor !== props.anchor || oldProps.maxWidth !== props.maxWidth) {
|
|
55
|
-
popup.options.anchor = props.anchor;
|
|
56
|
-
popup.setMaxWidth(props.maxWidth);
|
|
57
|
-
}
|
|
58
|
-
const classNameDiff = compareClassNames(oldProps.className, props.className);
|
|
59
|
-
if (classNameDiff) {
|
|
60
|
-
for (const c of classNameDiff) {
|
|
61
|
-
popup.toggleClassName(c);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
thisRef.current.props = props;
|
|
65
|
-
}
|
|
66
|
-
return createPortal(props.children, container);
|
|
67
|
-
}));
|
|
68
|
-
//# sourceMappingURL=popup.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"popup.js","names":["createPortal","useImperativeHandle","useEffect","useMemo","useRef","useContext","forwardRef","memo","applyReactStyle","MapContext","deepEqual","compareClassNames","Popup","props","ref","map","mapLib","container","document","createElement","thisRef","popup","options","pp","setLngLat","longitude","latitude","once","e","current","onOpen","onClose","on","setDOMContent","addTo","getMap","off","isOpen","remove","getElement","style","oldProps","getLngLat","lng","lat","offset","setOffset","anchor","maxWidth","setMaxWidth","classNameDiff","className","c","toggleClassName","children"],"sources":["../../src/components/popup.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-floating-promises */\n/* 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 { Popup as PopupInstance, PopupOptions } from \"../types/lib\";\nimport type { PopupEvent } from \"../types/events\";\n\nimport { MapContext } from \"./map\";\nimport { deepEqual } from \"../utils/deep-equal\";\nimport { compareClassNames } from \"../utils/compare-class-names\";\n\nexport type PopupProps = PopupOptions & {\n /** Longitude of the anchor location */\n longitude: number;\n /** Latitude of the anchor location */\n latitude: number;\n\n /** CSS style override, applied to the control's container */\n style?: React.CSSProperties;\n\n onOpen?: (e: PopupEvent) => void;\n onClose?: (e: PopupEvent) => void;\n children?: React.ReactNode;\n};\n\n/* eslint-disable complexity,max-statements */\nexport const Popup: React.FC<PopupProps> = memo(\n forwardRef((props: PopupProps, ref: React.Ref<PopupInstance>) => {\n const { map, mapLib } = useContext(MapContext);\n const container = useMemo(() => {\n return document.createElement(\"div\");\n }, []);\n const thisRef = useRef({ props });\n\n const popup: PopupInstance = useMemo(() => {\n const options = { ...props };\n const pp = new mapLib.Popup(options);\n pp.setLngLat([props.longitude, props.latitude]);\n pp.once(\"open\", (e) => {\n thisRef.current.props.onOpen?.(e as PopupEvent);\n });\n return pp;\n }, []);\n\n useEffect(() => {\n const onClose = (e) => {\n thisRef.current.props.onClose?.(e as PopupEvent);\n };\n popup.on(\"close\", onClose);\n popup.setDOMContent(container).addTo(map.getMap());\n\n return () => {\n // https://github.com/visgl/react-map-gl/issues/1825\n // onClose should not be fired if the popup is removed by unmounting\n // When using React strict mode, the component is mounted twice.\n // Firing the onClose callback here would be a false signal to remove the component.\n popup.off(\"close\", onClose);\n if (popup.isOpen()) {\n popup.remove();\n }\n };\n }, []);\n\n useEffect(() => {\n applyReactStyle(popup.getElement(), props.style);\n }, [props.style]);\n\n useImperativeHandle(ref, () => popup, []);\n\n if (popup.isOpen()) {\n const oldProps = thisRef.current.props;\n if (\n popup.getLngLat().lng !== props.longitude ||\n popup.getLngLat().lat !== props.latitude\n ) {\n popup.setLngLat([props.longitude, props.latitude]);\n }\n if (props.offset && !deepEqual(oldProps.offset, props.offset)) {\n popup.setOffset(props.offset);\n }\n if (\n oldProps.anchor !== props.anchor ||\n oldProps.maxWidth !== props.maxWidth\n ) {\n popup.options.anchor = props.anchor;\n popup.setMaxWidth(props.maxWidth);\n }\n const classNameDiff = compareClassNames(\n oldProps.className,\n props.className,\n );\n if (classNameDiff) {\n for (const c of classNameDiff) {\n popup.toggleClassName(c);\n }\n }\n thisRef.current.props = props;\n }\n\n return createPortal(props.children, container);\n }),\n);\n"],"mappings":"AAGA,SAASA,YAAY,QAAQ,WAAW;AACxC,SACEC,mBAAmB,EACnBC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,UAAU,EACVC,UAAU,EACVC,IAAI,QACC,OAAO;AAAC,SACNC,eAAe;AAAA,SAKfC,UAAU;AAAA,SACVC,SAAS;AAAA,SACTC,iBAAiB;AAiB1B,OAAO,MAAMC,KAA2B,GAAGL,IAAI,CAC7CD,UAAU,CAAC,CAACO,KAAiB,EAAEC,GAA6B,KAAK;EAC/D,MAAM;IAAEC,GAAG;IAAEC;EAAO,CAAC,GAAGX,UAAU,CAACI,UAAU,CAAC;EAC9C,MAAMQ,SAAS,GAAGd,OAAO,CAAC,MAAM;IAC9B,OAAOe,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EACtC,CAAC,EAAE,EAAE,CAAC;EACN,MAAMC,OAAO,GAAGhB,MAAM,CAAC;IAAES;EAAM,CAAC,CAAC;EAEjC,MAAMQ,KAAoB,GAAGlB,OAAO,CAAC,MAAM;IACzC,MAAM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,OAAO,CAACS,OAAO,CAAChB,KAAK;IACtC,IACEQ,KAAK,CAACqB,SAAS,CAAC,CAAC,CAACC,GAAG,KAAK9B,KAAK,CAACY,SAAS,IACzCJ,KAAK,CAACqB,SAAS,CAAC,CAAC,CAACE,GAAG,KAAK/B,KAAK,CAACa,QAAQ,EACxC;MACAL,KAAK,CAACG,SAAS,CAAC,CAACX,KAAK,CAACY,SAAS,EAAEZ,KAAK,CAACa,QAAQ,CAAC,CAAC;IACpD;IACA,IAAIb,KAAK,CAACgC,MAAM,IAAI,CAACnC,SAAS,CAAC+B,QAAQ,CAACI,MAAM,EAAEhC,KAAK,CAACgC,MAAM,CAAC,EAAE;MAC7DxB,KAAK,CAACyB,SAAS,CAACjC,KAAK,CAACgC,MAAM,CAAC;IAC/B;IACA,IACEJ,QAAQ,CAACM,MAAM,KAAKlC,KAAK,CAACkC,MAAM,IAChCN,QAAQ,CAACO,QAAQ,KAAKnC,KAAK,CAACmC,QAAQ,EACpC;MACA3B,KAAK,CAACC,OAAO,CAACyB,MAAM,GAAGlC,KAAK,CAACkC,MAAM;MACnC1B,KAAK,CAAC4B,WAAW,CAACpC,KAAK,CAACmC,QAAQ,CAAC;IACnC;IACA,MAAME,aAAa,GAAGvC,iBAAiB,CACrC8B,QAAQ,CAACU,SAAS,EAClBtC,KAAK,CAACsC,SACR,CAAC;IACD,IAAID,aAAa,EAAE;MACjB,KAAK,MAAME,CAAC,IAAIF,aAAa,EAAE;QAC7B7B,KAAK,CAACgC,eAAe,CAACD,CAAC,CAAC;MAC1B;IACF;IACAhC,OAAO,CAACS,OAAO,CAAChB,KAAK,GAAGA,KAAK;EAC/B;EAEA,OAAOb,YAAY,CAACa,KAAK,CAACyC,QAAQ,EAAErC,SAAS,CAAC;AAChD,CAAC,CACH,CAAC","ignoreList":[]}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import type { ControlPosition, ScaleControlOptions } from "../types/lib";
|
|
3
|
-
export type ScaleControlProps = ScaleControlOptions & {
|
|
4
|
-
unit?: string;
|
|
5
|
-
maxWidth?: number;
|
|
6
|
-
/** Placement of the control relative to the map. */
|
|
7
|
-
position?: ControlPosition;
|
|
8
|
-
/** CSS style override, applied to the control's container */
|
|
9
|
-
style?: React.CSSProperties;
|
|
10
|
-
};
|
|
11
|
-
export declare const ScaleControl: React.FC<ScaleControlProps>;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef, memo } from "react";
|
|
2
|
-
import { applyReactStyle } from "../utils/apply-react-style.js";
|
|
3
|
-
import { useControl } from "./use-control.js";
|
|
4
|
-
function _ScaleControl(props) {
|
|
5
|
-
const ctrl = useControl(_ref => {
|
|
6
|
-
let {
|
|
7
|
-
mapLib
|
|
8
|
-
} = _ref;
|
|
9
|
-
return new mapLib.ScaleControl(props);
|
|
10
|
-
}, {
|
|
11
|
-
position: props.position
|
|
12
|
-
});
|
|
13
|
-
const propsRef = useRef(props);
|
|
14
|
-
const prevProps = propsRef.current;
|
|
15
|
-
propsRef.current = props;
|
|
16
|
-
const {
|
|
17
|
-
style
|
|
18
|
-
} = props;
|
|
19
|
-
if (props.maxWidth !== undefined && props.maxWidth !== prevProps.maxWidth) {
|
|
20
|
-
ctrl.options.maxWidth = props.maxWidth;
|
|
21
|
-
}
|
|
22
|
-
if (props.unit !== undefined && props.unit !== prevProps.unit) {
|
|
23
|
-
ctrl.setUnit(props.unit);
|
|
24
|
-
}
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
applyReactStyle(ctrl._container, style);
|
|
27
|
-
}, [style]);
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
export const ScaleControl = memo(_ScaleControl);
|
|
31
|
-
//# sourceMappingURL=scale-control.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scale-control.js","names":["useEffect","useRef","memo","applyReactStyle","useControl","_ScaleControl","props","ctrl","_ref","mapLib","ScaleControl","position","propsRef","prevProps","current","style","maxWidth","undefined","options","unit","setUnit","_container"],"sources":["../../src/components/scale-control.ts"],"sourcesContent":["import * as React from \"react\";\nimport { useEffect, useRef, memo } from \"react\";\nimport { applyReactStyle } from \"../utils/apply-react-style\";\nimport { useControl } from \"./use-control\";\n\nimport type { ControlPosition, ScaleControlOptions } from \"../types/lib\";\n\nexport type ScaleControlProps = ScaleControlOptions & {\n // These props will be further constraint by OptionsT\n unit?: string;\n maxWidth?: number;\n\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 _ScaleControl(props: ScaleControlProps) {\n const ctrl = useControl(({ mapLib }) => new mapLib.ScaleControl(props), {\n position: props.position,\n });\n const propsRef = useRef<ScaleControlProps>(props);\n\n const prevProps = propsRef.current;\n propsRef.current = props;\n\n const { style } = props;\n\n if (props.maxWidth !== undefined && props.maxWidth !== prevProps.maxWidth) {\n ctrl.options.maxWidth = props.maxWidth;\n }\n if (props.unit !== undefined && props.unit !== prevProps.unit) {\n ctrl.setUnit(props.unit);\n }\n\n useEffect(() => {\n applyReactStyle(ctrl._container, style);\n }, [style]);\n\n return null;\n}\n\nexport const ScaleControl: React.FC<ScaleControlProps> = memo(_ScaleControl);\n"],"mappings":"AACA,SAASA,SAAS,EAAEC,MAAM,EAAEC,IAAI,QAAQ,OAAO;AAAC,SACvCC,eAAe;AAAA,SACfC,UAAU;AAenB,SAASC,aAAaA,CAACC,KAAwB,EAAE;EAC/C,MAAMC,IAAI,GAAGH,UAAU,CAACI,IAAA;IAAA,IAAC;MAAEC;IAAO,CAAC,GAAAD,IAAA;IAAA,OAAK,IAAIC,MAAM,CAACC,YAAY,CAACJ,KAAK,CAAC;EAAA,GAAE;IACtEK,QAAQ,EAAEL,KAAK,CAACK;EAClB,CAAC,CAAC;EACF,MAAMC,QAAQ,GAAGX,MAAM,CAAoBK,KAAK,CAAC;EAEjD,MAAMO,SAAS,GAAGD,QAAQ,CAACE,OAAO;EAClCF,QAAQ,CAACE,OAAO,GAAGR,KAAK;EAExB,MAAM;IAAES;EAAM,CAAC,GAAGT,KAAK;EAEvB,IAAIA,KAAK,CAACU,QAAQ,KAAKC,SAAS,IAAIX,KAAK,CAACU,QAAQ,KAAKH,SAAS,CAACG,QAAQ,EAAE;IACzET,IAAI,CAACW,OAAO,CAACF,QAAQ,GAAGV,KAAK,CAACU,QAAQ;EACxC;EACA,IAAIV,KAAK,CAACa,IAAI,KAAKF,SAAS,IAAIX,KAAK,CAACa,IAAI,KAAKN,SAAS,CAACM,IAAI,EAAE;IAC7DZ,IAAI,CAACa,OAAO,CAACd,KAAK,CAACa,IAAI,CAAC;EAC1B;EAEAnB,SAAS,CAAC,MAAM;IACdG,eAAe,CAACI,IAAI,CAACc,UAAU,EAAEN,KAAK,CAAC;EACzC,CAAC,EAAE,CAACA,KAAK,CAAC,CAAC;EAEX,OAAO,IAAI;AACb;AAEA,OAAO,MAAML,YAAyC,GAAGR,IAAI,CAACG,aAAa,CAAC","ignoreList":[]}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { useContext, useEffect, useMemo, useState, useRef, cloneElement } from "react";
|
|
3
|
-
import { MapContext } from "./map.js";
|
|
4
|
-
import assert from "../utils/assert.js";
|
|
5
|
-
import { deepEqual } from "../utils/deep-equal.js";
|
|
6
|
-
let sourceCounter = 0;
|
|
7
|
-
function createSource(map, id, props) {
|
|
8
|
-
if (map.style && map.style._loaded) {
|
|
9
|
-
const options = {
|
|
10
|
-
...props
|
|
11
|
-
};
|
|
12
|
-
delete options.id;
|
|
13
|
-
delete options.children;
|
|
14
|
-
map.addSource(id, options);
|
|
15
|
-
return map.getSource(id);
|
|
16
|
-
}
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
function updateSource(source, props, prevProps) {
|
|
20
|
-
assert(props.id === prevProps.id, "source id changed");
|
|
21
|
-
assert(props.type === prevProps.type, "source type changed");
|
|
22
|
-
let changedKey = "";
|
|
23
|
-
let changedKeyCount = 0;
|
|
24
|
-
for (const key in props) {
|
|
25
|
-
if (key !== "children" && key !== "id" && !deepEqual(prevProps[key], props[key])) {
|
|
26
|
-
changedKey = key;
|
|
27
|
-
changedKeyCount++;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (!changedKeyCount) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const type = props.type;
|
|
34
|
-
if (type === "geojson") {
|
|
35
|
-
source.setData(props.data);
|
|
36
|
-
} else if (type === "image") {
|
|
37
|
-
source.updateImage({
|
|
38
|
-
url: props.url,
|
|
39
|
-
coordinates: props.coordinates
|
|
40
|
-
});
|
|
41
|
-
} else {
|
|
42
|
-
switch (changedKey) {
|
|
43
|
-
case "coordinates":
|
|
44
|
-
source.setCoordinates?.(props.coordinates);
|
|
45
|
-
break;
|
|
46
|
-
case "url":
|
|
47
|
-
source.setUrl?.(props.url);
|
|
48
|
-
break;
|
|
49
|
-
case "tiles":
|
|
50
|
-
source.setTiles?.(props.tiles);
|
|
51
|
-
break;
|
|
52
|
-
default:
|
|
53
|
-
console.warn(`Unable to update <Source> prop: ${changedKey}`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
export function Source(props) {
|
|
58
|
-
const map = useContext(MapContext).map.getMap();
|
|
59
|
-
const propsRef = useRef(props);
|
|
60
|
-
const [, setStyleLoaded] = useState(0);
|
|
61
|
-
const id = useMemo(() => props.id || `jsx-source-${sourceCounter++}`, []);
|
|
62
|
-
useEffect(() => {
|
|
63
|
-
if (map) {
|
|
64
|
-
const forceUpdate = () => setTimeout(() => setStyleLoaded(version => version + 1), 0);
|
|
65
|
-
map.on("styledata", forceUpdate);
|
|
66
|
-
forceUpdate();
|
|
67
|
-
return () => {
|
|
68
|
-
map.off("styledata", forceUpdate);
|
|
69
|
-
if (map.style && map.style._loaded && map.getSource(id)) {
|
|
70
|
-
const allLayers = map.getStyle()?.layers;
|
|
71
|
-
if (allLayers) {
|
|
72
|
-
for (const layer of allLayers) {
|
|
73
|
-
if (layer.source === id) {
|
|
74
|
-
map.removeLayer(layer.id);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
map.removeSource(id);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
return undefined;
|
|
83
|
-
}, [map]);
|
|
84
|
-
let source = map && map.style && map.getSource(id);
|
|
85
|
-
if (source) {
|
|
86
|
-
updateSource(source, props, propsRef.current);
|
|
87
|
-
} else {
|
|
88
|
-
source = createSource(map, id, props);
|
|
89
|
-
}
|
|
90
|
-
propsRef.current = props;
|
|
91
|
-
return source && React.Children.map(props.children, child => child && cloneElement(child, {
|
|
92
|
-
source: id
|
|
93
|
-
})) || null;
|
|
94
|
-
}
|
|
95
|
-
//# sourceMappingURL=source.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"source.js","names":["React","useContext","useEffect","useMemo","useState","useRef","cloneElement","MapContext","assert","deepEqual","sourceCounter","createSource","map","id","props","style","_loaded","options","children","addSource","getSource","updateSource","source","prevProps","type","changedKey","changedKeyCount","key","setData","data","updateImage","url","coordinates","setCoordinates","setUrl","setTiles","tiles","console","warn","Source","getMap","propsRef","setStyleLoaded","forceUpdate","setTimeout","version","on","off","allLayers","getStyle","layers","layer","removeLayer","removeSource","undefined","current","Children","child"],"sources":["../../src/components/source.ts"],"sourcesContent":["import * as React from \"react\";\nimport {\n useContext,\n useEffect,\n useMemo,\n useState,\n useRef,\n cloneElement,\n} from \"react\";\nimport { MapContext } from \"./map\";\nimport assert from \"../utils/assert\";\nimport { deepEqual } from \"../utils/deep-equal\";\n\nimport type {\n GeoJSONSourceImplementation,\n ImageSourceImplementation,\n AnySourceImplementation,\n} from \"../types/internal\";\nimport type { SourceSpecification } from \"../types/style-spec\";\nimport type { Map as MapInstance } from \"../types/lib\";\n\nexport type SourceProps = SourceSpecification & {\n id?: string;\n children?: any;\n};\n\nlet sourceCounter = 0;\n\nfunction createSource(map: MapInstance, id: string, props: SourceProps) {\n // @ts-ignore\n if (map.style && map.style._loaded) {\n const options = { ...props };\n delete options.id;\n delete options.children;\n // @ts-ignore\n map.addSource(id, options);\n return map.getSource(id);\n }\n return null;\n}\n\n/* eslint-disable complexity */\nfunction updateSource(\n source: AnySourceImplementation,\n props: SourceProps,\n prevProps: SourceProps,\n) {\n assert(props.id === prevProps.id, \"source id changed\");\n assert(props.type === prevProps.type, \"source type changed\");\n\n let changedKey = \"\";\n let changedKeyCount = 0;\n\n for (const key in props) {\n if (\n key !== \"children\" &&\n key !== \"id\" &&\n !deepEqual(prevProps[key], props[key])\n ) {\n changedKey = key;\n changedKeyCount++;\n }\n }\n\n if (!changedKeyCount) {\n return;\n }\n\n const type = props.type;\n\n if (type === \"geojson\") {\n (source as GeoJSONSourceImplementation).setData(props.data);\n } else if (type === \"image\") {\n (source as ImageSourceImplementation).updateImage({\n url: props.url,\n coordinates: props.coordinates,\n });\n } else {\n switch (changedKey) {\n case \"coordinates\":\n // @ts-ignore\n source.setCoordinates?.(props.coordinates);\n break;\n case \"url\":\n // @ts-ignore\n source.setUrl?.(props.url);\n break;\n case \"tiles\":\n // @ts-ignore\n source.setTiles?.(props.tiles);\n break;\n default:\n // eslint-disable-next-line\n console.warn(`Unable to update <Source> prop: ${changedKey}`);\n }\n }\n}\n/* eslint-enable complexity */\n\nexport function Source(props: SourceProps) {\n const map = useContext(MapContext).map.getMap();\n const propsRef = useRef(props);\n const [, setStyleLoaded] = useState(0);\n\n const id = useMemo(() => props.id || `jsx-source-${sourceCounter++}`, []);\n\n useEffect(() => {\n if (map) {\n /* global setTimeout */\n const forceUpdate = () =>\n setTimeout(() => setStyleLoaded((version) => version + 1), 0);\n map.on(\"styledata\", forceUpdate);\n forceUpdate();\n\n return () => {\n map.off(\"styledata\", forceUpdate);\n // @ts-ignore\n if (map.style && map.style._loaded && map.getSource(id)) {\n // Parent effects are destroyed before child ones, see\n // https://github.com/facebook/react/issues/16728\n // Source can only be removed after all child layers are removed\n const allLayers = map.getStyle()?.layers;\n if (allLayers) {\n for (const layer of allLayers) {\n // @ts-ignore (2339) source does not exist on all layer types\n if (layer.source === id) {\n map.removeLayer(layer.id);\n }\n }\n }\n map.removeSource(id);\n }\n };\n }\n return undefined;\n }, [map]);\n\n // @ts-ignore\n let source = map && map.style && map.getSource(id);\n if (source) {\n updateSource(source, props, propsRef.current);\n } else {\n source = createSource(map, id, props);\n }\n propsRef.current = props;\n\n return (\n (source &&\n React.Children.map(\n props.children,\n (child) =>\n child &&\n cloneElement(child, {\n source: id,\n }),\n )) ||\n null\n );\n}\n"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SACEC,UAAU,EACVC,SAAS,EACTC,OAAO,EACPC,QAAQ,EACRC,MAAM,EACNC,YAAY,QACP,OAAO;AAAC,SACNC,UAAU;AAAA,OACZC,MAAM;AAAA,SACJC,SAAS;AAelB,IAAIC,aAAa,GAAG,CAAC;AAErB,SAASC,YAAYA,CAACC,GAAgB,EAAEC,EAAU,EAAEC,KAAkB,EAAE;EAEtE,IAAIF,GAAG,CAACG,KAAK,IAAIH,GAAG,CAACG,KAAK,CAACC,OAAO,EAAE;IAClC,MAAMC,OAAO,GAAG;MAAE,GAAGH;IAAM,CAAC;IAC5B,OAAOG,OAAO,CAACJ,EAAE;IACjB,OAAOI,OAAO,CAACC,QAAQ;IAEvBN,GAAG,CAACO,SAAS,CAACN,EAAE,EAAEI,OAAO,CAAC;IAC1B,OAAOL,GAAG,CAACQ,SAAS,CAACP,EAAE,CAAC;EAC1B;EACA,OAAO,IAAI;AACb;AAGA,SAASQ,YAAYA,CACnBC,MAA+B,EAC/BR,KAAkB,EAClBS,SAAsB,EACtB;EACAf,MAAM,CAACM,KAAK,CAACD,EAAE,KAAKU,SAAS,CAACV,EAAE,EAAE,mBAAmB,CAAC;EACtDL,MAAM,CAACM,KAAK,CAACU,IAAI,KAAKD,SAA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EAAER,KAAK,EAAE2B,QAAQ,CAACc,OAAO,CAAC;EAC/C,CAAC,MAAM;IACLjC,MAAM,GAAGX,YAAY,CAACC,GAAG,EAAEC,EAAE,EAAEC,KAAK,CAAC;EACvC;EACA2B,QAAQ,CAACc,OAAO,GAAGzC,KAAK;EAExB,OACGQ,MAAM,IACLtB,KAAK,CAACwD,QAAQ,CAAC5C,GAAG,CAChBE,KAAK,CAACI,QAAQ,EACbuC,KAAK,IACJA,KAAK,IACLnD,YAAY,CAACmD,KAAK,EAAE;IAClBnC,MAAM,EAAET;EACV,CAAC,CACL,CAAC,IACH,IAAI;AAER","ignoreList":[]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import type { ControlPosition } from "../types/lib";
|
|
3
|
-
import type { TerrainSpecification } from "../types/style-spec";
|
|
4
|
-
export type TerrainControlProps = TerrainSpecification & {
|
|
5
|
-
/** Placement of the control relative to the map. */
|
|
6
|
-
position?: ControlPosition;
|
|
7
|
-
/** CSS style override, applied to the control's container */
|
|
8
|
-
style?: React.CSSProperties;
|
|
9
|
-
};
|
|
10
|
-
export declare const TerrainControl: React.FC<TerrainControlProps>;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { useEffect, memo } from "react";
|
|
2
|
-
import { applyReactStyle } from "../utils/apply-react-style.js";
|
|
3
|
-
import { useControl } from "./use-control.js";
|
|
4
|
-
function _TerrainControl(props) {
|
|
5
|
-
const ctrl = useControl(_ref => {
|
|
6
|
-
let {
|
|
7
|
-
mapLib
|
|
8
|
-
} = _ref;
|
|
9
|
-
return new mapLib.TerrainControl(props);
|
|
10
|
-
}, {
|
|
11
|
-
position: props.position
|
|
12
|
-
});
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
applyReactStyle(ctrl._container, props.style);
|
|
15
|
-
}, [props.style]);
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
export const TerrainControl = memo(_TerrainControl);
|
|
19
|
-
//# sourceMappingURL=terrain-control.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"terrain-control.js","names":["useEffect","memo","applyReactStyle","useControl","_TerrainControl","props","ctrl","_ref","mapLib","TerrainControl","position","_container","style"],"sources":["../../src/components/terrain-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 } from \"../types/lib\";\nimport type { TerrainSpecification } from \"../types/style-spec\";\n\nexport type TerrainControlProps = TerrainSpecification & {\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 _TerrainControl(props: TerrainControlProps) {\n const ctrl = useControl(({ mapLib }) => new mapLib.TerrainControl(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 TerrainControl: React.FC<TerrainControlProps> =\n memo(_TerrainControl);\n"],"mappings":"AACA,SAASA,SAAS,EAAEC,IAAI,QAAQ,OAAO;AAAC,SAC/BC,eAAe;AAAA,SACfC,UAAU;AAYnB,SAASC,eAAeA,CAACC,KAA0B,EAAE;EACnD,MAAMC,IAAI,GAAGH,UAAU,CAACI,IAAA;IAAA,IAAC;MAAEC;IAAO,CAAC,GAAAD,IAAA;IAAA,OAAK,IAAIC,MAAM,CAACC,cAAc,CAACJ,KAAK,CAAC;EAAA,GAAE;IACxEK,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,cAA6C,GACxDR,IAAI,CAACG,eAAe,CAAC","ignoreList":[]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { IControl, ControlPosition } from "../types/lib";
|
|
2
|
-
import type { MapContextValue } from "./map";
|
|
3
|
-
type ControlOptions = {
|
|
4
|
-
position?: ControlPosition;
|
|
5
|
-
};
|
|
6
|
-
export declare function useControl<T extends IControl>(onCreate: (context: MapContextValue) => T, opts?: ControlOptions): T;
|
|
7
|
-
export declare function useControl<T extends IControl>(onCreate: (context: MapContextValue) => T, onRemove: (context: MapContextValue) => void, opts?: ControlOptions): T;
|
|
8
|
-
export declare function useControl<T extends IControl>(onCreate: (context: MapContextValue) => T, onAdd: (context: MapContextValue) => void, onRemove: (context: MapContextValue) => void, opts?: ControlOptions): T;
|
|
9
|
-
export {};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { useContext, useMemo, useEffect } from "react";
|
|
2
|
-
import { MapContext } from "./map.js";
|
|
3
|
-
export function useControl(onCreate, arg1, arg2, arg3) {
|
|
4
|
-
const context = useContext(MapContext);
|
|
5
|
-
const ctrl = useMemo(() => onCreate(context), []);
|
|
6
|
-
useEffect(() => {
|
|
7
|
-
const opts = arg3 || arg2 || arg1;
|
|
8
|
-
const onAdd = typeof arg1 === "function" && typeof arg2 === "function" ? arg1 : null;
|
|
9
|
-
const onRemove = typeof arg2 === "function" ? arg2 : typeof arg1 === "function" ? arg1 : null;
|
|
10
|
-
const {
|
|
11
|
-
map
|
|
12
|
-
} = context;
|
|
13
|
-
if (!map.hasControl(ctrl)) {
|
|
14
|
-
map.addControl(ctrl, opts?.position);
|
|
15
|
-
if (onAdd) {
|
|
16
|
-
onAdd(context);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return () => {
|
|
20
|
-
if (onRemove) {
|
|
21
|
-
onRemove(context);
|
|
22
|
-
}
|
|
23
|
-
if (map.hasControl(ctrl)) {
|
|
24
|
-
map.removeControl(ctrl);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
}, []);
|
|
28
|
-
return ctrl;
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=use-control.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-control.js","names":["useContext","useMemo","useEffect","MapContext","useControl","onCreate","arg1","arg2","arg3","context","ctrl","opts","onAdd","onRemove","map","hasControl","addControl","position","removeControl"],"sources":["../../src/components/use-control.ts"],"sourcesContent":["import { useContext, useMemo, useEffect } from \"react\";\nimport type { IControl, ControlPosition } from \"../types/lib\";\nimport { MapContext } from \"./map\";\nimport type { MapContextValue } from \"./map\";\n\ntype ControlOptions = {\n position?: ControlPosition;\n};\n\nexport function useControl<T extends IControl>(\n onCreate: (context: MapContextValue) => T,\n opts?: ControlOptions,\n): T;\n\nexport function useControl<T extends IControl>(\n onCreate: (context: MapContextValue) => T,\n onRemove: (context: MapContextValue) => void,\n opts?: ControlOptions,\n): T;\n\nexport function useControl<T extends IControl>(\n onCreate: (context: MapContextValue) => T,\n onAdd: (context: MapContextValue) => void,\n onRemove: (context: MapContextValue) => void,\n opts?: ControlOptions,\n): T;\n\nexport function useControl<T extends IControl>(\n onCreate: (context: MapContextValue) => T,\n arg1?: ((context: MapContextValue) => void) | ControlOptions,\n arg2?: ((context: MapContextValue) => void) | ControlOptions,\n arg3?: ControlOptions,\n): T {\n const context = useContext(MapContext);\n const ctrl = useMemo(() => onCreate(context), []);\n\n useEffect(() => {\n const opts = (arg3 || arg2 || arg1) as ControlOptions;\n const onAdd =\n typeof arg1 === \"function\" && typeof arg2 === \"function\" ? arg1 : null;\n const onRemove =\n typeof arg2 === \"function\"\n ? arg2\n : typeof arg1 === \"function\"\n ? arg1\n : null;\n\n const { map } = context;\n if (!map.hasControl(ctrl)) {\n map.addControl(ctrl, opts?.position);\n if (onAdd) {\n onAdd(context);\n }\n }\n\n return () => {\n if (onRemove) {\n onRemove(context);\n }\n // Map might have been removed (parent effects are destroyed before child ones)\n if (map.hasControl(ctrl)) {\n map.removeControl(ctrl);\n }\n };\n }, []);\n\n return ctrl;\n}\n"],"mappings":"AAAA,SAASA,UAAU,EAAEC,OAAO,EAAEC,SAAS,QAAQ,OAAO;AAAC,SAE9CC,UAAU;AAyBnB,OAAO,SAASC,UAAUA,CACxBC,QAAyC,EACzCC,IAA4D,EAC5DC,IAA4D,EAC5DC,IAAqB,EAClB;EACH,MAAMC,OAAO,GAAGT,UAAU,CAACG,UAAU,CAAC;EACtC,MAAMO,IAAI,GAAGT,OAAO,CAAC,MAAMI,QAAQ,CAACI,OAAO,CAAC,EAAE,EAAE,CAAC;EAEjDP,SAAS,CAAC,MAAM;IACd,MAAMS,IAAI,GAAIH,IAAI,IAAID,IAAI,IAAID,IAAuB;IACrD,MAAMM,KAAK,GACT,OAAON,IAAI,KAAK,UAAU,IAAI,OAAOC,IAAI,KAAK,UAAU,GAAGD,IAAI,GAAG,IAAI;IACxE,MAAMO,QAAQ,GACZ,OAAON,IAAI,KAAK,UAAU,GACtBA,IAAI,GACJ,OAAOD,IAAI,KAAK,UAAU,GAC1BA,IAAI,GACJ,IAAI;IAEV,MAAM;MAAEQ;IAAI,CAAC,GAAGL,OAAO;IACvB,IAAI,CAACK,GAAG,CAACC,UAAU,CAACL,IAAI,CAAC,EAAE;MACzBI,GAAG,CAACE,UAAU,CAACN,IAAI,EAAEC,IAAI,EAAEM,QAAQ,CAAC;MACpC,IAAIL,KAAK,EAAE;QACTA,KAAK,CAACH,OAAO,CAAC;MAChB;IACF;IAEA,OAAO,MAAM;MACX,IAAII,QAAQ,EAAE;QACZA,QAAQ,CAACJ,OAAO,CAAC;MACnB;MAEA,IAAIK,GAAG,CAACC,UAAU,CAACL,IAAI,CAAC,EAAE;QACxBI,GAAG,CAACI,aAAa,CAACR,IAAI,CAAC;MACzB;IACF,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOA,IAAI;AACb","ignoreList":[]}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { MapRef } from "../maplibre/create-ref";
|
|
3
|
-
type MountedMapsContextValue = {
|
|
4
|
-
maps: {
|
|
5
|
-
[id: string]: MapRef;
|
|
6
|
-
};
|
|
7
|
-
onMapMount: (map: MapRef, id: string) => void;
|
|
8
|
-
onMapUnmount: (id: string) => void;
|
|
9
|
-
};
|
|
10
|
-
export declare const MountedMapsContext: React.Context<MountedMapsContextValue>;
|
|
11
|
-
export declare const MapProvider: React.FC<{
|
|
12
|
-
children?: React.ReactNode;
|
|
13
|
-
}>;
|
|
14
|
-
export type MapCollection = {
|
|
15
|
-
[id: string]: MapRef | undefined;
|
|
16
|
-
current?: MapRef;
|
|
17
|
-
};
|
|
18
|
-
export declare function useMap(): MapCollection;
|
|
19
|
-
export {};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { useState, useCallback, useMemo, useContext } from "react";
|
|
3
|
-
import { MapContext } from "./map.js";
|
|
4
|
-
export const MountedMapsContext = React.createContext(null);
|
|
5
|
-
export const MapProvider = props => {
|
|
6
|
-
const [maps, setMaps] = useState({});
|
|
7
|
-
const onMapMount = useCallback(function (map) {
|
|
8
|
-
let id = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "default";
|
|
9
|
-
setMaps(currMaps => {
|
|
10
|
-
if (id === "current") {
|
|
11
|
-
throw new Error("'current' cannot be used as map id");
|
|
12
|
-
}
|
|
13
|
-
if (currMaps[id]) {
|
|
14
|
-
throw new Error(`Multiple maps with the same id: ${id}`);
|
|
15
|
-
}
|
|
16
|
-
return {
|
|
17
|
-
...currMaps,
|
|
18
|
-
[id]: map
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
}, []);
|
|
22
|
-
const onMapUnmount = useCallback(function () {
|
|
23
|
-
let id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "default";
|
|
24
|
-
setMaps(currMaps => {
|
|
25
|
-
if (currMaps[id]) {
|
|
26
|
-
const nextMaps = {
|
|
27
|
-
...currMaps
|
|
28
|
-
};
|
|
29
|
-
delete nextMaps[id];
|
|
30
|
-
return nextMaps;
|
|
31
|
-
}
|
|
32
|
-
return currMaps;
|
|
33
|
-
});
|
|
34
|
-
}, []);
|
|
35
|
-
return React.createElement(MountedMapsContext.Provider, {
|
|
36
|
-
value: {
|
|
37
|
-
maps,
|
|
38
|
-
onMapMount,
|
|
39
|
-
onMapUnmount
|
|
40
|
-
}
|
|
41
|
-
}, props.children);
|
|
42
|
-
};
|
|
43
|
-
export function useMap() {
|
|
44
|
-
const maps = useContext(MountedMapsContext)?.maps;
|
|
45
|
-
const currentMap = useContext(MapContext);
|
|
46
|
-
const mapsWithCurrent = useMemo(() => {
|
|
47
|
-
return {
|
|
48
|
-
...maps,
|
|
49
|
-
current: currentMap?.map
|
|
50
|
-
};
|
|
51
|
-
}, [maps, currentMap]);
|
|
52
|
-
return mapsWithCurrent;
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=use-map.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-map.js","names":["React","useState","useCallback","useMemo","useContext","MapContext","MountedMapsContext","createContext","MapProvider","props","maps","setMaps","onMapMount","map","id","arguments","length","undefined","currMaps","Error","onMapUnmount","nextMaps","createElement","Provider","value","children","useMap","currentMap","mapsWithCurrent","current"],"sources":["../../src/components/use-map.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { useState, useCallback, useMemo, useContext } from \"react\";\n\nimport { MapRef } from \"../maplibre/create-ref\";\nimport { MapContext } from \"./map\";\n\ntype MountedMapsContextValue = {\n maps: { [id: string]: MapRef };\n onMapMount: (map: MapRef, id: string) => void;\n onMapUnmount: (id: string) => void;\n};\n\nexport const MountedMapsContext =\n React.createContext<MountedMapsContextValue>(null);\n\nexport const MapProvider: React.FC<{ children?: React.ReactNode }> = (\n props,\n) => {\n const [maps, setMaps] = useState<{ [id: string]: MapRef }>({});\n\n const onMapMount = useCallback((map: MapRef, id: string = \"default\") => {\n setMaps((currMaps) => {\n if (id === \"current\") {\n throw new Error(\"'current' cannot be used as map id\");\n }\n if (currMaps[id]) {\n throw new Error(`Multiple maps with the same id: ${id}`);\n }\n return { ...currMaps, [id]: map };\n });\n }, []);\n\n const onMapUnmount = useCallback((id: string = \"default\") => {\n setMaps((currMaps) => {\n if (currMaps[id]) {\n const nextMaps = { ...currMaps };\n delete nextMaps[id];\n return nextMaps;\n }\n return currMaps;\n });\n }, []);\n\n return (\n <MountedMapsContext.Provider\n value={{\n maps,\n onMapMount,\n onMapUnmount,\n }}\n >\n {props.children}\n </MountedMapsContext.Provider>\n );\n};\n\nexport type MapCollection = {\n [id: string]: MapRef | undefined;\n current?: MapRef;\n};\n\nexport function useMap(): MapCollection {\n const maps = useContext(MountedMapsContext)?.maps;\n const currentMap = useContext(MapContext);\n\n const mapsWithCurrent = useMemo(() => {\n return { ...maps, current: currentMap?.map };\n }, [maps, currentMap]);\n\n return mapsWithCurrent as MapCollection;\n}\n"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,QAAQ,EAAEC,WAAW,EAAEC,OAAO,EAAEC,UAAU,QAAQ,OAAO;AAAC,SAG1DC,UAAU;AAQnB,OAAO,MAAMC,kBAAkB,GAC7BN,KAAK,CAACO,aAAa,CAA0B,IAAI,CAAC;AAEpD,OAAO,MAAMC,WAAqD,GAChEC,KAAK,IACF;EACH,MAAM,CAACC,IAAI,EAAEC,OAAO,CAAC,GAAGV,QAAQ,CAA2B,CAAC,CAAC,CAAC;EAE9D,MAAMW,UAAU,GAAGV,WAAW,CAAC,UAACW,GAAW,EAA6B;IAAA,IAA3BC,EAAU,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,SAAS;IACjEJ,OAAO,CAAEO,QAAQ,IAAK;MACpB,IAAIJ,EAAE,KAAK,SAAS,EAAE;QACpB,MAAM,IAAIK,KAAK,CAAC,oCAAoC,CAAC;MACvD;MACA,IAAID,QAAQ,CAACJ,EAAE,CA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
3
|
-
export default Map;
|
|
4
|
-
export { Marker } from "./components/marker";
|
|
5
|
-
export { Popup } from "./components/popup";
|
|
6
|
-
export { AttributionControl } from "./components/attribution-control";
|
|
7
|
-
export { FullscreenControl } from "./components/fullscreen-control";
|
|
8
|
-
export { GeolocateControl } from "./components/geolocate-control";
|
|
9
|
-
export { NavigationControl } from "./components/navigation-control";
|
|
10
|
-
export { ScaleControl } from "./components/scale-control";
|
|
11
|
-
export { TerrainControl } from "./components/terrain-control";
|
|
12
|
-
export { LogoControl } from "./components/logo-control";
|
|
13
|
-
export { Source } from "./components/source";
|
|
14
|
-
export { Layer } from "./components/layer";
|
|
15
|
-
export { useControl } from "./components/use-control";
|
|
16
|
-
export { MapProvider, useMap } from "./components/use-map";
|
|
17
|
-
export type { MapProps } from "./components/map";
|
|
18
|
-
export type { MapRef } from "./maplibre/create-ref";
|
|
19
|
-
export type { MarkerProps } from "./components/marker";
|
|
20
|
-
export type { PopupProps } from "./components/popup";
|
|
21
|
-
export type { AttributionControlProps } from "./components/attribution-control";
|
|
22
|
-
export type { FullscreenControlProps } from "./components/fullscreen-control";
|
|
23
|
-
export type { GeolocateControlProps } from "./components/geolocate-control";
|
|
24
|
-
export type { NavigationControlProps } from "./components/navigation-control";
|
|
25
|
-
export type { ScaleControlProps } from "./components/scale-control";
|
|
26
|
-
export type { TerrainControlProps } from "./components/terrain-control";
|
|
27
|
-
export type { LogoControlProps } from "./components/logo-control";
|
|
28
|
-
export type { SourceProps } from "./components/source";
|
|
29
|
-
export type { LayerProps } from "./components/layer";
|
|
30
|
-
export * from "./types/common";
|
|
31
|
-
export * from "./types/events";
|
|
32
|
-
export * from "./types/lib";
|
|
33
|
-
export * from "./types/style-spec";
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Map } from "./components/map.js";
|
|
2
|
-
export { Map };
|
|
3
|
-
export default Map;
|
|
4
|
-
export { Marker } from "./components/marker.js";
|
|
5
|
-
export { Popup } from "./components/popup.js";
|
|
6
|
-
export { AttributionControl } from "./components/attribution-control.js";
|
|
7
|
-
export { FullscreenControl } from "./components/fullscreen-control.js";
|
|
8
|
-
export { GeolocateControl } from "./components/geolocate-control.js";
|
|
9
|
-
export { NavigationControl } from "./components/navigation-control.js";
|
|
10
|
-
export { ScaleControl } from "./components/scale-control.js";
|
|
11
|
-
export { TerrainControl } from "./components/terrain-control.js";
|
|
12
|
-
export { LogoControl } from "./components/logo-control.js";
|
|
13
|
-
export { Source } from "./components/source.js";
|
|
14
|
-
export { Layer } from "./components/layer.js";
|
|
15
|
-
export { useControl } from "./components/use-control.js";
|
|
16
|
-
export { MapProvider, useMap } from "./components/use-map.js";
|
|
17
|
-
export * from "./types/common.js";
|
|
18
|
-
export * from "./types/events.js";
|
|
19
|
-
export * from "./types/lib.js";
|
|
20
|
-
export * from "./types/style-spec.js";
|
|
21
|
-
//# sourceMappingURL=exports-maplibre-gl.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"exports-maplibre-gl.js","names":["Map","Marker","Popup","AttributionControl","FullscreenControl","GeolocateControl","NavigationControl","ScaleControl","TerrainControl","LogoControl","Source","Layer","useControl","MapProvider","useMap"],"sources":["../src/exports-maplibre-gl.ts"],"sourcesContent":["import { Map } from \"./components/map\";\nexport { Map };\nexport default Map;\n\nexport { Marker } from \"./components/marker\";\nexport { Popup } from \"./components/popup\";\nexport { AttributionControl } from \"./components/attribution-control\";\nexport { FullscreenControl } from \"./components/fullscreen-control\";\nexport { GeolocateControl } from \"./components/geolocate-control\";\nexport { NavigationControl } from \"./components/navigation-control\";\nexport { ScaleControl } from \"./components/scale-control\";\nexport { TerrainControl } from \"./components/terrain-control\";\nexport { LogoControl } from \"./components/logo-control\";\nexport { Source } from \"./components/source\";\nexport { Layer } from \"./components/layer\";\nexport { useControl } from \"./components/use-control\";\nexport { MapProvider, useMap } from \"./components/use-map\";\n\nexport type { MapProps } from \"./components/map\";\nexport type { MapRef } from \"./maplibre/create-ref\";\nexport type { MarkerProps } from \"./components/marker\";\nexport type { PopupProps } from \"./components/popup\";\nexport type { AttributionControlProps } from \"./components/attribution-control\";\nexport type { FullscreenControlProps } from \"./components/fullscreen-control\";\nexport type { GeolocateControlProps } from \"./components/geolocate-control\";\nexport type { NavigationControlProps } from \"./components/navigation-control\";\nexport type { ScaleControlProps } from \"./components/scale-control\";\nexport type { TerrainControlProps } from \"./components/terrain-control\";\nexport type { LogoControlProps } from \"./components/logo-control\";\nexport type { SourceProps } from \"./components/source\";\nexport type { LayerProps } from \"./components/layer\";\n\n// Types\nexport * from \"./types/common\";\nexport * from \"./types/events\";\nexport * from \"./types/lib\";\nexport * from \"./types/style-spec\";\n"],"mappings":"SAASA,GAAG;AACZ,SAASA,GAAG;AACZ,eAAeA,GAAG;AAAC,SAEVC,MAAM;AAAA,SACNC,KAAK;AAAA,SACLC,kBAAkB;AAAA,SAClBC,iBAAiB;AAAA,SACjBC,gBAAgB;AAAA,SAChBC,iBAAiB;AAAA,SACjBC,YAAY;AAAA,SACZC,cAAc;AAAA,SACdC,WAAW;AAAA,SACXC,MAAM;AAAA,SACNC,KAAK;AAAA,SACLC,UAAU;AAAA,SACVC,WAAW,EAAEC,MAAM;AAAA;AAAA;AAAA;AAAA","ignoreList":[]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Map as MapInstance } from "../types/lib";
|
|
2
|
-
import type Maplibre from "./maplibre";
|
|
3
|
-
/** These methods may break the react binding if called directly */
|
|
4
|
-
declare const skipMethods: readonly ["setMaxBounds", "setMinZoom", "setMaxZoom", "setMinPitch", "setMaxPitch", "setRenderWorldCopies", "setProjection", "setStyle", "addSource", "removeSource", "addLayer", "removeLayer", "setLayerZoomRange", "setFilter", "setPaintProperty", "setLayoutProperty", "setLight", "setTerrain", "setFog", "remove"];
|
|
5
|
-
export type MapRef = {
|
|
6
|
-
getMap(): MapInstance;
|
|
7
|
-
} & Omit<MapInstance, (typeof skipMethods)[number]>;
|
|
8
|
-
export default function createRef(mapInstance: Maplibre): MapRef | null;
|
|
9
|
-
export {};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const skipMethods = ["setMaxBounds", "setMinZoom", "setMaxZoom", "setMinPitch", "setMaxPitch", "setRenderWorldCopies", "setProjection", "setStyle", "addSource", "removeSource", "addLayer", "removeLayer", "setLayerZoomRange", "setFilter", "setPaintProperty", "setLayoutProperty", "setLight", "setTerrain", "setFog", "remove"];
|
|
2
|
-
export default function createRef(mapInstance) {
|
|
3
|
-
if (!mapInstance) {
|
|
4
|
-
return null;
|
|
5
|
-
}
|
|
6
|
-
const map = mapInstance.map;
|
|
7
|
-
const result = {
|
|
8
|
-
getMap: () => map
|
|
9
|
-
};
|
|
10
|
-
for (const key of getMethodNames(map)) {
|
|
11
|
-
if (!(key in result) && !skipMethods.includes(key)) {
|
|
12
|
-
result[key] = map[key].bind(map);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return result;
|
|
16
|
-
}
|
|
17
|
-
function getMethodNames(obj) {
|
|
18
|
-
const result = new Set();
|
|
19
|
-
let proto = obj;
|
|
20
|
-
while (proto) {
|
|
21
|
-
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
22
|
-
if (key[0] !== "_" && typeof obj[key] === "function" && key !== "fire" && key !== "setEventedParent") {
|
|
23
|
-
result.add(key);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
proto = Object.getPrototypeOf(proto);
|
|
27
|
-
}
|
|
28
|
-
return Array.from(result);
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=create-ref.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-ref.js","names":["skipMethods","createRef","mapInstance","map","result","getMap","key","getMethodNames","includes","bind","obj","Set","proto","Object","getOwnPropertyNames","add","getPrototypeOf","Array","from"],"sources":["../../src/maplibre/create-ref.ts"],"sourcesContent":["import type { Map as MapInstance } from \"../types/lib\";\nimport type Maplibre from \"./maplibre\";\n\n/** These methods may break the react binding if called directly */\nconst skipMethods = [\n \"setMaxBounds\",\n \"setMinZoom\",\n \"setMaxZoom\",\n \"setMinPitch\",\n \"setMaxPitch\",\n \"setRenderWorldCopies\",\n \"setProjection\",\n \"setStyle\",\n \"addSource\",\n \"removeSource\",\n \"addLayer\",\n \"removeLayer\",\n \"setLayerZoomRange\",\n \"setFilter\",\n \"setPaintProperty\",\n \"setLayoutProperty\",\n \"setLight\",\n \"setTerrain\",\n \"setFog\",\n \"remove\",\n] as const;\n\nexport type MapRef = {\n getMap(): MapInstance;\n} & Omit<MapInstance, (typeof skipMethods)[number]>;\n\nexport default function createRef(mapInstance: Maplibre): MapRef | null {\n if (!mapInstance) {\n return null;\n }\n\n const map = mapInstance.map;\n const result: any = {\n getMap: () => map,\n };\n\n for (const key of getMethodNames(map)) {\n // @ts-expect-error\n if (!(key in result) && !skipMethods.includes(key)) {\n result[key] = map[key].bind(map);\n }\n }\n\n return result;\n}\n\nfunction getMethodNames(obj: Object) {\n const result = new Set<string>();\n\n let proto = obj;\n while (proto) {\n for (const key of Object.getOwnPropertyNames(proto)) {\n if (\n key[0] !== \"_\" &&\n typeof obj[key] === \"function\" &&\n key !== \"fire\" &&\n key !== \"setEventedParent\"\n ) {\n result.add(key);\n }\n }\n proto = Object.getPrototypeOf(proto);\n }\n return Array.from(result);\n}\n"],"mappings":"AAIA,MAAMA,WAAW,GAAG,CAClB,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,aAAa,EACb,sBAAsB,EACtB,eAAe,EACf,UAAU,EACV,WAAW,EACX,cAAc,EACd,UAAU,EACV,aAAa,EACb,mBAAmB,EACnB,WAAW,EACX,kBAAkB,EAClB,mBAAmB,EACnB,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,QAAQ,CACA;AAMV,eAAe,SAASC,SAASA,CAACC,WAAqB,EAAiB;EACtE,IAAI,CAACA,WAAW,EAAE;IAChB,OAAO,IAAI;EACb;EAEA,MAAMC,GAAG,GAAGD,WAAW,CAACC,GAA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