import React, { useCallback, useEffect, useMemo, useState } from "react"
import Style from "./BoxMap.module.css"
import BoxFull from "./BoxFull"
import { MapContainer, TileLayer } from "react-leaflet"
export default function BoxMap(
{
mapViewHook,
button,
children,
...props
}) {
const [map, setMap] = useState(null)
const onMapMove = useCallback(
() => mapViewHook.setCenter(map.getCenter()),
[mapViewHook, map],
)
const onMapZoom = useCallback(
() => mapViewHook.setZoom(map.getZoom()),
[mapViewHook, map],
)
const mapContainer = useMemo(
() => (
{children}
),
[mapViewHook],
)
useEffect(
() => {
if(map === null) {
return
}
map.on("move", onMapMove)
map.on("zoom", onMapZoom)
return () => {
map.off("move", onMapMove)
map.off("zoom", onMapZoom)
}
},
[map, mapViewHook]
)
return (
{mapContainer}
)
}