forked from VinokurovVE/tests
115 lines
3.4 KiB
TypeScript
115 lines
3.4 KiB
TypeScript
import { create } from 'zustand';
|
|
import { ToolType } from '../types/tools';
|
|
import { Point } from 'ol/geom';
|
|
import Map from 'ol/Map';
|
|
import { Coordinate } from 'ol/coordinate';
|
|
import { SatelliteMapsProvider } from '../interfaces/map';
|
|
|
|
interface MapState {
|
|
currentTool: ToolType;
|
|
measureType: "LineString" | "Polygon";
|
|
measureShowSegments: boolean;
|
|
measureClearPrevious: boolean;
|
|
tipPoint: Point | null;
|
|
map: Map | null;
|
|
currentZ: number | undefined;
|
|
currentX: number | undefined;
|
|
currentY: number | undefined;
|
|
currentCoordinate: Coordinate | null;
|
|
statusText: string;
|
|
satMapsProvider: SatelliteMapsProvider;
|
|
selectedObjectType: number | null;
|
|
}
|
|
|
|
export const useMapStore = create<MapState>(() => ({
|
|
currentTool: null,
|
|
measureType: "LineString",
|
|
measureShowSegments: true,
|
|
measureClearPrevious: true,
|
|
tipPoint: null,
|
|
map: null,
|
|
currentZ: undefined,
|
|
currentX: undefined,
|
|
currentY: undefined,
|
|
currentCoordinate: null,
|
|
statusText: '',
|
|
satMapsProvider: 'custom',
|
|
selectedObjectType: null,
|
|
}));
|
|
|
|
const setCurrentZ = (z: number | undefined) => useMapStore.setState(() => ({ currentZ: z }))
|
|
const setCurrentX = (x: number | undefined) => useMapStore.setState(() => ({ currentX: x }))
|
|
const setCurrentY = (y: number | undefined) => useMapStore.setState(() => ({ currentY: y }))
|
|
const setCurrentCoordinate = (c: Coordinate | null) => useMapStore.setState(() => ({ currentCoordinate: c }))
|
|
const setStatusText = (t: string) => useMapStore.setState(() => ({ statusText: t }))
|
|
const setSatMapsProvider = (p: SatelliteMapsProvider) => useMapStore.setState(() => ({ satMapsProvider: p }))
|
|
const setSelectedObjectType = (t: number | null) => useMapStore.setState(() => ({ selectedObjectType: t }))
|
|
const setMap = (m: Map | null) => useMapStore.setState(() => ({ map: m }))
|
|
|
|
const setTipPoint = (tipPoint: Point | null) => {
|
|
useMapStore.setState(() => ({ tipPoint: tipPoint }))
|
|
}
|
|
|
|
const getTipPoint = () => {
|
|
return useMapStore.getState().tipPoint
|
|
}
|
|
|
|
const getMap = () => {
|
|
return useMapStore.getState().map
|
|
}
|
|
|
|
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,
|
|
setCurrentZ,
|
|
setCurrentX,
|
|
setCurrentY,
|
|
setCurrentCoordinate,
|
|
setStatusText,
|
|
setSatMapsProvider,
|
|
setSelectedObjectType,
|
|
setMap,
|
|
getMap
|
|
} |