react-bkoi-gl 2.0.0 → 2.1.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/LICENSE +21 -0
- package/README.md +1429 -176
- package/dist/index.cjs +1299 -266
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +870 -0
- package/dist/index.d.ts +870 -2
- package/dist/index.js +2420 -2
- package/dist/index.js.map +1 -1
- package/dist/styles/react-bkoi-gl.css +95 -1
- package/package.json +83 -31
- 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
package/dist/components/map.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { useState, useRef, useEffect, useContext, useMemo, useImperativeHandle } from "react";
|
|
3
|
-
import { MountedMapsContext } from "./use-map.js";
|
|
4
|
-
import Maplibre from "../maplibre/maplibre.js";
|
|
5
|
-
import createRef from "../maplibre/create-ref.js";
|
|
6
|
-
import useIsomorphicLayoutEffect from "../utils/use-isomorphic-layout-effect.js";
|
|
7
|
-
import setGlobals from "../utils/set-globals.js";
|
|
8
|
-
import { LogoControl } from "./logo-control.js";
|
|
9
|
-
import { AttributionControl } from "./attribution-control.js";
|
|
10
|
-
export const MapContext = React.createContext(null);
|
|
11
|
-
function _Map(props, ref) {
|
|
12
|
-
const mountedMapsContext = useContext(MountedMapsContext);
|
|
13
|
-
const [mapInstance, setMapInstance] = useState(null);
|
|
14
|
-
const containerRef = useRef();
|
|
15
|
-
const {
|
|
16
|
-
current: contextValue
|
|
17
|
-
} = useRef({
|
|
18
|
-
mapLib: null,
|
|
19
|
-
map: null
|
|
20
|
-
});
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
const mapLib = props.mapLib;
|
|
23
|
-
let isMounted = true;
|
|
24
|
-
let maplibre;
|
|
25
|
-
Promise.resolve(mapLib || import("maplibre-gl")).then(module => {
|
|
26
|
-
if (!isMounted) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
if (!module) {
|
|
30
|
-
throw new Error("Invalid mapLib");
|
|
31
|
-
}
|
|
32
|
-
const mapboxgl = "Map" in module ? module : module.default;
|
|
33
|
-
if (!mapboxgl.Map) {
|
|
34
|
-
throw new Error("Invalid mapLib");
|
|
35
|
-
}
|
|
36
|
-
setGlobals(mapboxgl, props);
|
|
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);
|
|
45
|
-
}
|
|
46
|
-
contextValue.map = createRef(maplibre);
|
|
47
|
-
contextValue.mapLib = mapboxgl;
|
|
48
|
-
setMapInstance(maplibre);
|
|
49
|
-
mountedMapsContext?.onMapMount(contextValue.map, props.id);
|
|
50
|
-
}).catch(error => {
|
|
51
|
-
const {
|
|
52
|
-
onError
|
|
53
|
-
} = props;
|
|
54
|
-
if (onError) {
|
|
55
|
-
onError({
|
|
56
|
-
type: "error",
|
|
57
|
-
target: null,
|
|
58
|
-
originalEvent: null,
|
|
59
|
-
error
|
|
60
|
-
});
|
|
61
|
-
} else {
|
|
62
|
-
console.error(error);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
return () => {
|
|
66
|
-
isMounted = false;
|
|
67
|
-
if (maplibre) {
|
|
68
|
-
mountedMapsContext?.onMapUnmount(props.id);
|
|
69
|
-
if (props.reuseMaps) {
|
|
70
|
-
maplibre.recycle();
|
|
71
|
-
} else {
|
|
72
|
-
maplibre.destroy();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
}, []);
|
|
77
|
-
useIsomorphicLayoutEffect(() => {
|
|
78
|
-
if (mapInstance) {
|
|
79
|
-
mapInstance.setProps(props);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
useImperativeHandle(ref, () => contextValue.map, [mapInstance]);
|
|
83
|
-
const style = useMemo(() => ({
|
|
84
|
-
position: "relative",
|
|
85
|
-
width: "100%",
|
|
86
|
-
height: "100%",
|
|
87
|
-
...props.style
|
|
88
|
-
}), [props.style]);
|
|
89
|
-
const CHILD_CONTAINER_STYLE = {
|
|
90
|
-
height: "100%"
|
|
91
|
-
};
|
|
92
|
-
return React.createElement("div", {
|
|
93
|
-
id: props.id,
|
|
94
|
-
ref: containerRef,
|
|
95
|
-
style: style
|
|
96
|
-
}, mapInstance && React.createElement(MapContext.Provider, {
|
|
97
|
-
value: contextValue
|
|
98
|
-
}, React.createElement("div", {
|
|
99
|
-
"mapboxgl-children": "",
|
|
100
|
-
style: CHILD_CONTAINER_STYLE
|
|
101
|
-
}, React.createElement(LogoControl, {
|
|
102
|
-
position: "bottom-left"
|
|
103
|
-
}), React.createElement(AttributionControl, {
|
|
104
|
-
position: "bottom-right"
|
|
105
|
-
}), props.children)));
|
|
106
|
-
}
|
|
107
|
-
export const Map = React.forwardRef(_Map);
|
|
108
|
-
//# sourceMappingURL=map.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,UAAU,EACVC,OAAO,EACPC,mBAAmB,QACd,OAAO;AAAC,SAENC,kBAAkB;AAAA,OACpBC,QAAQ;AAAA,OACRC,SAAS;AAAA,OAGTC,yBAAyB;AAAA,OACzBC,UAAU;AAAA,SAERC,WAAW;AAAA,SACXC,kBAAkB;AAO3B,OAAO,MAAMC,UAAU,GAAGd,KAAK,CAACe,aAAa,CAAkB,IAAI,CAAC;AAuBpE,SAASC,IAAIA,CAACC,KAAe,EAAEC,GAAsB,EAAE;EACrD,MAAMC,kBAAkB,GAAGf,UAAU,CAACG,kBAAkB,CAAC;EACzD,MAAM,CAACa,WAAW,EAAEC,cAAc,CAAC,GAAGpB,QAAQ,CAAW,IAAI,CAAC;EAC9D,MAAMqB,YAAY,GAAGpB,MAAM,CAAC,CAAC;EAE7B,MAAM;IAAEqB,OAAO,EAAEC;EAAa,CAAC,GAAGtB,MAAM,CAAkB;IACxDuB,MAAM,EAAE,IAAI;IACZC,GAAG,EAAE;EACP,CAAC,CAAC;EAEFvB,SAAS,CAAC,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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,18 +0,0 @@
|
|
|
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 & {
|
|
5
|
-
/** Longitude of the anchor location */
|
|
6
|
-
longitude: number;
|
|
7
|
-
/** Latitude of the anchor location */
|
|
8
|
-
latitude: number;
|
|
9
|
-
popup?: PopupInstance;
|
|
10
|
-
/** CSS style override, applied to the control's container */
|
|
11
|
-
style?: React.CSSProperties;
|
|
12
|
-
onClick?: (e: MarkerEvent<MouseEvent>) => void;
|
|
13
|
-
onDragStart?: (e: MarkerDragEvent) => void;
|
|
14
|
-
onDrag?: (e: MarkerDragEvent) => void;
|
|
15
|
-
onDragEnd?: (e: MarkerDragEvent) => void;
|
|
16
|
-
children?: React.ReactNode;
|
|
17
|
-
};
|
|
18
|
-
export declare const Marker: React.FC<MarkerProps>;
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { createPortal } from "react-dom";
|
|
3
|
-
import { useImperativeHandle, useEffect, useMemo, useRef, useContext, forwardRef, memo } from "react";
|
|
4
|
-
import { applyReactStyle } from "../utils/apply-react-style.js";
|
|
5
|
-
import { MapContext } from "./map.js";
|
|
6
|
-
import { arePointsEqual } from "../utils/deep-equal.js";
|
|
7
|
-
import { compareClassNames } from "../utils/compare-class-names.js";
|
|
8
|
-
export const Marker = memo(forwardRef((props, ref) => {
|
|
9
|
-
const {
|
|
10
|
-
map,
|
|
11
|
-
mapLib
|
|
12
|
-
} = useContext(MapContext);
|
|
13
|
-
const thisRef = useRef({
|
|
14
|
-
props
|
|
15
|
-
});
|
|
16
|
-
const marker = useMemo(() => {
|
|
17
|
-
let hasChildren = false;
|
|
18
|
-
React.Children.forEach(props.children, el => {
|
|
19
|
-
if (el) {
|
|
20
|
-
hasChildren = true;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
const options = {
|
|
24
|
-
...props,
|
|
25
|
-
element: hasChildren ? document.createElement("div") : undefined
|
|
26
|
-
};
|
|
27
|
-
const mk = new mapLib.Marker(options);
|
|
28
|
-
mk.setLngLat([props.longitude, props.latitude]);
|
|
29
|
-
mk.getElement().addEventListener("click", e => {
|
|
30
|
-
thisRef.current.props.onClick?.({
|
|
31
|
-
type: "click",
|
|
32
|
-
target: mk,
|
|
33
|
-
originalEvent: e
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
mk.on("dragstart", e => {
|
|
37
|
-
const evt = e;
|
|
38
|
-
evt.lngLat = marker.getLngLat();
|
|
39
|
-
thisRef.current.props.onDragStart?.(evt);
|
|
40
|
-
});
|
|
41
|
-
mk.on("drag", e => {
|
|
42
|
-
const evt = e;
|
|
43
|
-
evt.lngLat = marker.getLngLat();
|
|
44
|
-
thisRef.current.props.onDrag?.(evt);
|
|
45
|
-
});
|
|
46
|
-
mk.on("dragend", e => {
|
|
47
|
-
const evt = e;
|
|
48
|
-
evt.lngLat = marker.getLngLat();
|
|
49
|
-
thisRef.current.props.onDragEnd?.(evt);
|
|
50
|
-
});
|
|
51
|
-
return mk;
|
|
52
|
-
}, []);
|
|
53
|
-
useEffect(() => {
|
|
54
|
-
marker.addTo(map.getMap());
|
|
55
|
-
return () => {
|
|
56
|
-
marker.remove();
|
|
57
|
-
};
|
|
58
|
-
}, []);
|
|
59
|
-
const {
|
|
60
|
-
longitude,
|
|
61
|
-
latitude,
|
|
62
|
-
offset,
|
|
63
|
-
style,
|
|
64
|
-
draggable = false,
|
|
65
|
-
popup = null,
|
|
66
|
-
rotation = 0,
|
|
67
|
-
rotationAlignment = "auto",
|
|
68
|
-
pitchAlignment = "auto"
|
|
69
|
-
} = props;
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
applyReactStyle(marker.getElement(), style);
|
|
72
|
-
}, [style]);
|
|
73
|
-
useImperativeHandle(ref, () => marker, []);
|
|
74
|
-
const oldProps = thisRef.current.props;
|
|
75
|
-
if (marker.getLngLat().lng !== longitude || marker.getLngLat().lat !== latitude) {
|
|
76
|
-
marker.setLngLat([longitude, latitude]);
|
|
77
|
-
}
|
|
78
|
-
if (offset && !arePointsEqual(marker.getOffset(), offset)) {
|
|
79
|
-
marker.setOffset(offset);
|
|
80
|
-
}
|
|
81
|
-
if (marker.isDraggable() !== draggable) {
|
|
82
|
-
marker.setDraggable(draggable);
|
|
83
|
-
}
|
|
84
|
-
if (marker.getRotation() !== rotation) {
|
|
85
|
-
marker.setRotation(rotation);
|
|
86
|
-
}
|
|
87
|
-
if (marker.getRotationAlignment() !== rotationAlignment) {
|
|
88
|
-
marker.setRotationAlignment(rotationAlignment);
|
|
89
|
-
}
|
|
90
|
-
if (marker.getPitchAlignment() !== pitchAlignment) {
|
|
91
|
-
marker.setPitchAlignment(pitchAlignment);
|
|
92
|
-
}
|
|
93
|
-
if (marker.getPopup() !== popup) {
|
|
94
|
-
marker.setPopup(popup);
|
|
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;
|
|
103
|
-
return createPortal(props.children, marker.getElement());
|
|
104
|
-
}));
|
|
105
|
-
//# sourceMappingURL=marker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,GAAG,IAAI;MACpB;IACF,CAAC,CAAC;IACF,MAAMK,OAAO,GAAG;MACd,GAAGX,KAAK;MACRY,OAAO,EAAEN,WAAW,GAAGO,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC,GAAGC;IACzD,CAAC;IAED,MAAMC,EAAE,GAAG,IAAIb,MAAM,CAACJ,MAAM,CAACY,OAAO,CAAC;I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oB,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,9 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import type { ControlPosition, NavigationControlOptions } from "../types/lib";
|
|
3
|
-
export type NavigationControlProps = NavigationControlOptions & {
|
|
4
|
-
/** Placement of the control relative to the map. */
|
|
5
|
-
position?: ControlPosition;
|
|
6
|
-
/** CSS style override, applied to the control's container */
|
|
7
|
-
style?: React.CSSProperties;
|
|
8
|
-
};
|
|
9
|
-
export declare const NavigationControl: React.FC<NavigationControlProps>;
|
|
@@ -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 _NavigationControl(props) {
|
|
5
|
-
const ctrl = useControl(_ref => {
|
|
6
|
-
let {
|
|
7
|
-
mapLib
|
|
8
|
-
} = _ref;
|
|
9
|
-
return new mapLib.NavigationControl(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 NavigationControl = memo(_NavigationControl);
|
|
19
|
-
//# sourceMappingURL=navigation-control.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,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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rC8B,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;IACl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b,KAAK,MAAMG,KAAK,IAAIH,SAAS,EAAE;cAE7B,IAAIG,KAAK,CAAC7B,MAAM,KAAKT,EAAE,EAAE;gBACvBD,GAAG,CAACwC,WAAW,CAACD,KAAK,CAACtC,EAAE,CAAC;cAC3B;YACF;UACF;UACAD,GAAG,CAACyC,YAAY,CAACxC,EAAE,CAAC;QACtB;MACF,CAAC;IACH;IACA,OAAOyC,SAAS;EAClB,CAAC,EAAE,CAAC1C,GAAG,CAAC,CAAC;EAGT,IAAIU,MAAM,GAAGV,GAAG,IAAIA,GAAG,CAACG,KAAK,IAAIH,GAAG,CAACQ,SAAS,CAACP,EAAE,CAAC;EAClD,IAAIS,MAAM,EAAE;IACVD,YAAY,CAACC,MAAM,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 {};
|