|
|
|
@ -157,23 +157,21 @@ export class MapEditor extends Emitter implements IMapEditor {
|
|
|
|
|
|
|
|
|
|
createOverlay(type: OverlayTypes) { |
|
|
|
|
this.finishEditOverlay(); |
|
|
|
|
if (type === OverlayTypes.Point) { |
|
|
|
|
this._createMarker(); |
|
|
|
|
} else { |
|
|
|
|
this.currentOverlayEditor = this.getEditorByType(type!); |
|
|
|
|
this.currentOverlayEditor?.create(); |
|
|
|
|
this.editorStatus = "creating"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
selectOverlays(ids?: string[]) { |
|
|
|
|
this.finishEditOverlay(); |
|
|
|
|
this.selectedIds?.forEach((id) => { |
|
|
|
|
const { target, type } = this.overlayMap[id]; |
|
|
|
|
target.setOptions(getOverlayOptions(type)); |
|
|
|
|
}); |
|
|
|
|
this.selectedIds?.forEach((id) => this._updateOverlayProps(id)); |
|
|
|
|
if (ids == null) return; |
|
|
|
|
this.selectedIds = ids; |
|
|
|
|
ids.forEach((id) => { |
|
|
|
|
const { target } = this.overlayMap[id]; |
|
|
|
|
target.setOptions(SelectedOptions); |
|
|
|
|
}); |
|
|
|
|
ids.forEach((id) => this._updateOverlayProps(id, true)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
deleteOverlays() { |
|
|
|
@ -199,9 +197,7 @@ export class MapEditor extends Emitter implements IMapEditor {
|
|
|
|
|
let id = getUID(); |
|
|
|
|
if (isCreatingOverlay) { |
|
|
|
|
this._addOverlay(id, { type, target }); |
|
|
|
|
target.setOptions( |
|
|
|
|
type === OverlayTypes.Polyline ? PolylineOptions : PolygonOptions |
|
|
|
|
); |
|
|
|
|
this._updateOverlayProps(id); |
|
|
|
|
} else { |
|
|
|
|
id = this.selectedIds[0]; |
|
|
|
|
} |
|
|
|
@ -237,17 +233,61 @@ export class MapEditor extends Emitter implements IMapEditor {
|
|
|
|
|
this.placeSearch?.search(item.name); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
editSelectedOverlay() { |
|
|
|
|
if (this.selectedIds.length !== 1) return; |
|
|
|
|
const [id] = this.selectedIds; |
|
|
|
|
const { target, type } = this.overlayMap[id]; |
|
|
|
|
this.currentOverlayEditor = this.getEditorByType(type); |
|
|
|
|
this.currentOverlayEditor?.edit(target); |
|
|
|
|
this.editorStatus = "editing"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getOverlay(id: string) { |
|
|
|
|
return this.overlayMap[id]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_createMarker() { |
|
|
|
|
const id = getUID(); |
|
|
|
|
const marker = this._buildMarker(this.getCenter()); |
|
|
|
|
this._addOverlay(id, { type: OverlayTypes.Point, target: marker }); |
|
|
|
|
this._updateOverlay(id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_buildMarker(position: number[]) { |
|
|
|
|
const marker = new AMap.Marker({ |
|
|
|
|
icon: "/images/marker.png", |
|
|
|
|
position: position as [number, number], |
|
|
|
|
anchor: "bottom-center", |
|
|
|
|
offset: new AMap.Pixel(-13, -30), |
|
|
|
|
}); |
|
|
|
|
marker.setMap(this.map); |
|
|
|
|
this.map.add(marker); |
|
|
|
|
return marker; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_updateOverlayProps(id: string, selected = false) { |
|
|
|
|
const { type, target } = this.getOverlay(id); |
|
|
|
|
if (type === OverlayTypes.Point) { |
|
|
|
|
target.setOptions({ draggable: selected }); |
|
|
|
|
} else { |
|
|
|
|
target.setOptions(selected ? SelectedOptions : getOverlayOptions(type)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_buildFromOverlay(overlay: IOverlay) { |
|
|
|
|
const { type, id } = overlay; |
|
|
|
|
let target: AMap.MapOverlay; |
|
|
|
|
if (type === OverlayTypes.Point) { |
|
|
|
|
target = this._buildMarker(overlay.lngLat!); |
|
|
|
|
} else { |
|
|
|
|
const editor = this.overlayEditors.find( |
|
|
|
|
(editor) => editor.getType() === type |
|
|
|
|
)!; |
|
|
|
|
const target = editor.build(overlay); |
|
|
|
|
this._addOverlay(id, { type, target }); |
|
|
|
|
target.setOptions( |
|
|
|
|
type === OverlayTypes.Polyline ? PolylineOptions : PolygonOptions |
|
|
|
|
); |
|
|
|
|
target = editor.build(overlay); |
|
|
|
|
this.map.add(target); |
|
|
|
|
} |
|
|
|
|
this._addOverlay(id, { type, target }); |
|
|
|
|
this._updateOverlayProps(id); |
|
|
|
|
if (overlay.backgroundImage) { |
|
|
|
|
this.updateOverlayBackground(id, overlay.backgroundImage); |
|
|
|
|
} |
|
|
|
@ -257,7 +297,11 @@ export class MapEditor extends Emitter implements IMapEditor {
|
|
|
|
|
if (this.overlayMap[id] == null) return; |
|
|
|
|
const { type, target } = this.overlayMap[id]; |
|
|
|
|
const evt: any = { id, type }; |
|
|
|
|
if (type === OverlayTypes.Circle) { |
|
|
|
|
if (type === OverlayTypes.Point) { |
|
|
|
|
const marker = target as AMap.Marker; |
|
|
|
|
const { lng, lat } = marker.getPosition()!; |
|
|
|
|
evt.lngLat = [lng, lat]; |
|
|
|
|
} else if (type === OverlayTypes.Circle) { |
|
|
|
|
const circle = target as AMap.Circle; |
|
|
|
|
const { lng, lat } = circle.getCenter(); |
|
|
|
|
evt.lngLat = [lng, lat]; |
|
|
|
@ -269,21 +313,12 @@ export class MapEditor extends Emitter implements IMapEditor {
|
|
|
|
|
this.updateOverlayBackground(id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
editSelectedOverlay() { |
|
|
|
|
if (this.selectedIds.length !== 1) return; |
|
|
|
|
const [id] = this.selectedIds; |
|
|
|
|
const { target, type } = this.overlayMap[id]; |
|
|
|
|
this.currentOverlayEditor = this.getEditorByType(type); |
|
|
|
|
this.currentOverlayEditor?.edit(target); |
|
|
|
|
this.editorStatus = "editing"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onOverlayDragEnd(id: string) { |
|
|
|
|
_onOverlayDragEnd(id: string) { |
|
|
|
|
this._updateOverlay(id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_addOverlay(id: string, overlay: OverlayTemp) { |
|
|
|
|
this.overlayMap[id] = overlay; |
|
|
|
|
overlay.target.on("dragend", () => this.onOverlayDragEnd(id)); |
|
|
|
|
overlay.target.on("dragend", () => this._onOverlayDragEnd(id)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|