mirror of
https://github.com/sstent/aicyclingcoach-go.git
synced 2026-01-27 01:22:18 +00:00
sync
This commit is contained in:
49
node_modules/react-leaflet/lib/Tooltip.js
generated
vendored
Normal file
49
node_modules/react-leaflet/lib/Tooltip.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
import { createElementObject, createOverlayComponent } from '@react-leaflet/core';
|
||||
import { Tooltip as LeafletTooltip } from 'leaflet';
|
||||
import { useEffect } from 'react';
|
||||
export const Tooltip = createOverlayComponent(function createTooltip(props, context) {
|
||||
const tooltip = new LeafletTooltip(props, context.overlayContainer);
|
||||
return createElementObject(tooltip, context);
|
||||
}, function useTooltipLifecycle(element, context, { position }, setOpen) {
|
||||
useEffect(function addTooltip() {
|
||||
const container = context.overlayContainer;
|
||||
if (container == null) {
|
||||
return;
|
||||
}
|
||||
const { instance } = element;
|
||||
const onTooltipOpen = (event)=>{
|
||||
if (event.tooltip === instance) {
|
||||
if (position != null) {
|
||||
instance.setLatLng(position);
|
||||
}
|
||||
instance.update();
|
||||
setOpen(true);
|
||||
}
|
||||
};
|
||||
const onTooltipClose = (event)=>{
|
||||
if (event.tooltip === instance) {
|
||||
setOpen(false);
|
||||
}
|
||||
};
|
||||
container.on({
|
||||
tooltipopen: onTooltipOpen,
|
||||
tooltipclose: onTooltipClose
|
||||
});
|
||||
container.bindTooltip(instance);
|
||||
return function removeTooltip() {
|
||||
container.off({
|
||||
tooltipopen: onTooltipOpen,
|
||||
tooltipclose: onTooltipClose
|
||||
});
|
||||
// @ts-ignore protected property
|
||||
if (container._map != null) {
|
||||
container.unbindTooltip();
|
||||
}
|
||||
};
|
||||
}, [
|
||||
element,
|
||||
context,
|
||||
setOpen,
|
||||
position
|
||||
]);
|
||||
});
|
||||
Reference in New Issue
Block a user