|
|
@ -1,19 +1,35 @@ |
|
|
|
import Emitter from "@finevis/emitter"; |
|
|
|
import Emitter from "@finevis/emitter"; |
|
|
|
import "../types"; |
|
|
|
import "@amap/amap-jsapi-types"; |
|
|
|
|
|
|
|
|
|
|
|
import { IMapState } from "@store"; |
|
|
|
import { IMapState } from "@store"; |
|
|
|
import { RectangleEditor } from "./editors"; |
|
|
|
import { |
|
|
|
|
|
|
|
BaseOverlayEditor, |
|
|
|
|
|
|
|
RectangleEditor, |
|
|
|
|
|
|
|
PolygonEditor, |
|
|
|
|
|
|
|
PolylineEditor, |
|
|
|
|
|
|
|
CircleEditor, |
|
|
|
|
|
|
|
} from "./editors"; |
|
|
|
|
|
|
|
|
|
|
|
import "@amap/amap-jsapi-types"; |
|
|
|
|
|
|
|
import { registerHotkey } from "../utils/hotkeys"; |
|
|
|
import { registerHotkey } from "../utils/hotkeys"; |
|
|
|
import { EventTypes } from "../types/enum"; |
|
|
|
import { EventTypes } from "../types/enum"; |
|
|
|
|
|
|
|
|
|
|
|
let uuid = 0; |
|
|
|
let uuid = 0; |
|
|
|
const getUuid = () => ++uuid; |
|
|
|
const getUuid = () => ++uuid; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type AMapOverlayEditor = |
|
|
|
|
|
|
|
| AMap.RectangleEditor |
|
|
|
|
|
|
|
| AMap.PolygonEditor |
|
|
|
|
|
|
|
| AMap.PolylineEditor |
|
|
|
|
|
|
|
| AMap.CircleEditor; |
|
|
|
|
|
|
|
|
|
|
|
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 rectangleEditor: RectangleEditor | undefined; |
|
|
|
private overlayEditors: BaseOverlayEditor<AMapOverlayEditor>[] = []; |
|
|
|
private overlayMap: Record<number, AMap.MapOverlay> = {}; |
|
|
|
private overlayMap: Record<number, AMap.MapOverlay> = {}; |
|
|
|
|
|
|
|
private _currentOverlayEditor: |
|
|
|
|
|
|
|
| BaseOverlayEditor<AMapOverlayEditor> |
|
|
|
|
|
|
|
| undefined; |
|
|
|
constructor(dom: HTMLDivElement) { |
|
|
|
constructor(dom: HTMLDivElement) { |
|
|
|
super(); |
|
|
|
super(); |
|
|
|
this.dom = dom; |
|
|
|
this.dom = dom; |
|
|
@ -31,6 +47,7 @@ export class MapEditor extends Emitter { |
|
|
|
"AMap.RectangleEditor", |
|
|
|
"AMap.RectangleEditor", |
|
|
|
"AMap.PolylineEditor", |
|
|
|
"AMap.PolylineEditor", |
|
|
|
"AMap.PolygonEditor", |
|
|
|
"AMap.PolygonEditor", |
|
|
|
|
|
|
|
"AMap.CircleEditor", |
|
|
|
"AMap.PlaceSearch", |
|
|
|
"AMap.PlaceSearch", |
|
|
|
"AMap.AutoComplete", |
|
|
|
"AMap.AutoComplete", |
|
|
|
], |
|
|
|
], |
|
|
@ -41,21 +58,26 @@ export class MapEditor extends Emitter { |
|
|
|
registerHotkey(" ", { callback: this.finishCreateOverlay.bind(this) }); |
|
|
|
registerHotkey(" ", { callback: this.finishCreateOverlay.bind(this) }); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
update(state: IMapState) { |
|
|
|
update(mapState: IMapState) { |
|
|
|
if (state.status === "createOverlay") { |
|
|
|
const { status, overlayType } = mapState; |
|
|
|
this.rectangleEditor?.create(); |
|
|
|
if (status === "createOverlay") { |
|
|
|
|
|
|
|
this._currentOverlayEditor = this.overlayEditors.find( |
|
|
|
|
|
|
|
(editor) => editor.getType() === overlayType |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
this._currentOverlayEditor?.create(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
finishCreateOverlay() { |
|
|
|
finishCreateOverlay() { |
|
|
|
const target = this.rectangleEditor?.finish(); |
|
|
|
if (this._currentOverlayEditor == null) return; |
|
|
|
|
|
|
|
const target = this._currentOverlayEditor.finish(); |
|
|
|
let evt: any = null; |
|
|
|
let evt: any = null; |
|
|
|
if (target != null) { |
|
|
|
if (target != null) { |
|
|
|
const id = getUuid(); |
|
|
|
const id = getUuid(); |
|
|
|
this.overlayMap[id] = target; |
|
|
|
this.overlayMap[id] = target; |
|
|
|
evt = { |
|
|
|
evt = { |
|
|
|
id, |
|
|
|
id, |
|
|
|
type: "rectangle", |
|
|
|
type: this._currentOverlayEditor.getType(), |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
this.emit(EventTypes.FinishCreateOverlay, evt); |
|
|
|
this.emit(EventTypes.FinishCreateOverlay, evt); |
|
|
@ -63,6 +85,11 @@ export class MapEditor extends Emitter { |
|
|
|
|
|
|
|
|
|
|
|
initEditors() { |
|
|
|
initEditors() { |
|
|
|
const { map } = this; |
|
|
|
const { map } = this; |
|
|
|
this.rectangleEditor = new RectangleEditor(map); |
|
|
|
this.overlayEditors = [ |
|
|
|
|
|
|
|
new RectangleEditor(map), |
|
|
|
|
|
|
|
new PolygonEditor(map), |
|
|
|
|
|
|
|
new PolylineEditor(map), |
|
|
|
|
|
|
|
new CircleEditor(map), |
|
|
|
|
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|