From e8f872c2346949fc1baa948bdc0c8281453f90ae Mon Sep 17 00:00:00 2001 From: Cmen <1176967590@qq.com> Date: Sun, 6 Mar 2022 11:32:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E5=9C=B0=E5=9B=BE=E4=B8=AD?= =?UTF-8?q?=E5=BF=83=E7=82=B9&=E7=BC=A9=E6=94=BE=E5=B1=82=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/editor/Plot/Tools/index.tsx | 17 +++++++++-------- src/map/MapEditor.ts | 18 ++++++++++++++++++ src/map/type.ts | 4 ++++ src/store/actions/index.ts | 6 ++++-- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/editor/Plot/Tools/index.tsx b/src/editor/Plot/Tools/index.tsx index 2c3e698..76f5d72 100644 --- a/src/editor/Plot/Tools/index.tsx +++ b/src/editor/Plot/Tools/index.tsx @@ -38,11 +38,12 @@ const IconWithTip = ({ type OverlayToolProps = { type: OverlayTypes; + hotkey: string; }; const OverlayTool = (props: OverlayToolProps) => { - const { type } = props; - const text = OverlayNamePrefixs[type]; + const { type, hotkey } = props; + const text = `创建${OverlayNamePrefixs[type]}(${hotkey})`; const overlayType = useSelector(overlayTypeSelector); const status = useSelector(statusSelector); @@ -57,18 +58,18 @@ const Tools = () => { return ( <>
- - - - + + + +
-
+ {/*
-
+
*/}
); diff --git a/src/map/MapEditor.ts b/src/map/MapEditor.ts index b78e45c..37b84d4 100644 --- a/src/map/MapEditor.ts +++ b/src/map/MapEditor.ts @@ -16,6 +16,7 @@ import { IMapOptions, IMapEditor } from "./type"; import { PolygonOptions, PolylineOptions, SelectedOptions } from "./constants"; import { EventTypes, OverlayTypes } from "../types/enum"; +import { Position } from "geojson"; type AMapOverlayEditor = | AMap.RectangleEditor @@ -82,6 +83,15 @@ export class MapEditor extends Emitter implements IMapEditor { ]; } + getCenter() { + const { lng, lat } = this.map.getCenter(); + return [lng, lat]; + } + + getZoom() { + return this.map.getZoom(); + } + getEditorByType(overlayType: OverlayTypes) { return this.overlayEditors.find( (editor) => editor.getType() === overlayType @@ -96,6 +106,14 @@ export class MapEditor extends Emitter implements IMapEditor { const polylineEditor = this.getEditorByType(OverlayTypes.Polyline); const circleEditor = this.getEditorByType(OverlayTypes.Circle); + if (options.center) { + const [lng, lat] = options.center; + this.map.setCenter(new AMap.LngLat(lng, lat)); + } + if (options.zoom != null) { + this.map.setZoom(options.zoom); + } + const addOverlay = ( id: string, target: AMap.MapOverlay, diff --git a/src/map/type.ts b/src/map/type.ts index 84c4654..f751305 100644 --- a/src/map/type.ts +++ b/src/map/type.ts @@ -9,6 +9,8 @@ export interface IMapEditor { selectOverlays(ids?: string[]): void; deleteOverlays(): void; clearOverlays(): void; + getCenter(): GeoJSON.Position; + getZoom(): number; } export interface IOverlay { @@ -25,4 +27,6 @@ export interface IMapOptions { circles: IOverlay[]; rectangles: IOverlay[]; selectedIds?: string[]; + center?: GeoJSON.Position; + zoom?: number; } diff --git a/src/store/actions/index.ts b/src/store/actions/index.ts index 6988871..1de9b94 100644 --- a/src/store/actions/index.ts +++ b/src/store/actions/index.ts @@ -49,8 +49,10 @@ export class EditorAction { } setInterval(() => { - sessionStorage.setItem("fine-geojson", JSON.stringify(this.mapOptions)); - console.log("updated!"); + const { mapOptions } = this; + mapOptions.center = this.mapEditor?.getCenter(); + mapOptions.zoom = this.mapEditor?.getZoom(); + sessionStorage.setItem("fine-geojson", JSON.stringify(mapOptions)); }, 10000); } // ---------- public methods -------------