|
|
@ -157,23 +157,21 @@ export class MapEditor extends Emitter implements IMapEditor { |
|
|
|
|
|
|
|
|
|
|
|
createOverlay(type: OverlayTypes) { |
|
|
|
createOverlay(type: OverlayTypes) { |
|
|
|
this.finishEditOverlay(); |
|
|
|
this.finishEditOverlay(); |
|
|
|
this.currentOverlayEditor = this.getEditorByType(type!); |
|
|
|
if (type === OverlayTypes.Point) { |
|
|
|
this.currentOverlayEditor?.create(); |
|
|
|
this._createMarker(); |
|
|
|
this.editorStatus = "creating"; |
|
|
|
} else { |
|
|
|
|
|
|
|
this.currentOverlayEditor = this.getEditorByType(type!); |
|
|
|
|
|
|
|
this.currentOverlayEditor?.create(); |
|
|
|
|
|
|
|
this.editorStatus = "creating"; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
selectOverlays(ids?: string[]) { |
|
|
|
selectOverlays(ids?: string[]) { |
|
|
|
this.finishEditOverlay(); |
|
|
|
this.finishEditOverlay(); |
|
|
|
this.selectedIds?.forEach((id) => { |
|
|
|
this.selectedIds?.forEach((id) => this._updateOverlayProps(id)); |
|
|
|
const { target, type } = this.overlayMap[id]; |
|
|
|
|
|
|
|
target.setOptions(getOverlayOptions(type)); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
if (ids == null) return; |
|
|
|
if (ids == null) return; |
|
|
|
this.selectedIds = ids; |
|
|
|
this.selectedIds = ids; |
|
|
|
ids.forEach((id) => { |
|
|
|
ids.forEach((id) => this._updateOverlayProps(id, true)); |
|
|
|
const { target } = this.overlayMap[id]; |
|
|
|
|
|
|
|
target.setOptions(SelectedOptions); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
deleteOverlays() { |
|
|
|
deleteOverlays() { |
|
|
@ -199,9 +197,7 @@ export class MapEditor extends Emitter implements IMapEditor { |
|
|
|
let id = getUID(); |
|
|
|
let id = getUID(); |
|
|
|
if (isCreatingOverlay) { |
|
|
|
if (isCreatingOverlay) { |
|
|
|
this._addOverlay(id, { type, target }); |
|
|
|
this._addOverlay(id, { type, target }); |
|
|
|
target.setOptions( |
|
|
|
this._updateOverlayProps(id); |
|
|
|
type === OverlayTypes.Polyline ? PolylineOptions : PolygonOptions |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
id = this.selectedIds[0]; |
|
|
|
id = this.selectedIds[0]; |
|
|
|
} |
|
|
|
} |
|
|
@ -237,17 +233,61 @@ export class MapEditor extends Emitter implements IMapEditor { |
|
|
|
this.placeSearch?.search(item.name); |
|
|
|
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) { |
|
|
|
_buildFromOverlay(overlay: IOverlay) { |
|
|
|
const { type, id } = overlay; |
|
|
|
const { type, id } = overlay; |
|
|
|
const editor = this.overlayEditors.find( |
|
|
|
let target: AMap.MapOverlay; |
|
|
|
(editor) => editor.getType() === type |
|
|
|
if (type === OverlayTypes.Point) { |
|
|
|
)!; |
|
|
|
target = this._buildMarker(overlay.lngLat!); |
|
|
|
const target = editor.build(overlay); |
|
|
|
} else { |
|
|
|
|
|
|
|
const editor = this.overlayEditors.find( |
|
|
|
|
|
|
|
(editor) => editor.getType() === type |
|
|
|
|
|
|
|
)!; |
|
|
|
|
|
|
|
target = editor.build(overlay); |
|
|
|
|
|
|
|
this.map.add(target); |
|
|
|
|
|
|
|
} |
|
|
|
this._addOverlay(id, { type, target }); |
|
|
|
this._addOverlay(id, { type, target }); |
|
|
|
target.setOptions( |
|
|
|
this._updateOverlayProps(id); |
|
|
|
type === OverlayTypes.Polyline ? PolylineOptions : PolygonOptions |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
this.map.add(target); |
|
|
|
|
|
|
|
if (overlay.backgroundImage) { |
|
|
|
if (overlay.backgroundImage) { |
|
|
|
this.updateOverlayBackground(id, overlay.backgroundImage); |
|
|
|
this.updateOverlayBackground(id, overlay.backgroundImage); |
|
|
|
} |
|
|
|
} |
|
|
@ -257,7 +297,11 @@ export class MapEditor extends Emitter implements IMapEditor { |
|
|
|
if (this.overlayMap[id] == null) return; |
|
|
|
if (this.overlayMap[id] == null) return; |
|
|
|
const { type, target } = this.overlayMap[id]; |
|
|
|
const { type, target } = this.overlayMap[id]; |
|
|
|
const evt: any = { id, type }; |
|
|
|
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 circle = target as AMap.Circle; |
|
|
|
const { lng, lat } = circle.getCenter(); |
|
|
|
const { lng, lat } = circle.getCenter(); |
|
|
|
evt.lngLat = [lng, lat]; |
|
|
|
evt.lngLat = [lng, lat]; |
|
|
@ -269,21 +313,12 @@ export class MapEditor extends Emitter implements IMapEditor { |
|
|
|
this.updateOverlayBackground(id); |
|
|
|
this.updateOverlayBackground(id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
editSelectedOverlay() { |
|
|
|
_onOverlayDragEnd(id: string) { |
|
|
|
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) { |
|
|
|
|
|
|
|
this._updateOverlay(id); |
|
|
|
this._updateOverlay(id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_addOverlay(id: string, overlay: OverlayTemp) { |
|
|
|
_addOverlay(id: string, overlay: OverlayTemp) { |
|
|
|
this.overlayMap[id] = overlay; |
|
|
|
this.overlayMap[id] = overlay; |
|
|
|
overlay.target.on("dragend", () => this.onOverlayDragEnd(id)); |
|
|
|
overlay.target.on("dragend", () => this._onOverlayDragEnd(id)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|