From 1ca28f82b29d86027e706d9f828a04433fe91806 Mon Sep 17 00:00:00 2001 From: Cmen <1176967590@qq.com> Date: Sat, 12 Mar 2022 09:17:15 +0800 Subject: [PATCH] refactor: move overlayType to map --- src/editor/Catalog/index.tsx | 3 +-- src/editor/Plot/Tools/index.tsx | 3 ++- src/editor/Property/index.tsx | 4 +--- src/map/MapEditor.ts | 5 ++--- src/map/editors/BaseOverlayEditor.ts | 3 +-- src/map/editors/CircleEditor.ts | 3 +-- src/map/editors/PolygonEditor.ts | 3 +-- src/map/editors/PolylineEditor.ts | 3 +-- src/map/editors/RectangleEditor.ts | 3 +-- src/map/type.ts | 9 ++++++++- src/store/actions/StoreAction.ts | 3 +-- src/store/actions/index.ts | 4 ++-- src/store/constants.ts | 2 +- src/store/reducers/map/index.ts | 4 ++-- src/store/utils/getGeoJSON.ts | 3 +-- src/store/utils/getMapOptions.ts | 3 +-- src/types/enum.ts | 7 ------- src/utils/index.ts | 2 +- 18 files changed, 28 insertions(+), 39 deletions(-) diff --git a/src/editor/Catalog/index.tsx b/src/editor/Catalog/index.tsx index 739e846..f0847e1 100644 --- a/src/editor/Catalog/index.tsx +++ b/src/editor/Catalog/index.tsx @@ -2,11 +2,10 @@ import { Collapse } from "antd"; import { useSelector } from "react-redux"; import { editorAction, selectedIdsSelector, mapOptionsSelector } from "@store"; -import { IOverlay } from "@map"; +import { IOverlay, OverlayTypes } from "@map"; import "./style.less"; import classNames from "classnames"; -import { OverlayTypes } from "../../types/enum"; const { Panel } = Collapse; diff --git a/src/editor/Plot/Tools/index.tsx b/src/editor/Plot/Tools/index.tsx index 7721ca2..32b5d50 100644 --- a/src/editor/Plot/Tools/index.tsx +++ b/src/editor/Plot/Tools/index.tsx @@ -7,7 +7,8 @@ import { statusSelector, overlayTypeSelector, } from "@store"; -import { OverlayTypes, Status } from "@types"; +import { Status } from "@types"; +import { OverlayTypes } from "@map"; import { SearchModal } from "./SearchModal"; import { useState } from "react"; diff --git a/src/editor/Property/index.tsx b/src/editor/Property/index.tsx index f7ae30a..4da43b7 100644 --- a/src/editor/Property/index.tsx +++ b/src/editor/Property/index.tsx @@ -1,9 +1,7 @@ import { useSelector } from "react-redux"; import { Form, Select } from "antd"; import { selectedIdsSelector, mapOptionsSelector, editorAction } from "@store"; -import { OverlayCategory, IOverlay } from "@map"; - -import { OverlayTypes } from "@types"; +import { OverlayCategory, IOverlay, OverlayTypes } from "@map"; import { FineInput } from "./FineInput"; import { OverlayBackground } from "./OverlayBackground"; diff --git a/src/map/MapEditor.ts b/src/map/MapEditor.ts index d7e27b3..c014d3e 100644 --- a/src/map/MapEditor.ts +++ b/src/map/MapEditor.ts @@ -2,6 +2,7 @@ import Emitter from "@finevis/emitter"; import "@amap/amap-jsapi-types"; import { getOverlayPaths, getUID, registerHotkey } from "@utils"; +import { EventTypes } from "@types"; import { BaseOverlayEditor, @@ -11,12 +12,10 @@ import { CircleEditor, } from "./editors"; -import { IMapOptions, IMapEditor, IOverlay } from "./type"; +import { IMapOptions, IMapEditor, IOverlay, OverlayTypes } from "./type"; import { PolygonOptions, PolylineOptions, SelectedOptions } from "./constants"; -import { EventTypes, OverlayTypes } from "../types/enum"; - type AMapOverlayEditor = | AMap.RectangleEditor | AMap.PolygonEditor diff --git a/src/map/editors/BaseOverlayEditor.ts b/src/map/editors/BaseOverlayEditor.ts index c0ddeb2..5f1940c 100644 --- a/src/map/editors/BaseOverlayEditor.ts +++ b/src/map/editors/BaseOverlayEditor.ts @@ -1,5 +1,4 @@ -import { OverlayTypes } from "@types"; -import { IOverlay } from "../type"; +import { IOverlay, OverlayTypes } from "../type"; export abstract class BaseOverlayEditor { map: AMap.Map; diff --git a/src/map/editors/CircleEditor.ts b/src/map/editors/CircleEditor.ts index 16345c9..320f683 100644 --- a/src/map/editors/CircleEditor.ts +++ b/src/map/editors/CircleEditor.ts @@ -1,5 +1,4 @@ -import { OverlayTypes } from "@types"; -import { IOverlay } from "../type"; +import { IOverlay, OverlayTypes } from "../type"; import { BaseOverlayEditor } from "./BaseOverlayEditor"; export class CircleEditor extends BaseOverlayEditor { diff --git a/src/map/editors/PolygonEditor.ts b/src/map/editors/PolygonEditor.ts index cee4aa4..c54cdd0 100644 --- a/src/map/editors/PolygonEditor.ts +++ b/src/map/editors/PolygonEditor.ts @@ -1,5 +1,4 @@ -import { OverlayTypes } from "@types"; -import { IOverlay } from "../type"; +import { IOverlay, OverlayTypes } from "../type"; import { BaseOverlayEditor } from "./BaseOverlayEditor"; export class PolygonEditor extends BaseOverlayEditor { diff --git a/src/map/editors/PolylineEditor.ts b/src/map/editors/PolylineEditor.ts index cd9374e..d4e6ed2 100644 --- a/src/map/editors/PolylineEditor.ts +++ b/src/map/editors/PolylineEditor.ts @@ -1,5 +1,4 @@ -import { OverlayTypes } from "@types"; -import { IOverlay } from "../type"; +import { IOverlay, OverlayTypes } from "../type"; import { BaseOverlayEditor } from "./BaseOverlayEditor"; export class PolylineEditor extends BaseOverlayEditor { diff --git a/src/map/editors/RectangleEditor.ts b/src/map/editors/RectangleEditor.ts index be57c81..6da1b95 100644 --- a/src/map/editors/RectangleEditor.ts +++ b/src/map/editors/RectangleEditor.ts @@ -1,5 +1,4 @@ -import { OverlayTypes } from "@types"; -import { IOverlay } from "../type"; +import { IOverlay, OverlayTypes } from "../type"; import { BaseOverlayEditor } from "./BaseOverlayEditor"; export class RectangleEditor extends BaseOverlayEditor { diff --git a/src/map/type.ts b/src/map/type.ts index 3ea2650..5f56046 100644 --- a/src/map/type.ts +++ b/src/map/type.ts @@ -1,4 +1,4 @@ -import { EventTypes, OverlayTypes } from "@types"; +import { EventTypes } from "@types"; export interface IMapEditor { on(type: EventTypes, evt: any): void; @@ -40,3 +40,10 @@ export interface IMapOptions { center?: GeoJSON.Position; zoom?: number; } + +export enum OverlayTypes { + Rectangle = "rectangle", + Polygon = "polygon", + Polyline = "polyline", + Circle = "circle", +} diff --git a/src/store/actions/StoreAction.ts b/src/store/actions/StoreAction.ts index 7b12610..517d2fe 100644 --- a/src/store/actions/StoreAction.ts +++ b/src/store/actions/StoreAction.ts @@ -1,5 +1,4 @@ -import { OverlayTypes } from "@types"; -import { IOverlay } from "@map"; +import { IOverlay, OverlayTypes } from "@map"; import { IEditorState } from "../type"; export enum ActionTypes { CreateOverlay = "createOverlay", diff --git a/src/store/actions/index.ts b/src/store/actions/index.ts index 327b45a..f7c0253 100644 --- a/src/store/actions/index.ts +++ b/src/store/actions/index.ts @@ -10,8 +10,8 @@ import { } from "@utils"; import { getGeoJSON, getMapOptions } from "../utils"; -import { OverlayTypes, EventTypes } from "@types"; -import { IOverlay, IMapOptions } from "@map"; +import { EventTypes } from "@types"; +import { IOverlay, IMapOptions, OverlayTypes } from "@map"; import { StoreAction } from "./StoreAction"; import { IStore } from "../type"; import { initState } from "../initState"; diff --git a/src/store/constants.ts b/src/store/constants.ts index 5eae8a7..7a6665f 100644 --- a/src/store/constants.ts +++ b/src/store/constants.ts @@ -1,4 +1,4 @@ -import { OverlayTypes } from "@types"; +import { OverlayTypes } from "@map"; export const OverlayNamePrefixs: Record = { [OverlayTypes.Rectangle]: "矩形", diff --git a/src/store/reducers/map/index.ts b/src/store/reducers/map/index.ts index ab57031..bccb846 100644 --- a/src/store/reducers/map/index.ts +++ b/src/store/reducers/map/index.ts @@ -1,8 +1,8 @@ import produce from "immer"; import { initState } from "../../initState"; import { OverlayNamePrefixs } from "@store"; -import { OverlayTypes, Status } from "@types"; -import { IOverlay, OverlayCategory } from "@map"; +import { Status } from "@types"; +import { IOverlay, OverlayCategory, OverlayTypes } from "@map"; export function createOverlay(state = initState, payload: OverlayTypes) { return produce(state, (draft) => { diff --git a/src/store/utils/getGeoJSON.ts b/src/store/utils/getGeoJSON.ts index 86f6f68..61636c4 100644 --- a/src/store/utils/getGeoJSON.ts +++ b/src/store/utils/getGeoJSON.ts @@ -1,5 +1,4 @@ -import { OverlayTypes } from "@types"; -import { IMapOptions, IOverlay, OverlayCategory } from "@map"; +import { IMapOptions, IOverlay, OverlayCategory, OverlayTypes } from "@map"; import { gcj02_To_gps84 } from "@utils"; import * as turf from "@turf/turf"; diff --git a/src/store/utils/getMapOptions.ts b/src/store/utils/getMapOptions.ts index 761f2ab..8fb852f 100644 --- a/src/store/utils/getMapOptions.ts +++ b/src/store/utils/getMapOptions.ts @@ -1,5 +1,4 @@ -import { IMapOptions, IOverlay, OverlayCategory } from "@map"; -import { OverlayTypes } from "@types"; +import { IMapOptions, IOverlay, OverlayCategory, OverlayTypes } from "@map"; import { getUID, gps84_To_gcj02 } from "@utils"; export function getMapOptions(geojson: GeoJSON.FeatureCollection) { diff --git a/src/types/enum.ts b/src/types/enum.ts index 237bf1b..7aa9d0c 100644 --- a/src/types/enum.ts +++ b/src/types/enum.ts @@ -2,13 +2,6 @@ export enum EventTypes { FinishEditOverlay = "finishEditOverlay", } -export enum OverlayTypes { - Rectangle = "rectangle", - Polygon = "polygon", - Polyline = "polyline", - Circle = "circle", -} - // 操作指令集 export enum Command { CreateOverlay = "createOveraly", diff --git a/src/utils/index.ts b/src/utils/index.ts index 87e3a88..413abde 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,5 +1,5 @@ import { uid } from "uid"; -import { OverlayTypes } from "@types"; +import { OverlayTypes } from "@map"; export * from "./hotkeys"; export * from "./download";