基于高德地图JS api开发的geojson编辑器. http://geojson.finevis.cc/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.5 KiB

3 years ago
import produce from "immer";
import { initState } from "../../initState";
import { IOverlay, OverlayNamePrefixs } from "@store";
3 years ago
import { OverlayTypes, Status, Command } from "@types";
3 years ago
export function createOverlay(state = initState, payload: any) {
return produce(state, (draft) => {
3 years ago
draft.map.status = Status.CreateOverlay;
draft.map.command = Command.CreateOverlay;
draft.map.overlayType = payload as OverlayTypes;
3 years ago
});
}
3 years ago
export function finishEditOverlay(state = initState, payload: any) {
3 years ago
return produce(state, (draft) => {
const overlay = payload as IOverlay;
3 years ago
const { type, id } = overlay;
3 years ago
// todo: uniqueName.
overlay.name = OverlayNamePrefixs[type] + overlay.id;
3 years ago
draft.map.status = null;
draft.map.command = null;
draft.map.overlayType = null;
3 years ago
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);
}
3 years ago
});
}
3 years ago
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;
});
}