Browse Source

修复不能多次选中删除的问题

master
Cmen 3 years ago
parent
commit
eb6f5dd06c
  1. 1
      src/map/MapEditor.ts
  2. 2
      src/map/editors/BaseOverlayEditor.ts
  3. 2
      src/map/editors/CircleEditor.ts
  4. 2
      src/map/editors/PolygonEditor.ts
  5. 2
      src/map/editors/PolylineEditor.ts
  6. 2
      src/map/editors/RectangleEditor.ts
  7. 1
      src/map/type.ts
  8. 7
      src/store/actions/index.ts
  9. 7
      src/store/reducers/map/index.ts

1
src/map/MapEditor.ts

@ -171,6 +171,7 @@ export class MapEditor extends Emitter implements IMapEditor {
this.map.remove(target); this.map.remove(target);
delete this.overlayMap[id]; delete this.overlayMap[id];
}); });
this.selectedIds = [];
} }
finishEditOverlay() { finishEditOverlay() {

2
src/map/editors/BaseOverlayEditor.ts

@ -1,5 +1,5 @@
import { OverlayTypes } from "@types"; import { OverlayTypes } from "@types";
import { IOverlay } from "../../store/type"; import { IOverlay } from "../type";
export abstract class BaseOverlayEditor<T extends AMap.BaseEditor> { export abstract class BaseOverlayEditor<T extends AMap.BaseEditor> {
map: AMap.Map; map: AMap.Map;

2
src/map/editors/CircleEditor.ts

@ -1,5 +1,5 @@
import { OverlayTypes } from "@types"; import { OverlayTypes } from "@types";
import { IOverlay } from "@store"; import { IOverlay } from "../type";
import { BaseOverlayEditor } from "./BaseOverlayEditor"; import { BaseOverlayEditor } from "./BaseOverlayEditor";
export class CircleEditor extends BaseOverlayEditor<AMap.CircleEditor> { export class CircleEditor extends BaseOverlayEditor<AMap.CircleEditor> {

2
src/map/editors/PolygonEditor.ts

@ -1,5 +1,5 @@
import { OverlayTypes } from "@types"; import { OverlayTypes } from "@types";
import { IOverlay } from "../../store/type"; import { IOverlay } from "../type";
import { BaseOverlayEditor } from "./BaseOverlayEditor"; import { BaseOverlayEditor } from "./BaseOverlayEditor";
export class PolygonEditor extends BaseOverlayEditor<AMap.PolygonEditor> { export class PolygonEditor extends BaseOverlayEditor<AMap.PolygonEditor> {

2
src/map/editors/PolylineEditor.ts

@ -1,5 +1,5 @@
import { OverlayTypes } from "@types"; import { OverlayTypes } from "@types";
import { IOverlay } from "@store"; import { IOverlay } from "../type";
import { BaseOverlayEditor } from "./BaseOverlayEditor"; import { BaseOverlayEditor } from "./BaseOverlayEditor";
export class PolylineEditor extends BaseOverlayEditor<AMap.PolylineEditor> { export class PolylineEditor extends BaseOverlayEditor<AMap.PolylineEditor> {

2
src/map/editors/RectangleEditor.ts

@ -1,5 +1,5 @@
import { OverlayTypes } from "@types"; import { OverlayTypes } from "@types";
import { IOverlay } from "../../store/type"; import { IOverlay } from "../type";
import { BaseOverlayEditor } from "./BaseOverlayEditor"; import { BaseOverlayEditor } from "./BaseOverlayEditor";
export class RectangleEditor extends BaseOverlayEditor<AMap.RectangleEditor> { export class RectangleEditor extends BaseOverlayEditor<AMap.RectangleEditor> {

1
src/map/type.ts

@ -7,6 +7,7 @@ export interface IMapEditor {
importProject(options: IMapOptions): void; importProject(options: IMapOptions): void;
importGeoJSON(geojson: GeoJSON.FeatureCollection): void; importGeoJSON(geojson: GeoJSON.FeatureCollection): void;
selectOverlays(ids?: string[]): void; selectOverlays(ids?: string[]): void;
deleteOverlays(): void;
} }
export interface IOverlay { export interface IOverlay {

7
src/store/actions/index.ts

@ -73,12 +73,13 @@ export class EditorAction {
} }
deleteOverlays() { deleteOverlays() {
const { selectedIds } = this.mapOptions; const { selectedIds } = this.store.getState();
if (selectedIds?.length == 0) return; if (selectedIds?.length === 0) return;
Modal.confirm({ Modal.confirm({
title: "确定删除覆盖物吗?", title: "确定删除覆盖物吗?",
onOk: () => { onOk: () => {
// this.store.dispatch(EditorAction.deleteOverlays()); this.mapEditor?.deleteOverlays();
this.store.dispatch(StoreAction.deleteOverlays());
}, },
}); });
} }

7
src/store/reducers/map/index.ts

@ -12,18 +12,15 @@ export function createOverlay(state = initState, payload: OverlayTypes) {
} }
export function deleteOverlays(state = initState, payload: any) { export function deleteOverlays(state = initState, payload: any) {
const { selectedIds } = state.map; const { selectedIds } = state;
const [id] = selectedIds!; const [id] = selectedIds!;
const filterFunc = (overlay: IOverlay) => overlay.id !== id; const filterFunc = (overlay: IOverlay) => overlay.id !== id;
return produce(state, (draft) => { return produce(state, (draft) => {
// draft.map.status = Status.CreateOverlay;
// draft.map.command = Command.DeleteOverlays;
draft.map.rectangles = draft.map.rectangles.filter(filterFunc); draft.map.rectangles = draft.map.rectangles.filter(filterFunc);
draft.map.polygons = draft.map.polygons.filter(filterFunc); draft.map.polygons = draft.map.polygons.filter(filterFunc);
draft.map.polylines = draft.map.polylines.filter(filterFunc); draft.map.polylines = draft.map.polylines.filter(filterFunc);
draft.map.circles = draft.map.circles.filter(filterFunc); draft.map.circles = draft.map.circles.filter(filterFunc);
draft.map.selectedIds = []; draft.selectedIds = [];
// draft.map.overlayType = payload as OverlayTypes;
}); });
} }

Loading…
Cancel
Save