mirror of
https://github.com/sstent/aicyclingcoach-go.git
synced 2026-01-27 01:22:18 +00:00
sync
This commit is contained in:
30
node_modules/@react-leaflet/core/lib/control.js
generated
vendored
Normal file
30
node_modules/@react-leaflet/core/lib/control.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { useLeafletContext } from './context.js';
|
||||
export function createControlHook(useElement) {
|
||||
return function useLeafletControl(props) {
|
||||
const context = useLeafletContext();
|
||||
const elementRef = useElement(props, context);
|
||||
const { instance } = elementRef.current;
|
||||
const positionRef = useRef(props.position);
|
||||
const { position } = props;
|
||||
useEffect(function addControl() {
|
||||
instance.addTo(context.map);
|
||||
return function removeControl() {
|
||||
instance.remove();
|
||||
};
|
||||
}, [
|
||||
context.map,
|
||||
instance
|
||||
]);
|
||||
useEffect(function updateControl() {
|
||||
if (position != null && position !== positionRef.current) {
|
||||
instance.setPosition(position);
|
||||
positionRef.current = position;
|
||||
}
|
||||
}, [
|
||||
instance,
|
||||
position
|
||||
]);
|
||||
return elementRef;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user