|
|
|
import produce from "immer";
|
|
|
|
import { initState } from "../../initState";
|
|
|
|
import { IOverlay, OverlayNamePrefixs } from "@store";
|
|
|
|
import { OverlayTypes, Status, Command } from "@types";
|
|
|
|
|
|
|
|
export function createOverlay(state = initState, payload: any) {
|
|
|
|
return produce(state, (draft) => {
|
|
|
|
draft.map.status = Status.CreateOverlay;
|
|
|
|
draft.map.command = Command.CreateOverlay;
|
|
|
|
draft.map.overlayType = payload as OverlayTypes;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function finishEditOverlay(state = initState, payload: any) {
|
|
|
|
return produce(state, (draft) => {
|
|
|
|
const overlay = payload as IOverlay;
|
|
|
|
const { type, id } = overlay;
|
|
|
|
// todo: uniqueName.
|
|
|
|
overlay.name = OverlayNamePrefixs[type] + overlay.id;
|
|
|
|
draft.map.status = null;
|
|
|
|
draft.map.command = null;
|
|
|
|
draft.map.overlayType = null;
|
|
|
|
const overlays =
|
|
|
|
type === OverlayTypes.Rectangle
|
|
|
|
? draft.map.rectangles
|
|
|
|
: type === OverlayTypes.Circle
|
|
|
|
? draft.map.circles
|
|
|
|
: type === OverlayTypes.Polygon
|
|
|
|
? draft.map.polygons
|
|
|
|
: draft.map.polylines;
|
|
|
|
const existed = overlays.find((overlay) => overlay.id === id);
|
|
|
|
if (existed) {
|
|
|
|
overlays[overlays.indexOf(existed)] = overlay;
|
|
|
|
} else {
|
|
|
|
overlays.push(overlay);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function selectOverlay(state = initState, payload: any) {
|
|
|
|
const id = payload as string;
|
|
|
|
return produce(state, (draft) => {
|
|
|
|
draft.map.command = Command.SelectOverlay;
|
|
|
|
draft.map.selectedIds = [id];
|
|
|
|
draft.map.status = null;
|
|
|
|
});
|
|
|
|
}
|