|
|
|
@ -11,7 +11,7 @@ import {
|
|
|
|
|
CircleEditor, |
|
|
|
|
} from "./editors"; |
|
|
|
|
|
|
|
|
|
import { IMapOptions, IMapEditor } from "./type"; |
|
|
|
|
import { IMapOptions, IMapEditor, IOverlay } from "./type"; |
|
|
|
|
|
|
|
|
|
import { PolygonOptions, PolylineOptions, SelectedOptions } from "./constants"; |
|
|
|
|
|
|
|
|
@ -102,16 +102,6 @@ export class MapEditor extends Emitter implements IMapEditor {
|
|
|
|
|
this.clearOverlays(); |
|
|
|
|
const { overlays } = options; |
|
|
|
|
|
|
|
|
|
const overlayEditors: Record< |
|
|
|
|
OverlayTypes, |
|
|
|
|
BaseOverlayEditor<AMapOverlayEditor> |
|
|
|
|
> = { |
|
|
|
|
[OverlayTypes.Rectangle]: this.getEditorByType(OverlayTypes.Rectangle), |
|
|
|
|
[OverlayTypes.Polygon]: this.getEditorByType(OverlayTypes.Polygon), |
|
|
|
|
[OverlayTypes.Polyline]: this.getEditorByType(OverlayTypes.Polyline), |
|
|
|
|
[OverlayTypes.Circle]: this.getEditorByType(OverlayTypes.Circle), |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
if (options.center) { |
|
|
|
|
const [lng, lat] = options.center; |
|
|
|
|
this.map.setCenter(new AMap.LngLat(lng, lat)); |
|
|
|
@ -120,18 +110,7 @@ export class MapEditor extends Emitter implements IMapEditor {
|
|
|
|
|
this.map.setZoom(options.zoom); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
overlays.forEach((overlay) => { |
|
|
|
|
const { type, id } = overlay; |
|
|
|
|
const target = overlayEditors[type].build(overlay); |
|
|
|
|
this._addOverlay(id, { type, target }); |
|
|
|
|
target.setOptions( |
|
|
|
|
type === OverlayTypes.Polyline ? PolylineOptions : PolygonOptions |
|
|
|
|
); |
|
|
|
|
this.map.add(target); |
|
|
|
|
if (overlay.backgroundImage) { |
|
|
|
|
this.updateOverlayBackground(id, overlay.backgroundImage); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
overlays.forEach((overlay) => this._buildFromOverlay(overlay)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
importGeoJSON(geojson: GeoJSON.FeatureCollection): void { |
|
|
|
@ -225,6 +204,33 @@ export class MapEditor extends Emitter implements IMapEditor {
|
|
|
|
|
this.editorStatus = null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
copyOverlay(overlay: IOverlay) { |
|
|
|
|
const id = getUID(); |
|
|
|
|
const newOverlay = { |
|
|
|
|
...overlay, |
|
|
|
|
id, |
|
|
|
|
}; |
|
|
|
|
this._buildFromOverlay(newOverlay); |
|
|
|
|
this._updateOverlay(id); |
|
|
|
|
return id; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_buildFromOverlay(overlay: IOverlay) { |
|
|
|
|
const { type, id } = overlay; |
|
|
|
|
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 |
|
|
|
|
); |
|
|
|
|
this.map.add(target); |
|
|
|
|
if (overlay.backgroundImage) { |
|
|
|
|
this.updateOverlayBackground(id, overlay.backgroundImage); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_updateOverlay(id: string) { |
|
|
|
|
if (this.overlayMap[id] == null) return; |
|
|
|
|
const { type, target } = this.overlayMap[id]; |
|
|
|
|