@vinctus/react-maplibre 1.3.2 → 1.3.3
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/Popup.d.ts +5 -0
- package/dist/Popup.js +7 -1
- package/package.json +1 -1
package/dist/Popup.d.ts
CHANGED
|
@@ -6,5 +6,10 @@ export type PopupProps = {
|
|
|
6
6
|
className?: string;
|
|
7
7
|
closeOnClick?: boolean;
|
|
8
8
|
closeButton?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Called when MapLibre closes the popup through its close button or a map click. The popup is
|
|
11
|
+
* not reopened by a later render, so the parent should stop rendering it here.
|
|
12
|
+
*/
|
|
13
|
+
onClose?: () => void;
|
|
9
14
|
};
|
|
10
15
|
export declare const Popup: FC<PopupProps>;
|
package/dist/Popup.js
CHANGED
|
@@ -2,8 +2,10 @@ import { useEffect, useContext, useRef } from 'react';
|
|
|
2
2
|
import maplibre from 'maplibre-gl';
|
|
3
3
|
import ReactDOMServer from 'react-dom/server';
|
|
4
4
|
import { MapContext } from './Map';
|
|
5
|
-
export const Popup = ({ children, longitude, latitude, className, closeOnClick, closeButton, }) => {
|
|
5
|
+
export const Popup = ({ children, longitude, latitude, className, closeOnClick, closeButton, onClose, }) => {
|
|
6
6
|
const { map, mapLoaded } = useContext(MapContext);
|
|
7
|
+
const onCloseRef = useRef(onClose);
|
|
8
|
+
onCloseRef.current = onClose;
|
|
7
9
|
// The content is compared by its rendered markup because `children` has a new identity on every
|
|
8
10
|
// parent render.
|
|
9
11
|
const html = ReactDOMServer.renderToStaticMarkup(children);
|
|
@@ -21,8 +23,12 @@ export const Popup = ({ children, longitude, latitude, className, closeOnClick,
|
|
|
21
23
|
.setLngLat(coordinates)
|
|
22
24
|
.setHTML(initialHtml)
|
|
23
25
|
.addTo(map);
|
|
26
|
+
const handleClose = () => { var _a; return (_a = onCloseRef.current) === null || _a === void 0 ? void 0 : _a.call(onCloseRef); };
|
|
27
|
+
popup.on('close', handleClose);
|
|
24
28
|
popupInstance.current = popup;
|
|
25
29
|
return () => {
|
|
30
|
+
// Removing the popup here also fires `close`, which is not a user closing it.
|
|
31
|
+
popup.off('close', handleClose);
|
|
26
32
|
try {
|
|
27
33
|
popup.remove();
|
|
28
34
|
}
|