Cmen
3 years ago
16 changed files with 158 additions and 29 deletions
@ -0,0 +1,11 @@
|
||||
import { OverlayTypes } from "@types"; |
||||
import { BaseOverlayEditor } from "./BaseOverlayEditor"; |
||||
|
||||
export class CircleEditor extends BaseOverlayEditor<AMap.CircleEditor> { |
||||
getType(): OverlayTypes { |
||||
return OverlayTypes.Circle; |
||||
} |
||||
initEditor(map: AMap.Map) { |
||||
return new AMap.CircleEditor(this.map); |
||||
} |
||||
} |
@ -0,0 +1,11 @@
|
||||
import { OverlayTypes } from "@types"; |
||||
import { BaseOverlayEditor } from "./BaseOverlayEditor"; |
||||
|
||||
export class PolygonEditor extends BaseOverlayEditor<AMap.PolygonEditor> { |
||||
getType(): OverlayTypes { |
||||
return OverlayTypes.Polygon; |
||||
} |
||||
initEditor(map: AMap.Map) { |
||||
return new AMap.PolygonEditor(map); |
||||
} |
||||
} |
@ -0,0 +1,12 @@
|
||||
import { OverlayTypes } from "@types"; |
||||
import { BaseOverlayEditor } from "./BaseOverlayEditor"; |
||||
|
||||
export class PolylineEditor extends BaseOverlayEditor<AMap.PolylineEditor> { |
||||
initEditor(map: AMap.Map) { |
||||
return new AMap.PolylineEditor(this.map); |
||||
} |
||||
|
||||
getType(): OverlayTypes { |
||||
return OverlayTypes.Polyline; |
||||
} |
||||
} |
@ -1,7 +1,12 @@
|
||||
import { BaseLayerEditor } from "./BaseLayerEditor"; |
||||
import { OverlayTypes } from "@types"; |
||||
import { BaseOverlayEditor } from "./BaseOverlayEditor"; |
||||
|
||||
export class RectangleEditor extends BaseLayerEditor<AMap.PolygonEditor> { |
||||
export class RectangleEditor extends BaseOverlayEditor<AMap.RectangleEditor> { |
||||
initEditor(map: AMap.Map) { |
||||
return new AMap.RectangleEditor(this.map); |
||||
} |
||||
|
||||
getType(): OverlayTypes { |
||||
return OverlayTypes.Rectangle; |
||||
} |
||||
} |
||||
|
@ -1,2 +1,5 @@
|
||||
export * from "./BaseLayerEditor"; |
||||
export * from "./BaseOverlayEditor"; |
||||
export * from "./RectangleEditor"; |
||||
export * from "./PolygonEditor"; |
||||
export * from "./CircleEditor"; |
||||
export * from "./PolylineEditor"; |
||||
|
@ -1,21 +1,38 @@
|
||||
import produce from "immer"; |
||||
import { initState } from "../../initState"; |
||||
import { IOverlay } from "@store"; |
||||
import { OverlayTypes } from "@types"; |
||||
|
||||
const OverlayNamePrefixs: Record<OverlayTypes, string> = { |
||||
[OverlayTypes.Rectangle]: "矩形", |
||||
[OverlayTypes.Polygon]: "多边形", |
||||
[OverlayTypes.Polyline]: "多段线", |
||||
[OverlayTypes.Circle]: "圆形", |
||||
}; |
||||
|
||||
export function createOverlay(state = initState, payload: any) { |
||||
return produce(state, (draft) => { |
||||
draft.map.status = "createOverlay"; |
||||
draft.map.overlayType = payload as string; |
||||
draft.map.overlayType = payload as OverlayTypes; |
||||
}); |
||||
} |
||||
|
||||
export function finishCreateOverlay(state = initState, payload: any) { |
||||
return produce(state, (draft) => { |
||||
const overlay = payload as IOverlay; |
||||
const { type } = overlay; |
||||
// todo: uniqueName.
|
||||
overlay.name = "矩形" + overlay.id; |
||||
overlay.name = OverlayNamePrefixs[type] + overlay.id; |
||||
draft.map.status = ""; |
||||
draft.map.overlayType = ""; |
||||
draft.map.rectangles = state.map.rectangles.concat([overlay]); |
||||
draft.map.overlayType = null; |
||||
(type === OverlayTypes.Rectangle |
||||
? draft.map.rectangles |
||||
: type === OverlayTypes.Circle |
||||
? draft.map.circles |
||||
: type === OverlayTypes.Polygon |
||||
? draft.map.polygons |
||||
: draft.map.polylines |
||||
).push(overlay); |
||||
// draft.map.rectangles = state.map.rectangles.concat([overlay]);
|
||||
}); |
||||
} |
||||
|
@ -1,3 +1,3 @@
|
||||
import { editorAction, IEditorState } from "@store"; |
||||
import { IEditorState } from "@store"; |
||||
|
||||
export const mapStateSelector = (state: IEditorState) => state.map; |
||||
|
@ -1,3 +1,10 @@
|
||||
export enum EventTypes { |
||||
FinishCreateOverlay = "finishCreateOverlay", |
||||
} |
||||
|
||||
export enum OverlayTypes { |
||||
Rectangle = "rectangle", |
||||
Polygon = "polygon", |
||||
Polyline = "polyline", |
||||
Circle = "circle", |
||||
} |
||||
|
Loading…
Reference in new issue