|
|
@ -13,9 +13,9 @@ import { |
|
|
|
} from "./editors"; |
|
|
|
} from "./editors"; |
|
|
|
|
|
|
|
|
|
|
|
import { registerHotkey } from "../utils/hotkeys"; |
|
|
|
import { registerHotkey } from "../utils/hotkeys"; |
|
|
|
import { PolygonOptions, PolylineOptions } from "./constants"; |
|
|
|
import { PolygonOptions, PolylineOptions, SelectedOptions } from "./constants"; |
|
|
|
|
|
|
|
|
|
|
|
import { EventTypes, OverlayTypes } from "../types/enum"; |
|
|
|
import { Command, EventTypes, OverlayTypes } from "../types/enum"; |
|
|
|
|
|
|
|
|
|
|
|
let uuid = 0; |
|
|
|
let uuid = 0; |
|
|
|
const getUuid = () => ++uuid; |
|
|
|
const getUuid = () => ++uuid; |
|
|
@ -26,11 +26,16 @@ type AMapOverlayEditor = |
|
|
|
| AMap.PolylineEditor |
|
|
|
| AMap.PolylineEditor |
|
|
|
| AMap.CircleEditor; |
|
|
|
| AMap.CircleEditor; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type OverlayTemp = { |
|
|
|
|
|
|
|
type: OverlayTypes; |
|
|
|
|
|
|
|
target: AMap.MapOverlay; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export class MapEditor extends Emitter { |
|
|
|
export class MapEditor extends Emitter { |
|
|
|
dom: HTMLDivElement; |
|
|
|
dom: HTMLDivElement; |
|
|
|
private _map: AMap.Map | undefined; |
|
|
|
private _map: AMap.Map | undefined; |
|
|
|
private overlayEditors: BaseOverlayEditor<AMapOverlayEditor>[] = []; |
|
|
|
private overlayEditors: BaseOverlayEditor<AMapOverlayEditor>[] = []; |
|
|
|
private overlayMap: Record<number, AMap.MapOverlay> = {}; |
|
|
|
private overlayMap: Record<string, OverlayTemp> = {}; |
|
|
|
private _currentOverlayEditor: |
|
|
|
private _currentOverlayEditor: |
|
|
|
| BaseOverlayEditor<AMapOverlayEditor> |
|
|
|
| BaseOverlayEditor<AMapOverlayEditor> |
|
|
|
| undefined; |
|
|
|
| undefined; |
|
|
@ -63,14 +68,31 @@ export class MapEditor extends Emitter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
update(mapState: IMapState) { |
|
|
|
update(mapState: IMapState) { |
|
|
|
const { status, overlayType } = mapState; |
|
|
|
const { command } = mapState; |
|
|
|
if (status === "createOverlay") { |
|
|
|
switch (command) { |
|
|
|
|
|
|
|
case Command.CreateOverlay: |
|
|
|
|
|
|
|
this._createOverlay(mapState); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case Command.SelectOverlay: |
|
|
|
|
|
|
|
this._selectOverlays(mapState.selectedIds); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_createOverlay(mapState: IMapState) { |
|
|
|
|
|
|
|
const { overlayType } = mapState; |
|
|
|
this.finishCreateOverlay(); |
|
|
|
this.finishCreateOverlay(); |
|
|
|
this._currentOverlayEditor = this.overlayEditors.find( |
|
|
|
this._currentOverlayEditor = this.overlayEditors.find( |
|
|
|
(editor) => editor.getType() === overlayType |
|
|
|
(editor) => editor.getType() === overlayType |
|
|
|
); |
|
|
|
); |
|
|
|
this._currentOverlayEditor?.create(); |
|
|
|
this._currentOverlayEditor?.create(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_selectOverlays(ids?: string[]) { |
|
|
|
|
|
|
|
if (!ids?.length) return; |
|
|
|
|
|
|
|
ids.forEach((id) => { |
|
|
|
|
|
|
|
const { target } = this.overlayMap[id]; |
|
|
|
|
|
|
|
target.setOptions(SelectedOptions); |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
finishCreateOverlay() { |
|
|
|
finishCreateOverlay() { |
|
|
@ -79,7 +101,7 @@ export class MapEditor extends Emitter { |
|
|
|
if (target == null) return; |
|
|
|
if (target == null) return; |
|
|
|
const id = getUuid(); |
|
|
|
const id = getUuid(); |
|
|
|
const type = this._currentOverlayEditor.getType(); |
|
|
|
const type = this._currentOverlayEditor.getType(); |
|
|
|
this.overlayMap[id] = target; |
|
|
|
this.overlayMap[id] = { type, target }; |
|
|
|
const evt: any = { id, type }; |
|
|
|
const evt: any = { id, type }; |
|
|
|
if (type === OverlayTypes.Circle) { |
|
|
|
if (type === OverlayTypes.Circle) { |
|
|
|
const circle = target as AMap.Circle; |
|
|
|
const circle = target as AMap.Circle; |
|
|
|