Download tmp-demo-frontend/node_modules/react-leaflet/lib/Tooltip.js from LarryD123/OurData: direct link, hf CLI and curl.
- Browser
- Download file 1.65 kB
-
https://huggingface.co/datasets/LarryD123/OurData/resolve/main/tmp-demo-frontend/node_modules/react-leaflet/lib/Tooltip.js
- Command line
-
hf download hf://datasets/LarryD123/OurData/tmp-demo-frontend/node_modules/react-leaflet/lib/Tooltip.js
-
curl -L -o Tooltip.js https://huggingface.co/datasets/LarryD123/OurData/resolve/main/tmp-demo-frontend/node_modules/react-leaflet/lib/Tooltip.js
1.65 kB
| 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 | |
| ]); | |
| }); | |