parent
47b2aeb48b
commit
ed1f4bc47c
@ -0,0 +1,24 @@ |
||||
import leaflet from 'leaflet'; |
||||
import { type Ref, useEffect } from 'preact/hooks'; |
||||
|
||||
export const useLayers = ( |
||||
mapRef: Readonly<Ref<leaflet.Map | undefined>>, |
||||
layers: leaflet.Layer[], |
||||
) => |
||||
useEffect(() => { |
||||
const map = mapRef.current; |
||||
if (!map) { |
||||
return; |
||||
} |
||||
|
||||
for (const layer of layers) { |
||||
layer.addTo(map); |
||||
} |
||||
|
||||
return () => { |
||||
for (const layer of layers) { |
||||
layer.removeFrom(map); |
||||
layer.remove(); |
||||
} |
||||
}; |
||||
}, [mapRef, layers]); |
@ -1,6 +1,6 @@ |
||||
import leaflet from 'leaflet'; |
||||
import { type Ref, useEffect } from 'preact/hooks'; |
||||
import type { Coordinates } from '../../../shared/types'; |
||||
import type { Coordinates } from '../../shared/types'; |
||||
|
||||
export const useMapClick = ( |
||||
mapRef: Readonly<Ref<leaflet.Map | undefined>>, |
@ -1,10 +1,9 @@ |
||||
import { type Ref, useEffect } from 'preact/hooks'; |
||||
import Sortable from 'sortablejs'; |
||||
import type { ReorderListParams } from '../../types'; |
||||
|
||||
export const useSortable = ( |
||||
listContainerRef: Readonly<Ref<HTMLElement>>, |
||||
onListReorder: (params: ReorderListParams) => void, |
||||
onListReorder: (params: { oldIndex: number; newIndex: number }) => void, |
||||
) => |
||||
useEffect(() => { |
||||
if (!listContainerRef.current) { |
Loading…
Reference in new issue