Browse Source

支持取消选中

master
Cmen 3 years ago
parent
commit
6114b2aa5a
  1. 4
      src/map/MapEditor.ts
  2. 2
      src/map/type.ts
  3. 2
      src/store/actions/StoreAction.ts
  4. 12
      src/store/actions/index.ts
  5. 8
      src/store/reducers/index.ts

4
src/map/MapEditor.ts

@ -152,11 +152,11 @@ export class MapEditor extends Emitter implements IMapEditor {
} }
selectOverlays(ids?: string[]) { selectOverlays(ids?: string[]) {
if (!ids?.length) return; this.selectedIds?.forEach((id) => {
this.selectedIds.forEach((id) => {
const { target, type } = this.overlayMap[id]; const { target, type } = this.overlayMap[id];
target.setOptions(getOverlayOptions(type)); target.setOptions(getOverlayOptions(type));
}); });
if (ids == null) return;
this.selectedIds = ids; this.selectedIds = ids;
ids.forEach((id) => { ids.forEach((id) => {
const { target } = this.overlayMap[id]; const { target } = this.overlayMap[id];

2
src/map/type.ts

@ -6,7 +6,7 @@ export interface IMapEditor {
createOverlay(type: OverlayTypes): void; createOverlay(type: OverlayTypes): void;
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;
} }
export interface IOverlay { export interface IOverlay {

2
src/store/actions/StoreAction.ts

@ -22,7 +22,7 @@ export const StoreAction = {
payload: overlay, payload: overlay,
}; };
}, },
selectOverlay(id: string) { selectOverlay(id?: string) {
return { return {
type: ActionTypes.SelectOverlay, type: ActionTypes.SelectOverlay,
payload: id, payload: id,

12
src/store/actions/index.ts

@ -7,7 +7,7 @@ import { getGeoJSON } from "../utils";
import { OverlayTypes, EventTypes } from "@types"; import { OverlayTypes, EventTypes } from "@types";
import { IOverlay, IMapOptions } from "@map"; import { IOverlay, IMapOptions } from "@map";
import { StoreAction } from "./StoreAction"; import { StoreAction } from "./StoreAction";
import { IStore, IEditorState } from "../type"; import { IStore } from "../type";
import { initState } from "../initState"; import { initState } from "../initState";
export { ActionTypes } from "./StoreAction"; export { ActionTypes } from "./StoreAction";
@ -89,8 +89,14 @@ export class EditorAction {
} }
selectOverlay(id: string) { selectOverlay(id: string) {
this.mapEditor?.selectOverlays([id]); const { selectedIds } = this.store.getState();
this.dispatch(StoreAction.selectOverlay(id)); if (selectedIds.indexOf(id) >= 0) {
this.mapEditor?.selectOverlays();
this.dispatch(StoreAction.selectOverlay());
} else {
this.mapEditor?.selectOverlays([id]);
this.dispatch(StoreAction.selectOverlay(id));
}
} }
saveProject() { saveProject() {

8
src/store/reducers/index.ts

@ -23,10 +23,12 @@ function replaceState(state = initState, payload: IEditorState) {
return payload; return payload;
} }
export function selectOverlay(state = initState, payload: any) { export function selectOverlay(state = initState, payload: string | undefined) {
const id = payload as string; // const id = payload as string;
// todo: 考虑支持多选
const ids = payload ? [payload] : [];
return produce(state, (draft) => { return produce(state, (draft) => {
draft.selectedIds = [id]; draft.selectedIds = ids;
}); });
} }

Loading…
Cancel
Save