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 -------------