Browse Source

refactor: 选中状态优化

master
Cmen 3 years ago
parent
commit
76e80c9d17
  1. BIN
      public/images/marker2.png
  2. 6
      src/map/MapEditor.ts
  3. 11
      src/store/actions/index.ts

BIN
public/images/marker2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

6
src/map/MapEditor.ts

@ -268,7 +268,11 @@ export class MapEditor extends Emitter implements IMapEditor {
_updateOverlayProps(id: string, selected = false) {
const { type, target } = this.getOverlay(id);
if (type === OverlayTypes.Point) {
target.setOptions({ draggable: selected });
const marker = target as AMap.Marker;
marker.setOptions({
draggable: selected,
});
marker.setIcon(`/images/marker${selected ? "2" : ""}.png`);
} else {
target.setOptions(selected ? SelectedOptions : getOverlayOptions(type));
}

11
src/store/actions/index.ts

@ -52,7 +52,8 @@ export class EditorAction {
// 创建覆盖物结束
this.mapEditor.on(EventTypes.FinishEditOverlay, (overlay: IOverlay) => {
this.dispatch(StoreAction.finishEditOverlay(overlay));
this.selectOverlay(overlay.id);
// 创建或者编辑结束继续选中, 编辑选中保留不取消选中
this.selectOverlay(overlay.id, false);
});
}
@ -96,11 +97,13 @@ export class EditorAction {
});
}
selectOverlay(id: string) {
selectOverlay(id: string, reset = true) {
const { selectedIds } = this.store.getState();
if (selectedIds.indexOf(id) >= 0) {
this.mapEditor?.selectOverlays();
this.dispatch(StoreAction.selectOverlay());
if (reset) {
this.mapEditor?.selectOverlays();
this.dispatch(StoreAction.selectOverlay());
}
} else {
this.mapEditor?.selectOverlays([id]);
this.dispatch(StoreAction.selectOverlay(id));

Loading…
Cancel
Save