react-bkoi-gl 1.0.5 → 1.0.7
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/dist/components/geolocate-control.js +5 -10
- package/dist/components/geolocate-control.js.map +1 -1
- package/dist/components/layer.js +3 -5
- package/dist/components/layer.js.map +1 -1
- package/dist/components/map.js +6 -8
- package/dist/components/map.js.map +1 -1
- package/dist/components/marker.js +7 -13
- package/dist/components/marker.js.map +1 -1
- package/dist/components/popup.js +5 -8
- package/dist/components/popup.js.map +1 -1
- package/dist/components/source.js +4 -6
- package/dist/components/source.js.map +1 -1
- package/dist/components/use-control.js +1 -1
- package/dist/components/use-control.js.map +1 -1
- package/dist/components/use-map.js +11 -11
- package/dist/components/use-map.js.map +1 -1
- package/dist/mapbox/mapbox.js +68 -72
- package/dist/mapbox/mapbox.js.map +1 -1
- package/dist/styles/react-bkoi-gl.css +1 -1
- package/dist/utils/style-utils.js +3 -5
- package/dist/utils/style-utils.js.map +1 -1
- package/package.json +4 -6
|
@@ -17,24 +17,19 @@ function GeolocateControl(props, ref) {
|
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
gc.on('geolocate', e => {
|
|
20
|
-
|
|
21
|
-
(_thisRef$current$prop = (_thisRef$current$prop2 = thisRef.current.props).onGeolocate) === null || _thisRef$current$prop === void 0 || _thisRef$current$prop.call(_thisRef$current$prop2, e);
|
|
20
|
+
thisRef.current.props.onGeolocate?.(e);
|
|
22
21
|
});
|
|
23
22
|
gc.on('error', e => {
|
|
24
|
-
|
|
25
|
-
(_thisRef$current$prop3 = (_thisRef$current$prop4 = thisRef.current.props).onError) === null || _thisRef$current$prop3 === void 0 || _thisRef$current$prop3.call(_thisRef$current$prop4, e);
|
|
23
|
+
thisRef.current.props.onError?.(e);
|
|
26
24
|
});
|
|
27
25
|
gc.on('outofmaxbounds', e => {
|
|
28
|
-
|
|
29
|
-
(_thisRef$current$prop5 = (_thisRef$current$prop6 = thisRef.current.props).onOutOfMaxBounds) === null || _thisRef$current$prop5 === void 0 || _thisRef$current$prop5.call(_thisRef$current$prop6, e);
|
|
26
|
+
thisRef.current.props.onOutOfMaxBounds?.(e);
|
|
30
27
|
});
|
|
31
28
|
gc.on('trackuserlocationstart', e => {
|
|
32
|
-
|
|
33
|
-
(_thisRef$current$prop7 = (_thisRef$current$prop8 = thisRef.current.props).onTrackUserLocationStart) === null || _thisRef$current$prop7 === void 0 || _thisRef$current$prop7.call(_thisRef$current$prop8, e);
|
|
29
|
+
thisRef.current.props.onTrackUserLocationStart?.(e);
|
|
34
30
|
});
|
|
35
31
|
gc.on('trackuserlocationend', e => {
|
|
36
|
-
|
|
37
|
-
(_thisRef$current$prop9 = (_thisRef$current$prop10 = thisRef.current.props).onTrackUserLocationEnd) === null || _thisRef$current$prop9 === void 0 || _thisRef$current$prop9.call(_thisRef$current$prop10, e);
|
|
32
|
+
thisRef.current.props.onTrackUserLocationEnd?.(e);
|
|
38
33
|
});
|
|
39
34
|
return gc;
|
|
40
35
|
}, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geolocate-control.js","names":["useImperativeHandle","useRef","useEffect","forwardRef","memo","applyReactStyle","useControl","GeolocateControl","props","ref","thisRef","ctrl","_ref","mapLib","gc","setupUI","_setupUI","args","_container","hasChildNodes","on","e","
|
|
1
|
+
{"version":3,"file":"geolocate-control.js","names":["useImperativeHandle","useRef","useEffect","forwardRef","memo","applyReactStyle","useControl","GeolocateControl","props","ref","thisRef","ctrl","_ref","mapLib","gc","setupUI","_setupUI","args","_container","hasChildNodes","on","e","current","onGeolocate","onError","onOutOfMaxBounds","onTrackUserLocationStart","onTrackUserLocationEnd","position","style"],"sources":["../../src/components/geolocate-control.ts"],"sourcesContent":["import * as React from 'react';\nimport {useImperativeHandle, useRef, useEffect, forwardRef, memo} from 'react';\nimport {applyReactStyle} from '../utils/apply-react-style';\nimport useControl from './use-control';\n\nimport type {\n ControlPosition,\n GeolocateControlInstance,\n GeolocateEvent,\n GeolocateResultEvent,\n GeolocateErrorEvent\n} from '../types';\n\nexport type GeolocateControlProps<\n OptionsT,\n ControlT extends GeolocateControlInstance\n> = OptionsT & {\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 /** Called on each Geolocation API position update that returned as success. */\n onGeolocate?: (e: GeolocateResultEvent<ControlT>) => void;\n /** Called on each Geolocation API position update that returned as an error. */\n onError?: (e: GeolocateErrorEvent<ControlT>) => void;\n /** Called on each Geolocation API position update that returned as success but user position\n * is out of map `maxBounds`. */\n onOutOfMaxBounds?: (e: GeolocateResultEvent<ControlT>) => void;\n /** Called when the GeolocateControl changes to the active lock state. */\n onTrackUserLocationStart?: (e: GeolocateEvent<ControlT>) => void;\n /** Called when the GeolocateControl changes to the background state. */\n onTrackUserLocationEnd?: (e: GeolocateEvent<ControlT>) => void;\n};\n\nfunction GeolocateControl<GeolocateControlOptions, ControlT extends GeolocateControlInstance>(\n props: GeolocateControlProps<GeolocateControlOptions, ControlT>,\n ref: React.Ref<ControlT>\n) {\n const thisRef = useRef({props});\n\n const ctrl = useControl<ControlT>(\n ({mapLib}) => {\n const gc = new mapLib.GeolocateControl(props) as ControlT;\n\n // Hack: fix GeolocateControl reuse\n // When using React strict mode, the component is mounted twice.\n // GeolocateControl's UI creation is asynchronous. Removing and adding it back causes the UI to be initialized twice.\n // @ts-expect-error private method\n const setupUI = gc._setupUI;\n // @ts-expect-error private method\n gc._setupUI = args => {\n if (!gc._container.hasChildNodes()) {\n setupUI(args);\n }\n };\n\n gc.on('geolocate', e => {\n thisRef.current.props.onGeolocate?.(e as GeolocateResultEvent<ControlT>);\n });\n gc.on('error', e => {\n thisRef.current.props.onError?.(e as GeolocateErrorEvent<ControlT>);\n });\n gc.on('outofmaxbounds', e => {\n thisRef.current.props.onOutOfMaxBounds?.(e as GeolocateResultEvent<ControlT>);\n });\n gc.on('trackuserlocationstart', e => {\n thisRef.current.props.onTrackUserLocationStart?.(e as GeolocateEvent<ControlT>);\n });\n gc.on('trackuserlocationend', e => {\n thisRef.current.props.onTrackUserLocationEnd?.(e as GeolocateEvent<ControlT>);\n });\n\n return gc;\n },\n {position: props.position}\n );\n\n thisRef.current.props = props;\n\n useImperativeHandle(ref, () => ctrl, []);\n\n useEffect(() => {\n applyReactStyle(ctrl._container, props.style);\n }, [props.style]);\n\n return null;\n}\n\nexport default memo(forwardRef(GeolocateControl));\n"],"mappings":"AACA,SAAQA,mBAAmB,EAAEC,MAAM,EAAEC,SAAS,EAAEC,UAAU,EAAEC,IAAI,QAAO,OAAO;AAAC,SACvEC,eAAe;AAAA,OAChBC,UAAU;AAgCjB,SAASC,gBAAgBA,CACvBC,KAA+D,EAC/DC,GAAwB,EACxB;EACA,MAAMC,OAAO,GAAGT,MAAM,CAAC;IAACO;EAAK,CAAC,CAAC;EAE/B,MAAMG,IAAI,GAAGL,UAAU,CACrBM,IAAA,IAAc;IAAA,IAAb;MAACC;IAAM,CAAC,GAAAD,IAAA;IACP,MAAME,EAAE,GAAG,IAAID,MAAM,CAACN,gBAAgB,CAACC,KAAK,CAAa;IAMzD,MAAMO,OAAO,GAAGD,EAAE,CAACE,QAAQ;IAE3BF,EAAE,CAACE,QAAQ,GAAGC,IAAI,IAAI;MACpB,IAAI,CAACH,EAAE,CAACI,UAAU,CAACC,aAAa,CAAC,CAAC,EAAE;QAClCJ,OAAO,CAACE,IAAI,CAAC;MACf;IACF,CAAC;IAEDH,EAAE,CAACM,EAAE,CAAC,WAAW,EAAEC,CAAC,IAAI;MACtBX,OAAO,CAACY,OAAO,CAACd,KAAK,CAACe,WAAW,GAAGF,CAAmC,CAAC;IAC1E,CAAC,CAAC;IACFP,EAAE,CAACM,EAAE,CAAC,OAAO,EAAEC,CAAC,IAAI;MAClBX,OAAO,CAACY,OAAO,CAACd,KAAK,CAACgB,OAAO,GAAGH,CAAkC,CAAC;IACrE,CAAC,CAAC;IACFP,EAAE,CAACM,EAAE,CAAC,gBAAgB,EAAEC,CAAC,IAAI;MAC3BX,OAAO,CAACY,OAAO,CAACd,KAAK,CAACiB,gBAAgB,GAAGJ,CAAmC,CAAC;IAC/E,CAAC,CAAC;IACFP,EAAE,CAACM,EAAE,CAAC,wBAAwB,EAAEC,CAAC,IAAI;MACnCX,OAAO,CAACY,OAAO,CAACd,KAAK,CAACkB,wBAAwB,GAAGL,CAA6B,CAAC;IACjF,CAAC,CAAC;IACFP,EAAE,CAACM,EAAE,CAAC,sBAAsB,EAAEC,CAAC,IAAI;MACjCX,OAAO,CAACY,OAAO,CAACd,KAAK,CAACmB,sBAAsB,GAAGN,CAA6B,CAAC;IAC/E,CAAC,CAAC;IAEF,OAAOP,EAAE;EACX,CAAC,EACD;IAACc,QAAQ,EAAEpB,KAAK,CAACoB;EAAQ,CAC3B,CAAC;EAEDlB,OAAO,CAACY,OAAO,CAACd,KAAK,GAAGA,KAAK;EAE7BR,mBAAmB,CAACS,GAAG,EAAE,MAAME,IAAI,EAAE,EAAE,CAAC;EAExCT,SAAS,CAAC,MAAM;IACdG,eAAe,CAACM,IAAI,CAACO,UAAU,EAAEV,KAAK,CAACqB,KAAK,CAAC;EAC/C,CAAC,EAAE,CAACrB,KAAK,CAACqB,KAAK,CAAC,CAAC;EAEjB,OAAO,IAAI;AACb;AAEA,eAAezB,IAAI,CAACD,UAAU,CAACI,gBAAgB,CAAC,CAAC","ignoreList":[]}
|
package/dist/components/layer.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
1
|
import { useContext, useEffect, useMemo, useState, useRef } from 'react';
|
|
5
2
|
import { MapContext } from "./map.js";
|
|
6
3
|
import assert from "../utils/assert.js";
|
|
@@ -57,9 +54,10 @@ function updateLayer(map, id, props, prevProps) {
|
|
|
57
54
|
}
|
|
58
55
|
function createLayer(map, id, props) {
|
|
59
56
|
if (map.style && map.style._loaded && (!('source' in props) || map.getSource(props.source))) {
|
|
60
|
-
const options =
|
|
57
|
+
const options = {
|
|
58
|
+
...props,
|
|
61
59
|
id
|
|
62
|
-
}
|
|
60
|
+
};
|
|
63
61
|
delete options.beforeId;
|
|
64
62
|
map.addLayer(options, props.beforeId);
|
|
65
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layer.js","names":["useContext","useEffect","useMemo","useState","useRef","MapContext","assert","deepEqual","updateLayer","map","id","props","prevProps","type","layout","paint","filter","minzoom","maxzoom","beforeId","moveLayer","prevLayout","key","setLayoutProperty","hasOwnProperty","undefined","prevPaint","setPaintProperty","setFilter","setLayerZoomRange","createLayer","style","_loaded","getSource","source","options","
|
|
1
|
+
{"version":3,"file":"layer.js","names":["useContext","useEffect","useMemo","useState","useRef","MapContext","assert","deepEqual","updateLayer","map","id","props","prevProps","type","layout","paint","filter","minzoom","maxzoom","beforeId","moveLayer","prevLayout","key","setLayoutProperty","hasOwnProperty","undefined","prevPaint","setPaintProperty","setFilter","setLayerZoomRange","createLayer","style","_loaded","getSource","source","options","addLayer","layerCounter","Layer","getMap","propsRef","setStyleLoaded","forceUpdate","version","on","off","getLayer","removeLayer","layer","current","error","console","warn"],"sources":["../../src/components/layer.ts"],"sourcesContent":["import {useContext, useEffect, useMemo, useState, useRef} from 'react';\nimport {MapContext} from './map';\nimport assert from '../utils/assert';\nimport {deepEqual} from '../utils/deep-equal';\n\nimport type {MapInstance, CustomLayerInterface, ILayer} from '../types';\n\n// Omiting property from a union type, see\n// https://github.com/microsoft/TypeScript/issues/39556#issuecomment-656925230\ntype OptionalId<T> = T extends {id: string} ? Omit<T, 'id'> & {id?: string} : T;\ntype OptionalSource<T> = T extends {source: string} ? Omit<T, 'source'> & {source?: string} : T;\n\nexport type LayerProps<LayerT> = OptionalSource<OptionalId<LayerT>> & {\n /** If set, the layer will be inserted before the specified layer */\n beforeId?: string;\n};\n\n/* eslint-disable complexity, max-statements */\nfunction updateLayer<LayerT extends ILayer>(\n map: MapInstance,\n id: string,\n props: LayerProps<LayerT>,\n prevProps: LayerProps<LayerT>\n) {\n assert(props.id === prevProps.id, 'layer id changed');\n assert(props.type === prevProps.type, 'layer type changed');\n\n if (props.type === 'custom' || prevProps.type === 'custom') {\n return;\n }\n\n const {layout = {}, paint = {}, filter, minzoom, maxzoom, beforeId} = props;\n\n if (beforeId !== prevProps.beforeId) {\n map.moveLayer(id, beforeId);\n }\n if (layout !== prevProps.layout) {\n const prevLayout = prevProps.layout || {};\n for (const key in layout) {\n if (!deepEqual(layout[key], prevLayout[key])) {\n map.setLayoutProperty(id, key, layout[key]);\n }\n }\n for (const key in prevLayout) {\n if (!layout.hasOwnProperty(key)) {\n map.setLayoutProperty(id, key, undefined);\n }\n }\n }\n if (paint !== prevProps.paint) {\n const prevPaint = prevProps.paint || {};\n for (const key in paint) {\n if (!deepEqual(paint[key], prevPaint[key])) {\n map.setPaintProperty(id, key, paint[key]);\n }\n }\n for (const key in prevPaint) {\n if (!paint.hasOwnProperty(key)) {\n map.setPaintProperty(id, key, undefined);\n }\n }\n }\n\n if (!deepEqual(filter, prevProps.filter)) {\n map.setFilter(id, filter);\n }\n if (minzoom !== prevProps.minzoom || maxzoom !== prevProps.maxzoom) {\n map.setLayerZoomRange(id, minzoom, maxzoom);\n }\n}\n\nfunction createLayer<LayerT extends ILayer>(\n map: MapInstance,\n id: string,\n props: LayerProps<LayerT>\n) {\n // @ts-ignore\n if (map.style && map.style._loaded && (!('source' in props) || map.getSource(props.source))) {\n const options: LayerProps<LayerT> = {...props, id};\n delete options.beforeId;\n\n // @ts-ignore\n map.addLayer(options, props.beforeId);\n }\n}\n\n/* eslint-enable complexity, max-statements */\n\nlet layerCounter = 0;\n\nfunction Layer<LayerT extends ILayer>(props: LayerProps<LayerT | CustomLayerInterface>) {\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-layer-${layerCounter++}`, []);\n\n useEffect(() => {\n if (map) {\n const forceUpdate = () => setStyleLoaded(version => version + 1);\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.getLayer(id)) {\n map.removeLayer(id);\n }\n };\n }\n return undefined;\n }, [map]);\n\n // @ts-ignore\n const layer = map && map.style && map.getLayer(id);\n if (layer) {\n try {\n updateLayer(map, id, props, propsRef.current);\n } catch (error) {\n console.warn(error); // eslint-disable-line\n }\n } else {\n createLayer(map, id, props);\n }\n\n // Store last rendered props\n propsRef.current = props;\n\n return null;\n}\n\nexport default Layer;\n"],"mappings":"AAAA,SAAQA,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,MAAM,QAAO,OAAO;AAAC,SAC/DC,UAAU;AAAA,OACXC,MAAM;AAAA,SACLC,SAAS;AAejB,SAASC,WAAWA,CAClBC,GAAgB,EAChBC,EAAU,EACVC,KAAyB,EACzBC,SAA6B,EAC7B;EACAN,MAAM,CAACK,KAAK,CAACD,EAAE,KAAKE,SAAS,CAACF,EAAE,EAAE,kBAAkB,CAAC;EACrDJ,MAAM,CAACK,KAAK,CAACE,IAAI,KAAKD,SAAS,CAACC,IAAI,EAAE,oBAAoB,CAAC;EAE3D,IAAIF,KAAK,C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
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
1
|
import * as React from 'react';
|
|
5
2
|
import { useState, useRef, useEffect, useContext, useMemo, useImperativeHandle } from 'react';
|
|
6
3
|
import { MountedMapsContext } from "./use-map.js";
|
|
@@ -45,7 +42,7 @@ export default function Map(props, ref, defaultLib) {
|
|
|
45
42
|
contextValue.map = createRef(mapbox);
|
|
46
43
|
contextValue.mapLib = mapboxgl;
|
|
47
44
|
setMapInstance(mapbox);
|
|
48
|
-
mountedMapsContext
|
|
45
|
+
mountedMapsContext?.onMapMount(contextValue.map, props.id);
|
|
49
46
|
} else {
|
|
50
47
|
throw new Error('Map is not supported by this browser');
|
|
51
48
|
}
|
|
@@ -67,7 +64,7 @@ export default function Map(props, ref, defaultLib) {
|
|
|
67
64
|
return () => {
|
|
68
65
|
isMounted = false;
|
|
69
66
|
if (mapbox) {
|
|
70
|
-
mountedMapsContext
|
|
67
|
+
mountedMapsContext?.onMapUnmount(props.id);
|
|
71
68
|
if (props.reuseMaps) {
|
|
72
69
|
mapbox.recycle();
|
|
73
70
|
} else {
|
|
@@ -82,11 +79,12 @@ export default function Map(props, ref, defaultLib) {
|
|
|
82
79
|
}
|
|
83
80
|
});
|
|
84
81
|
useImperativeHandle(ref, () => contextValue.map, [mapInstance]);
|
|
85
|
-
const style = useMemo(() =>
|
|
82
|
+
const style = useMemo(() => ({
|
|
86
83
|
position: 'relative',
|
|
87
84
|
width: '100%',
|
|
88
|
-
height: '100%'
|
|
89
|
-
|
|
85
|
+
height: '100%',
|
|
86
|
+
...props.style
|
|
87
|
+
}), [props.style]);
|
|
90
88
|
const CHILD_CONTAINER_STYLE = {
|
|
91
89
|
height: '100%'
|
|
92
90
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.js","names":["React","useState","useRef","useEffect","useContext","useMemo","useImperativeHandle","MountedMapsContext","Mapbox","createRef","useIsomorphicLayoutEffect","setGlobals","MapContext","createContext","Map","props","ref","defaultLib","mountedMapsContext","mapInstance","setMapInstance","containerRef","current","contextValue","mapLib","map","isMounted","mapbox","Promise","resolve","then","module","Error","mapboxgl","default","supported","reuseMaps","reuse","onMapMount","id","catch","error","onError","type","target","originalEvent","console","onMapUnmount","recycle","destroy","setProps","style","
|
|
1
|
+
{"version":3,"file":"map.js","names":["React","useState","useRef","useEffect","useContext","useMemo","useImperativeHandle","MountedMapsContext","Mapbox","createRef","useIsomorphicLayoutEffect","setGlobals","MapContext","createContext","Map","props","ref","defaultLib","mountedMapsContext","mapInstance","setMapInstance","containerRef","current","contextValue","mapLib","map","isMounted","mapbox","Promise","resolve","then","module","Error","mapboxgl","default","supported","reuseMaps","reuse","onMapMount","id","catch","error","onError","type","target","originalEvent","console","onMapUnmount","recycle","destroy","setProps","style","position","width","height","CHILD_CONTAINER_STYLE","createElement","Provider","value","children"],"sources":["../../src/components/map.tsx"],"sourcesContent":["import * as React from 'react';\nimport {useState, useRef, useEffect, useContext, useMemo, useImperativeHandle} from 'react';\n\nimport {MountedMapsContext} from './use-map';\nimport Mapbox, {MapboxProps} from '../mapbox/mapbox';\nimport createRef, {MapRef} from '../mapbox/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, MapInstance, MapStyle, Callbacks} from '../types';\n\nexport type MapContextValue<MapT extends MapInstance = MapInstance> = {\n mapLib: MapLib<MapT>;\n map: MapRef<MapT>;\n};\n\nexport const MapContext = React.createContext<MapContextValue>(null);\n\ntype MapInitOptions<MapOptions> = Omit<\n MapOptions,\n 'style' | 'container' | 'bounds' | 'fitBoundsOptions' | 'center'\n>;\n\nexport type MapProps<\n MapOptions,\n StyleT extends MapStyle,\n CallbacksT extends Callbacks,\n MapT extends MapInstance\n> = MapInitOptions<MapOptions> &\n MapboxProps<StyleT, CallbacksT> &\n GlobalSettings & {\n mapLib?: MapLib<MapT> | Promise<MapLib<MapT>>;\n reuseMaps?: boolean;\n /** Map container id */\n id?: string;\n /** Map container CSS style */\n style?: CSSProperties;\n children?: any;\n };\n\nexport default function Map<\n MapOptions,\n StyleT extends MapStyle,\n CallbacksT extends Callbacks,\n MapT extends MapInstance\n>(\n props: MapProps<MapOptions, StyleT, CallbacksT, MapT>,\n ref: React.Ref<MapRef<MapT>>,\n defaultLib: MapLib<MapT> | Promise<MapLib<MapT>>\n) {\n const mountedMapsContext = useContext(MountedMapsContext);\n const [mapInstance, setMapInstance] = useState<Mapbox<StyleT, CallbacksT, MapT>>(null);\n const containerRef = useRef();\n\n const {current: contextValue} = useRef<MapContextValue<MapT>>({mapLib: null, map: null});\n\n useEffect(() => {\n const mapLib = props.mapLib;\n let isMounted = true;\n let mapbox: Mapbox<StyleT, CallbacksT, MapT>;\n\n Promise.resolve(mapLib || defaultLib)\n .then((module: MapLib<MapT> | {default: MapLib<MapT>}) => {\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 // workerUrl & workerClass may change the result of supported()\n // https://github.com/visgl/react-map-gl/discussions/2027\n setGlobals(mapboxgl, props);\n if (!mapboxgl.supported || mapboxgl.supported(props)) {\n if (props.reuseMaps) {\n mapbox = Mapbox.reuse(props, containerRef.current);\n }\n if (!mapbox) {\n mapbox = new Mapbox(mapboxgl.Map, props, containerRef.current);\n }\n contextValue.map = createRef(mapbox);\n contextValue.mapLib = mapboxgl;\n\n setMapInstance(mapbox);\n mountedMapsContext?.onMapMount(contextValue.map, props.id);\n } else {\n throw new Error('Map is not supported by this browser');\n }\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 (mapbox) {\n mountedMapsContext?.onMapUnmount(props.id);\n if (props.reuseMaps) {\n mapbox.recycle();\n } else {\n mapbox.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 {props.children}\n </div>\n </MapContext.Provider>\n )}\n </div>\n );\n}\n"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAAQC,QAAQ,EAAEC,MAAM,EAAEC,SAAS,EAAEC,UAAU,EAAEC,OAAO,EAAEC,mBAAmB,QAAO,OAAO;AAAC,SAEpFC,kBAAkB;AAAA,OACnBC,MAAM;AAAA,OACNC,SAAS;AAAA,OAGTC,yBAAyB;AAAA,OACzBC,UAAU;AAQjB,OAAO,MAAMC,UAAU,GAAGZ,KAAK,CAACa,aAAa,CAAkB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E/D,MAAMgC,KAAoB,GAAG9C,OAAO,CAClC,OAAO;IACL+C,QAAQ,EAAE,UAAU;IACpBC,KAAK,EAAE,MAAM;IACbC,MAAM,EAAE,MAAM;IACd,GAAGvC,KAAK,CAACoC;EACX,CAAC,CAAC,EACF,CAACpC,KAAK,CAACoC,KAAK,CACd,CAAC;EAED,MAAMI,qBAAqB,GAAG;IAC5BD,MAAM,EAAE;EACV,CAAC;EAED,OACEtD,KAAA,CAAAwD,aAAA;IAAKjB,EAAE,EAAExB,KAAK,CAACwB,EAAG;IAACvB,GAAG,EAAEK,YAAa;IAAC8B,KAAK,EAAEA;EAAM,GAChDhC,WAAW,IACVnB,KAAA,CAAAwD,aAAA,CAAC5C,UAAU,CAAC6C,QAAQ;IAACC,KAAK,EAAEnC;EAAa,GACvCvB,KAAA,CAAAwD,aAAA;IAAK,qBAAkB,EAAE;IAACL,KAAK,EAAEI;EAAsB,GACpDxC,KAAK,CAAC4C,QACJ,CACc,CAEpB,CAAC;AAEV","ignoreList":[]}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
1
|
import * as React from 'react';
|
|
5
2
|
import { createPortal } from 'react-dom';
|
|
6
3
|
import { useImperativeHandle, useEffect, useMemo, useRef, useContext, forwardRef, memo } from 'react';
|
|
@@ -23,36 +20,33 @@ function Marker(props, ref) {
|
|
|
23
20
|
hasChildren = true;
|
|
24
21
|
}
|
|
25
22
|
});
|
|
26
|
-
const options =
|
|
23
|
+
const options = {
|
|
24
|
+
...props,
|
|
27
25
|
element: hasChildren ? document.createElement('div') : null
|
|
28
|
-
}
|
|
26
|
+
};
|
|
29
27
|
const mk = new mapLib.Marker(options);
|
|
30
28
|
mk.setLngLat([props.longitude, props.latitude]);
|
|
31
29
|
mk.getElement().addEventListener('click', e => {
|
|
32
|
-
|
|
33
|
-
(_thisRef$current$prop = (_thisRef$current$prop2 = thisRef.current.props).onClick) === null || _thisRef$current$prop === void 0 || _thisRef$current$prop.call(_thisRef$current$prop2, {
|
|
30
|
+
thisRef.current.props.onClick?.({
|
|
34
31
|
type: 'click',
|
|
35
32
|
target: mk,
|
|
36
33
|
originalEvent: e
|
|
37
34
|
});
|
|
38
35
|
});
|
|
39
36
|
mk.on('dragstart', e => {
|
|
40
|
-
var _thisRef$current$prop3, _thisRef$current$prop4;
|
|
41
37
|
const evt = e;
|
|
42
38
|
evt.lngLat = marker.getLngLat();
|
|
43
|
-
|
|
39
|
+
thisRef.current.props.onDragStart?.(evt);
|
|
44
40
|
});
|
|
45
41
|
mk.on('drag', e => {
|
|
46
|
-
var _thisRef$current$prop5, _thisRef$current$prop6;
|
|
47
42
|
const evt = e;
|
|
48
43
|
evt.lngLat = marker.getLngLat();
|
|
49
|
-
|
|
44
|
+
thisRef.current.props.onDrag?.(evt);
|
|
50
45
|
});
|
|
51
46
|
mk.on('dragend', e => {
|
|
52
|
-
var _thisRef$current$prop7, _thisRef$current$prop8;
|
|
53
47
|
const evt = e;
|
|
54
48
|
evt.lngLat = marker.getLngLat();
|
|
55
|
-
|
|
49
|
+
thisRef.current.props.onDragEnd?.(evt);
|
|
56
50
|
});
|
|
57
51
|
return mk;
|
|
58
52
|
}, []);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marker.js","names":["React","createPortal","useImperativeHandle","useEffect","useMemo","useRef","useContext","forwardRef","memo","applyReactStyle","MapContext","arePointsEqual","Marker","props","ref","map","mapLib","thisRef","current","marker","hasChildren","Children","forEach","children","el","options","
|
|
1
|
+
{"version":3,"file":"marker.js","names":["React","createPortal","useImperativeHandle","useEffect","useMemo","useRef","useContext","forwardRef","memo","applyReactStyle","MapContext","arePointsEqual","Marker","props","ref","map","mapLib","thisRef","current","marker","hasChildren","Children","forEach","children","el","options","element","document","createElement","mk","setLngLat","longitude","latitude","getElement","addEventListener","e","onClick","type","target","originalEvent","on","evt","lngLat","getLngLat","onDragStart","onDrag","onDragEnd","addTo","getMap","remove","offset","style","draggable","popup","rotation","rotationAlignment","pitchAlignment","lng","lat","getOffset","setOffset","isDraggable","setDraggable","getRotation","setRotation","getRotationAlignment","setRotationAlignment","getPitchAlignment","setPitchAlignment","getPopup","setPopup"],"sources":["../../src/components/marker.ts"],"sourcesContent":["/* global document */\nimport * as React from 'react';\nimport {createPortal} from 'react-dom';\nimport {useImperativeHandle, useEffect, useMemo, useRef, useContext, forwardRef, memo} from 'react';\nimport {applyReactStyle} from '../utils/apply-react-style';\n\nimport type {MarkerEvent, MarkerDragEvent, PointLike, MarkerInstance} from '../types';\n\nimport {MapContext} from './map';\nimport {arePointsEqual} from '../utils/deep-equal';\n\nexport type MarkerProps<OptionsT, MarkerT extends MarkerInstance> = OptionsT & {\n /** Longitude of the anchor location */\n longitude: number;\n /** Latitude of the anchor location */\n latitude: number;\n\n // These types will be further constraint by OptionsT\n draggable?: boolean;\n offset?: PointLike;\n pitchAlignment?: string;\n rotation?: number;\n rotationAlignment?: string;\n popup?: any;\n\n /** CSS style override, applied to the control's container */\n style?: React.CSSProperties;\n onClick?: (e: MarkerEvent<MarkerT, MouseEvent>) => void;\n onDragStart?: (e: MarkerDragEvent<MarkerT>) => void;\n onDrag?: (e: MarkerDragEvent<MarkerT>) => void;\n onDragEnd?: (e: MarkerDragEvent<MarkerT>) => void;\n children?: React.ReactNode;\n};\n\n/* eslint-disable complexity,max-statements */\nfunction Marker<MarkerOptions, MarkerT extends MarkerInstance>(\n props: MarkerProps<MarkerOptions, MarkerT>,\n ref: React.Ref<MarkerT>\n) {\n const {map, mapLib} = useContext(MapContext);\n const thisRef = useRef({props});\n thisRef.current.props = props;\n\n const marker: MarkerT = 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') : null\n };\n\n const mk = new mapLib.Marker(options) as MarkerT;\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<MarkerT>;\n evt.lngLat = marker.getLngLat();\n thisRef.current.props.onDragStart?.(evt);\n });\n mk.on('drag', e => {\n const evt = e as MarkerDragEvent<MarkerT>;\n evt.lngLat = marker.getLngLat();\n thisRef.current.props.onDrag?.(evt);\n });\n mk.on('dragend', e => {\n const evt = e as MarkerDragEvent<MarkerT>;\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 if (marker.getLngLat().lng !== longitude || marker.getLngLat().lat !== latitude) {\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\n return createPortal(props.children, marker.getElement());\n}\n\nexport default memo(forwardRef(Marker));\n"],"mappings":"AACA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAAQC,YAAY,QAAO,WAAW;AACtC,SAAQC,mBAAmB,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,UAAU,EAAEC,UAAU,EAAEC,IAAI,QAAO,OAAO;AAAC,SAC5FC,eAAe;AAAA,SAIfC,UAAU;AAAA,SACVC,cAAc;AA0BtB,SAASC,MAAMA,CACbC,KAA0C,EAC1CC,GAAuB,EACvB;EACA,MAAM;IAACC,GAAG;IAAEC;EAAM,CAAC,GAAGV,UAAU,CAACI,UAAU,CAAC;EAC5C,MAAMO,OAAO,GAAGZ,MAAM,CAAC;IAACQ;EAAK,CAAC,CAAC;EAC/BI,OAAO,CAACC,OAAO,CAACL,KAAK,GAAGA,KAAK;EAE7B,MAAMM,MAAe,GAAGf,OAAO,CAAC,MAAM;IACpC,IAAIgB,WAAW,GAAG,KAAK;IACvBpB,KAAK,CAACqB,QAAQ,CAACC,OAAO,CAACT,KAAK,CAACU,QAAQ,EAAEC,EAAE,IAAI;MAC3C,IAAIA,EAAE,EAAE;QACNJ,WAAW,GAAG,IAAI;MACpB;IACF,CAAC,CAAC;IACF,MAAMK,OAAO,GAAG;MACd,GAAGZ,KAAK;MACRa,OAAO,EAAEN,WAAW,GAAGO,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC,GAAG;IACzD,CAAC;IAED,MAAMC,EAAE,GAAG,IAAIb,MAAM,CAACJ,MAAM,CAACa,OAAO,CAAY;IAChDI,EAAE,CAACC,SAAS,CA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;EACA,IAAIpC,MAAM,CAACgD,iBAAiB,CAAC,CAAC,KAAKX,cAAc,EAAE;IACjDrC,MAAM,CAACiD,iBAAiB,CAACZ,cAAc,CAAC;EAC1C;EACA,IAAIrC,MAAM,CAACkD,QAAQ,CAAC,CAAC,KAAKhB,KAAK,EAAE;IAC/BlC,MAAM,CAACmD,QAAQ,CAACjB,KAAK,CAAC;EACxB;EAEA,OAAOpD,YAAY,CAACY,KAAK,CAACU,QAAQ,EAAEJ,MAAM,CAACc,UAAU,CAAC,CAAC,CAAC;AAC1D;AAEA,eAAezB,IAAI,CAACD,UAAU,CAACK,MAAM,CAAC,CAAC","ignoreList":[]}
|
package/dist/components/popup.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
1
|
import { createPortal } from 'react-dom';
|
|
5
2
|
import { useImperativeHandle, useEffect, useMemo, useRef, useContext, forwardRef, memo } from 'react';
|
|
6
3
|
import { applyReactStyle } from "../utils/apply-react-style.js";
|
|
@@ -22,19 +19,19 @@ function Popup(props, ref) {
|
|
|
22
19
|
});
|
|
23
20
|
thisRef.current.props = props;
|
|
24
21
|
const popup = useMemo(() => {
|
|
25
|
-
const options =
|
|
22
|
+
const options = {
|
|
23
|
+
...props
|
|
24
|
+
};
|
|
26
25
|
const pp = new mapLib.Popup(options);
|
|
27
26
|
pp.setLngLat([props.longitude, props.latitude]);
|
|
28
27
|
pp.once('open', e => {
|
|
29
|
-
|
|
30
|
-
(_thisRef$current$prop = (_thisRef$current$prop2 = thisRef.current.props).onOpen) === null || _thisRef$current$prop === void 0 || _thisRef$current$prop.call(_thisRef$current$prop2, e);
|
|
28
|
+
thisRef.current.props.onOpen?.(e);
|
|
31
29
|
});
|
|
32
30
|
return pp;
|
|
33
31
|
}, []);
|
|
34
32
|
useEffect(() => {
|
|
35
33
|
const onClose = e => {
|
|
36
|
-
|
|
37
|
-
(_thisRef$current$prop3 = (_thisRef$current$prop4 = thisRef.current.props).onClose) === null || _thisRef$current$prop3 === void 0 || _thisRef$current$prop3.call(_thisRef$current$prop4, e);
|
|
34
|
+
thisRef.current.props.onClose?.(e);
|
|
38
35
|
};
|
|
39
36
|
popup.on('close', onClose);
|
|
40
37
|
popup.setDOMContent(container).addTo(map.getMap());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popup.js","names":["createPortal","useImperativeHandle","useEffect","useMemo","useRef","useContext","forwardRef","memo","applyReactStyle","MapContext","deepEqual","getClassList","className","Set","trim","split","Popup","props","ref","map","mapLib","container","document","createElement","thisRef","current","popup","options","
|
|
1
|
+
{"version":3,"file":"popup.js","names":["createPortal","useImperativeHandle","useEffect","useMemo","useRef","useContext","forwardRef","memo","applyReactStyle","MapContext","deepEqual","getClassList","className","Set","trim","split","Popup","props","ref","map","mapLib","container","document","createElement","thisRef","current","popup","options","pp","setLngLat","longitude","latitude","once","e","onOpen","onClose","on","setDOMContent","addTo","getMap","off","isOpen","remove","getElement","style","getLngLat","lng","lat","offset","setOffset","anchor","maxWidth","setMaxWidth","prevClassList","nextClassList","c","has","removeClassName","addClassName","children"],"sources":["../../src/components/popup.ts"],"sourcesContent":["/* global document */\nimport * as React from 'react';\nimport {createPortal} from 'react-dom';\nimport {useImperativeHandle, useEffect, useMemo, useRef, useContext, forwardRef, memo} from 'react';\nimport {applyReactStyle} from '../utils/apply-react-style';\n\nimport type {PopupEvent, PopupInstance} from '../types';\n\nimport {MapContext} from './map';\nimport {deepEqual} from '../utils/deep-equal';\n\nexport type PopupProps<OptionsT, PopupT extends PopupInstance> = OptionsT & {\n /** Longitude of the anchor location */\n longitude: number;\n /** Latitude of the anchor location */\n latitude: number;\n\n // These types will be further constraint by OptionsT\n anchor?: string;\n offset?: any;\n className?: string;\n maxWidth?: string;\n\n /** CSS style override, applied to the control's container */\n style?: React.CSSProperties;\n\n onOpen?: (e: PopupEvent<PopupT>) => void;\n onClose?: (e: PopupEvent<PopupT>) => void;\n children?: React.ReactNode;\n};\n\n// Adapted from https://github.com/mapbox/mapbox-gl-js/blob/v1.13.0/src/ui/popup.js\nfunction getClassList(className: string) {\n return new Set(className ? className.trim().split(/\\s+/) : []);\n}\n\n/* eslint-disable complexity,max-statements */\nfunction Popup<PopupOptions, PopupT extends PopupInstance>(\n props: PopupProps<PopupOptions, PopupT>,\n ref: React.Ref<PopupT>\n) {\n const {map, mapLib} = useContext(MapContext);\n const container = useMemo(() => {\n return document.createElement('div');\n }, []);\n const thisRef = useRef({props});\n thisRef.current.props = props;\n\n const popup: PopupT = useMemo(() => {\n const options = {...props};\n const pp = new mapLib.Popup(options) as PopupT;\n pp.setLngLat([props.longitude, props.latitude]);\n pp.once('open', e => {\n thisRef.current.props.onOpen?.(e as PopupEvent<PopupT>);\n });\n return pp;\n }, []);\n\n useEffect(() => {\n const onClose = e => {\n thisRef.current.props.onClose?.(e as PopupEvent<PopupT>);\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 if (popup.getLngLat().lng !== props.longitude || popup.getLngLat().lat !== props.latitude) {\n popup.setLngLat([props.longitude, props.latitude]);\n }\n if (props.offset && !deepEqual(popup.options.offset, props.offset)) {\n popup.setOffset(props.offset);\n }\n if (popup.options.anchor !== props.anchor || popup.options.maxWidth !== props.maxWidth) {\n popup.options.anchor = props.anchor;\n popup.setMaxWidth(props.maxWidth);\n }\n if (popup.options.className !== props.className) {\n const prevClassList = getClassList(popup.options.className);\n const nextClassList = getClassList(props.className);\n\n for (const c of prevClassList) {\n if (!nextClassList.has(c)) {\n popup.removeClassName(c);\n }\n }\n for (const c of nextClassList) {\n if (!prevClassList.has(c)) {\n popup.addClassName(c);\n }\n }\n popup.options.className = props.className;\n }\n }\n\n return createPortal(props.children, container);\n}\n\nexport default memo(forwardRef(Popup));\n"],"mappings":"AAEA,SAAQA,YAAY,QAAO,WAAW;AACtC,SAAQC,mBAAmB,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,UAAU,EAAEC,UAAU,EAAEC,IAAI,QAAO,OAAO;AAAC,SAC5FC,eAAe;AAAA,SAIfC,UAAU;AAAA,SACVC,SAAS;AAuBjB,SAASC,YAAYA,CAACC,SAAiB,EAAE;EACvC,OAAO,IAAIC,GAAG,CAACD,SAAS,GAAGA,SAAS,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;AAChE;AAGA,SAASC,KAAKA,CACZC,KAAuC,EACvCC,GAAsB,EACtB;EACA,MAAM;IAACC,GAAG;IAAEC;EAAM,CAAC,GAAGf,UAAU,CAACI,UAAU,CAAC;EAC5C,MAAMY,SAAS,GAAGlB,OAAO,CAAC,MAAM;IAC9B,OAAOmB,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EACtC,CAAC,EAAE,EAAE,CAAC;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B,KAAK,CAAC+B,eAAe,CAACF,CAAC,CAAC;QAC1B;MACF;MACA,KAAK,MAAMA,CAAC,IAAID,aAAa,EAAE;QAC7B,IAAI,CAACD,aAAa,CAACG,GAAG,CAACD,CAAC,CAAC,EAAE;UACzB7B,KAAK,CAACgC,YAAY,CAACH,CAAC,CAAC;QACvB;MACF;MACA7B,KAAK,CAACC,OAAO,CAACf,SAAS,GAAGK,KAAK,CAACL,SAAS;IAC3C;EACF;EAEA,OAAOZ,YAAY,CAACiB,KAAK,CAAC0C,QAAQ,EAAEtC,SAAS,CAAC;AAChD;AAEA,eAAed,IAAI,CAACD,UAAU,CAACU,KAAK,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
1
|
import * as React from 'react';
|
|
5
2
|
import { useContext, useEffect, useMemo, useState, useRef } from 'react';
|
|
6
3
|
import { cloneElement } from 'react';
|
|
@@ -10,7 +7,9 @@ import { deepEqual } from "../utils/deep-equal.js";
|
|
|
10
7
|
let sourceCounter = 0;
|
|
11
8
|
function createSource(map, id, props) {
|
|
12
9
|
if (map.style && map.style._loaded) {
|
|
13
|
-
const options =
|
|
10
|
+
const options = {
|
|
11
|
+
...props
|
|
12
|
+
};
|
|
14
13
|
delete options.id;
|
|
15
14
|
delete options.children;
|
|
16
15
|
map.addSource(id, options);
|
|
@@ -69,8 +68,7 @@ function Source(props) {
|
|
|
69
68
|
return () => {
|
|
70
69
|
map.off('styledata', forceUpdate);
|
|
71
70
|
if (map.style && map.style._loaded && map.getSource(id)) {
|
|
72
|
-
|
|
73
|
-
const allLayers = (_map$getStyle = map.getStyle()) === null || _map$getStyle === void 0 ? void 0 : _map$getStyle.layers;
|
|
71
|
+
const allLayers = map.getStyle()?.layers;
|
|
74
72
|
if (allLayers) {
|
|
75
73
|
for (const layer of allLayers) {
|
|
76
74
|
if (layer.source === id) {
|
|
@@ -1 +1 @@
|
|
|
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","
|
|
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 {useContext, useEffect, useMemo, useState, useRef} from 'react';\nimport {cloneElement} from 'react';\nimport {MapContext} from './map';\nimport assert from '../utils/assert';\nimport {deepEqual} from '../utils/deep-equal';\n\nimport type {\n MapInstance,\n ISource,\n CustomSource,\n GeoJSONSourceImplementation,\n ImageSourceImplemtation,\n AnySourceImplementation\n} from '../types';\nimport type {GeoJSONSourceRaw, ImageSourceRaw, VectorSourceRaw} from '../types/style-spec-bkoi-gl';\n\nexport type SourceProps<SourceT> = (SourceT | CustomSource) & {\n id?: string;\n children?: any;\n};\n\nlet sourceCounter = 0;\n\nfunction createSource<SourceT extends ISource>(\n map: MapInstance,\n id: string,\n props: SourceProps<SourceT>\n) {\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<SourceT extends ISource>(\n source: AnySourceImplementation,\n props: SourceProps<SourceT>,\n prevProps: SourceProps<SourceT>\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 (key !== 'children' && key !== 'id' && !deepEqual(prevProps[key], props[key])) {\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(\n (props as unknown as GeoJSONSourceRaw).data as any\n );\n } else if (type === 'image') {\n (source as ImageSourceImplemtation).updateImage({\n url: (props as unknown as ImageSourceRaw).url,\n coordinates: (props as unknown as ImageSourceRaw).coordinates\n });\n } else if ('setCoordinates' in source && changedKeyCount === 1 && changedKey === 'coordinates') {\n source.setCoordinates((props as ImageSourceRaw).coordinates);\n } else if ('setUrl' in source) {\n // Added in 1.12.0:\n // vectorTileSource.setTiles\n // vectorTileSource.setUrl\n switch (changedKey) {\n case 'url':\n source.setUrl((props as VectorSourceRaw).url);\n break;\n case 'tiles':\n source.setTiles((props as VectorSourceRaw).tiles);\n break;\n default:\n }\n } else {\n // eslint-disable-next-line\n console.warn(`Unable to update <Source> prop: ${changedKey}`);\n }\n}\n/* eslint-enable complexity */\n\nfunction Source<SourceT extends ISource>(props: SourceProps<SourceT>) {\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 = () => 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\nexport default Source;\n"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAAQC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,MAAM,QAAO,OAAO;AACtE,SAAQC,YAAY,QAAO,OAAO;AAAC,SAC3BC,UAAU;AAAA,OACXC,MAAM;AAAA,SACLC,SAAS;AAiBjB,IAAIC,aAAa,GAAG,CAAC;AAErB,SAASC,YAAYA,CACnBC,GAAgB,EAChBC,EAAU,EACVC,KAA2B,EAC3B;EAEA,IAAIF,GAAG,CAACG,KAAK,IAAIH,GAAG,CAACG,KAAK,CAACC,OAAO,EAAE;IAClC,MAAMC,OAAO,GAAG;MAAC,GAAGH;IAAK,CAAC;IAC1B,OAAOG,OAAO,CAACJ,EAAE;IACjB,OAAOI,OAAO,CAACC,QAAQ;IAEvBN,GAAG,CAACO,SAAS,CAACN,EAAE,EAAEI,OAAO,CAAC;IAC1B,OAAOL,GAAG,CAACQ,SAAS,CAACP,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7B,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,EACduC,KAAK,IACHA,KAAK,IACLnD,YAAY,CAACmD,KAAK,EAAE;IAClBnC,MAAM,EAAET;EACV,CAAC,CACL,CAAC,IACH,IAAI;AAER;AAEA,eAAe0B,MAAM","ignoreList":[]}
|
|
@@ -11,7 +11,7 @@ function useControl(onCreate, arg1, arg2, arg3) {
|
|
|
11
11
|
map
|
|
12
12
|
} = context;
|
|
13
13
|
if (!map.hasControl(ctrl)) {
|
|
14
|
-
map.addControl(ctrl, opts
|
|
14
|
+
map.addControl(ctrl, opts?.position);
|
|
15
15
|
if (onAdd) {
|
|
16
16
|
onAdd(context);
|
|
17
17
|
}
|
|
@@ -1 +1 @@
|
|
|
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';\nimport {MapContext} from './map';\nimport type {MapContextValue} from './map';\n\ntype ControlOptions = {\n position?: ControlPosition;\n};\n\nfunction useControl<T extends IControl>(\n onCreate: (context: MapContextValue) => T,\n opts?: ControlOptions\n): T;\n\nfunction useControl<T extends IControl>(\n onCreate: (context: MapContextValue) => T,\n onRemove: (context: MapContextValue) => void,\n opts?: ControlOptions\n): T;\n\nfunction 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\nfunction 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 = typeof arg1 === 'function' && typeof arg2 === 'function' ? arg1 : null;\n const onRemove = typeof arg2 === 'function' ? arg2 : typeof arg1 === 'function' ? arg1 : 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\nexport default useControl;\n"],"mappings":"AAAA,SAAQA,UAAU,EAAEC,OAAO,EAAEC,SAAS,QAAO,OAAO;AAAC,SAE7CC,UAAU;AAyBlB,SAASC,UAAUA,CACjBC,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,GAAG,OAAON,IAAI,KAAK,UAAU,IAAI,OAAOC,IAAI,KAAK,UAAU,GAAGD,IAAI,GAAG,IAAI;IACpF,MAAMO,QAAQ,GAAG,OAAON,IAAI,KAAK,UAAU,GAAGA,IAAI,GAAG,OAAOD,IAAI,KAAK,UAAU,GAAGA,IAAI,GAAG,IAAI;IAE7F,MAAM;MAACQ;IAAG,CAAC,GAAGL,OAAO;IACrB,IAAI,CAACK,GAAG,CAACC,UAAU,CAACL,IAAI,CAAC,EAAE;MACzBI,GAAG,CAACE,UAAU,CAACN,IAAI,EAAEC,IAAI,
|
|
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';\nimport {MapContext} from './map';\nimport type {MapContextValue} from './map';\n\ntype ControlOptions = {\n position?: ControlPosition;\n};\n\nfunction useControl<T extends IControl>(\n onCreate: (context: MapContextValue) => T,\n opts?: ControlOptions\n): T;\n\nfunction useControl<T extends IControl>(\n onCreate: (context: MapContextValue) => T,\n onRemove: (context: MapContextValue) => void,\n opts?: ControlOptions\n): T;\n\nfunction 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\nfunction 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 = typeof arg1 === 'function' && typeof arg2 === 'function' ? arg1 : null;\n const onRemove = typeof arg2 === 'function' ? arg2 : typeof arg1 === 'function' ? arg1 : 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\nexport default useControl;\n"],"mappings":"AAAA,SAAQA,UAAU,EAAEC,OAAO,EAAEC,SAAS,QAAO,OAAO;AAAC,SAE7CC,UAAU;AAyBlB,SAASC,UAAUA,CACjBC,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,GAAG,OAAON,IAAI,KAAK,UAAU,IAAI,OAAOC,IAAI,KAAK,UAAU,GAAGD,IAAI,GAAG,IAAI;IACpF,MAAMO,QAAQ,GAAG,OAAON,IAAI,KAAK,UAAU,GAAGA,IAAI,GAAG,OAAOD,IAAI,KAAK,UAAU,GAAGA,IAAI,GAAG,IAAI;IAE7F,MAAM;MAACQ;IAAG,CAAC,GAAGL,OAAO;IACrB,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;AAEA,eAAeN,UAAU","ignoreList":[]}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
1
|
import * as React from 'react';
|
|
5
2
|
import { useState, useCallback, useMemo, useContext } from 'react';
|
|
6
3
|
import { MapContext } from "./map.js";
|
|
@@ -16,16 +13,19 @@ export const MapProvider = props => {
|
|
|
16
13
|
if (currMaps[id]) {
|
|
17
14
|
throw new Error(`Multiple maps with the same id: ${id}`);
|
|
18
15
|
}
|
|
19
|
-
return
|
|
16
|
+
return {
|
|
17
|
+
...currMaps,
|
|
20
18
|
[id]: map
|
|
21
|
-
}
|
|
19
|
+
};
|
|
22
20
|
});
|
|
23
21
|
}, []);
|
|
24
22
|
const onMapUnmount = useCallback(function () {
|
|
25
23
|
let id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
|
|
26
24
|
setMaps(currMaps => {
|
|
27
25
|
if (currMaps[id]) {
|
|
28
|
-
const nextMaps =
|
|
26
|
+
const nextMaps = {
|
|
27
|
+
...currMaps
|
|
28
|
+
};
|
|
29
29
|
delete nextMaps[id];
|
|
30
30
|
return nextMaps;
|
|
31
31
|
}
|
|
@@ -41,13 +41,13 @@ export const MapProvider = props => {
|
|
|
41
41
|
}, props.children);
|
|
42
42
|
};
|
|
43
43
|
export function useMap() {
|
|
44
|
-
|
|
45
|
-
const maps = (_useContext = useContext(MountedMapsContext)) === null || _useContext === void 0 ? void 0 : _useContext.maps;
|
|
44
|
+
const maps = useContext(MountedMapsContext)?.maps;
|
|
46
45
|
const currentMap = useContext(MapContext);
|
|
47
46
|
const mapsWithCurrent = useMemo(() => {
|
|
48
|
-
return
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
return {
|
|
48
|
+
...maps,
|
|
49
|
+
current: currentMap?.map
|
|
50
|
+
};
|
|
51
51
|
}, [maps, currentMap]);
|
|
52
52
|
return mapsWithCurrent;
|
|
53
53
|
}
|
|
@@ -1 +1 @@
|
|
|
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","
|
|
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 '../mapbox/create-ref';\nimport {MapContext} from './map';\nimport {MapInstance} from '../types';\n\ntype MountedMapsContextValue = {\n maps: {[id: string]: MapRef<MapInstance>};\n onMapMount: (map: MapRef<MapInstance>, id: string) => void;\n onMapUnmount: (id: string) => void;\n};\n\nexport const MountedMapsContext = React.createContext<MountedMapsContextValue>(null);\n\nexport const MapProvider: React.FC<{children?: React.ReactNode}> = props => {\n const [maps, setMaps] = useState<{[id: string]: MapRef<MapInstance>}>({});\n\n const onMapMount = useCallback((map: MapRef<MapInstance>, 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<MapT extends MapInstance> = {\n [id: string]: MapRef<MapT> | undefined;\n current?: MapRef<MapT>;\n};\n\nexport function useMap<MapT extends MapInstance>(): MapCollection<MapT> {\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<MapT>;\n}\n"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAAQC,QAAQ,EAAEC,WAAW,EAAEC,OAAO,EAAEC,UAAU,QAAO,OAAO;AAAC,SAGzDC,UAAU;AASlB,OAAO,MAAMC,kBAAkB,GAAGN,KAAK,CAACO,aAAa,CAA0B,IAAI,CAAC;AAEpF,OAAO,MAAMC,WAAmD,GAAGC,KAAK,IAAI;EAC1E,MAAM,CAACC,IAAI,EAAEC,OAAO,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