2021-05-25 13:58:52 +00:00
|
|
|
import { useMemo, useState } from "react"
|
2021-05-22 02:44:08 +00:00
|
|
|
import Coordinates from "../objects/Coordinates"
|
|
|
|
import MapArea from "../objects/MapArea"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook which holds values required to create a {@link MapArea}.
|
|
|
|
*/
|
|
|
|
export default function useMapAreaState() {
|
|
|
|
const [zoom, setZoom] = useState(3)
|
|
|
|
const [center, setCenter] = useState(new Coordinates(0, 0))
|
2021-05-25 13:58:52 +00:00
|
|
|
const mapArea = useMemo(
|
|
|
|
() => MapArea.fromZoomLevel(zoom, center),
|
|
|
|
[zoom, center]
|
|
|
|
)
|
2021-05-22 02:44:08 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
zoom,
|
|
|
|
setZoom,
|
|
|
|
center,
|
|
|
|
setCenter,
|
|
|
|
mapArea,
|
|
|
|
}
|
|
|
|
}
|