|
|
@ -16,7 +16,6 @@ import { IMapOptions, IMapEditor } from "./type"; |
|
|
|
import { PolygonOptions, PolylineOptions, SelectedOptions } from "./constants"; |
|
|
|
import { PolygonOptions, PolylineOptions, SelectedOptions } from "./constants"; |
|
|
|
|
|
|
|
|
|
|
|
import { EventTypes, OverlayTypes } from "../types/enum"; |
|
|
|
import { EventTypes, OverlayTypes } from "../types/enum"; |
|
|
|
import { Position } from "geojson"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type AMapOverlayEditor = |
|
|
|
type AMapOverlayEditor = |
|
|
|
| AMap.RectangleEditor |
|
|
|
| AMap.RectangleEditor |
|
|
@ -95,16 +94,22 @@ export class MapEditor extends Emitter implements IMapEditor { |
|
|
|
getEditorByType(overlayType: OverlayTypes) { |
|
|
|
getEditorByType(overlayType: OverlayTypes) { |
|
|
|
return this.overlayEditors.find( |
|
|
|
return this.overlayEditors.find( |
|
|
|
(editor) => editor.getType() === overlayType |
|
|
|
(editor) => editor.getType() === overlayType |
|
|
|
); |
|
|
|
)!; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
importProject(options: IMapOptions) { |
|
|
|
importProject(options: IMapOptions) { |
|
|
|
this.clearOverlays(); |
|
|
|
this.clearOverlays(); |
|
|
|
const { rectangles, polygons, polylines, circles } = options; |
|
|
|
const { overlays } = options; |
|
|
|
const rectangleEditor = this.getEditorByType(OverlayTypes.Rectangle); |
|
|
|
|
|
|
|
const polygonEditor = this.getEditorByType(OverlayTypes.Polygon); |
|
|
|
const overlayEditors: Record< |
|
|
|
const polylineEditor = this.getEditorByType(OverlayTypes.Polyline); |
|
|
|
OverlayTypes, |
|
|
|
const circleEditor = this.getEditorByType(OverlayTypes.Circle); |
|
|
|
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) { |
|
|
|
if (options.center) { |
|
|
|
const [lng, lat] = options.center; |
|
|
|
const [lng, lat] = options.center; |
|
|
@ -114,11 +119,9 @@ export class MapEditor extends Emitter implements IMapEditor { |
|
|
|
this.map.setZoom(options.zoom); |
|
|
|
this.map.setZoom(options.zoom); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const addOverlay = ( |
|
|
|
overlays.forEach((overlay) => { |
|
|
|
id: string, |
|
|
|
const { type, id } = overlay; |
|
|
|
target: AMap.MapOverlay, |
|
|
|
const target = overlayEditors[type].build(overlay); |
|
|
|
type: OverlayTypes |
|
|
|
|
|
|
|
) => { |
|
|
|
|
|
|
|
this.overlayMap[id] = { |
|
|
|
this.overlayMap[id] = { |
|
|
|
type, |
|
|
|
type, |
|
|
|
target, |
|
|
|
target, |
|
|
@ -127,28 +130,7 @@ export class MapEditor extends Emitter implements IMapEditor { |
|
|
|
type === OverlayTypes.Polyline ? PolylineOptions : PolygonOptions |
|
|
|
type === OverlayTypes.Polyline ? PolylineOptions : PolygonOptions |
|
|
|
); |
|
|
|
); |
|
|
|
this.map.add(target); |
|
|
|
this.map.add(target); |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
rectangles.forEach((rect) => |
|
|
|
|
|
|
|
addOverlay(rect.id, rectangleEditor!.build(rect), OverlayTypes.Rectangle) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
polygons.forEach((polygon) => |
|
|
|
|
|
|
|
addOverlay( |
|
|
|
|
|
|
|
polygon.id, |
|
|
|
|
|
|
|
polygonEditor!.build(polygon), |
|
|
|
|
|
|
|
OverlayTypes.Polygon |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
polylines.forEach((polyline) => |
|
|
|
|
|
|
|
addOverlay( |
|
|
|
|
|
|
|
polyline.id, |
|
|
|
|
|
|
|
polylineEditor!.build(polyline), |
|
|
|
|
|
|
|
OverlayTypes.Polyline |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
circles.forEach((circle) => |
|
|
|
|
|
|
|
addOverlay(circle.id, circleEditor!.build(circle), OverlayTypes.Circle) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
importGeoJSON(geojson: GeoJSON.FeatureCollection): void { |
|
|
|
importGeoJSON(geojson: GeoJSON.FeatureCollection): void { |
|
|
|