Files
flights_web_raw/ClientApp/node_modules/react-leaflet/lib/Popup.js
T
gnezim 0a5ab058a6 Initial commit: Aeroflot Flights Web - Angular 12 baseline
- Angular 12 application with PrimeNG components
- 5 existing Cypress e2e test suites
- SCSS styling with BEM naming convention
- i18n support (10 languages)
- Leaflet map integration
- Complete component hierarchy and routing structure

This baseline will be used for Angular → React migration.
2026-04-05 18:47:57 +03:00

50 lines
1.6 KiB
JavaScript

import { createElementObject, createOverlayComponent } from '@react-leaflet/core';
import { Popup as LeafletPopup } from 'leaflet';
import { useEffect } from 'react';
export const Popup = createOverlayComponent(function createPopup(props, context) {
const popup = new LeafletPopup(props, context.overlayContainer);
return createElementObject(popup, context);
}, function usePopupLifecycle(element, context, { position }, setOpen) {
useEffect(function addPopup() {
const { instance } = element;
function onPopupOpen(event) {
if (event.popup === instance) {
instance.update();
setOpen(true);
}
}
function onPopupClose(event) {
if (event.popup === instance) {
setOpen(false);
}
}
context.map.on({
popupopen: onPopupOpen,
popupclose: onPopupClose
});
if (context.overlayContainer == null) {
// Attach to a Map
if (position != null) {
instance.setLatLng(position);
}
instance.openOn(context.map);
} else {
// Attach to container component
context.overlayContainer.bindPopup(instance);
}
return function removePopup() {
context.map.off({
popupopen: onPopupOpen,
popupclose: onPopupClose
});
context.overlayContainer?.unbindPopup();
context.map.removeLayer(instance);
};
}, [
element,
context,
setOpen,
position
]);
});