forked from VinokurovVE/tests
Object data
This commit is contained in:
85
client/src/store/map.ts
Normal file
85
client/src/store/map.ts
Normal file
@ -0,0 +1,85 @@
|
||||
import { create } from 'zustand';
|
||||
import { ToolType } from '../types/tools';
|
||||
import { Point } from 'ol/geom';
|
||||
import Map from 'ol/Map';
|
||||
|
||||
interface MapState {
|
||||
currentTool: ToolType,
|
||||
measureType: "LineString" | "Polygon",
|
||||
measureShowSegments: boolean,
|
||||
measureClearPrevious: boolean,
|
||||
tipPoint: Point | null,
|
||||
map: Map | null
|
||||
}
|
||||
|
||||
export const useMapStore = create<MapState>(() => ({
|
||||
currentTool: null,
|
||||
measureType: "LineString",
|
||||
measureShowSegments: true,
|
||||
measureClearPrevious: true,
|
||||
tipPoint: null,
|
||||
map: null
|
||||
}));
|
||||
|
||||
const getMap = () => {
|
||||
return useMapStore.getState().map
|
||||
}
|
||||
|
||||
const setMap = (map: Map | null) => {
|
||||
useMapStore.setState(() => ({ map: map }))
|
||||
}
|
||||
|
||||
const setTipPoint = (tipPoint: Point | null) => {
|
||||
useMapStore.setState(() => ({ tipPoint: tipPoint }))
|
||||
}
|
||||
|
||||
const getTipPoint = () => {
|
||||
return useMapStore.getState().tipPoint
|
||||
}
|
||||
|
||||
const setMeasureType = (tool: "LineString" | "Polygon") => {
|
||||
useMapStore.setState(() => ({ measureType: tool }))
|
||||
}
|
||||
|
||||
const getMeasureType = () => {
|
||||
return useMapStore.getState().measureType
|
||||
}
|
||||
|
||||
const setCurrentTool = (tool: ToolType) => {
|
||||
tool === useMapStore.getState().currentTool
|
||||
? useMapStore.setState(() => ({ currentTool: null }))
|
||||
: useMapStore.setState(() => ({ currentTool: tool }))
|
||||
}
|
||||
|
||||
const getCurrentTool = () => {
|
||||
return useMapStore.getState().currentTool
|
||||
}
|
||||
|
||||
const getMeasureShowSegments = () => {
|
||||
return useMapStore.getState().measureShowSegments
|
||||
}
|
||||
|
||||
const getMeasureClearPrevious = () => {
|
||||
return useMapStore.getState().measureClearPrevious
|
||||
}
|
||||
|
||||
const setMeasureShowSegments = (bool: boolean) => {
|
||||
useMapStore.setState(() => ({ measureShowSegments: bool }))
|
||||
}
|
||||
|
||||
const setMeasureClearPrevious = (bool: boolean) => {
|
||||
useMapStore.setState(() => ({ measureClearPrevious: bool }))
|
||||
}
|
||||
|
||||
export {
|
||||
setCurrentTool,
|
||||
getCurrentTool,
|
||||
setMeasureShowSegments,
|
||||
setMeasureClearPrevious,
|
||||
getMeasureShowSegments,
|
||||
getMeasureClearPrevious,
|
||||
setMeasureType,
|
||||
getMeasureType,
|
||||
getTipPoint,
|
||||
setTipPoint
|
||||
}
|
Reference in New Issue
Block a user