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. 8
      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[]) {
if (!ids?.length) return;
this.selectedIds.forEach((id) => {
this.selectedIds?.forEach((id) => {
const { target, type } = this.overlayMap[id];
target.setOptions(getOverlayOptions(type));
});
if (ids == null) return;
this.selectedIds = ids;
ids.forEach((id) => {
const { target } = this.overlayMap[id];

2
src/map/type.ts

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

2
src/store/actions/StoreAction.ts

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

8
src/store/actions/index.ts

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

8
src/store/reducers/index.ts

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

Loading…
Cancel
Save