Browse Source

自动暂存

master
Cmen 3 years ago
parent
commit
13de8da846
  1. 3
      package.json
  2. 16
      src/map/index.ts
  3. 19
      src/store/GlobalController.ts
  4. 8
      src/store/actions.ts
  5. 6
      src/store/reducers/index.ts
  6. 3
      src/types/enum.ts
  7. 5
      src/utils/index.ts
  8. 12
      yarn.lock

3
package.json

@ -17,7 +17,8 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-redux": "^7.2.6",
"redux": "^4.1.2"
"redux": "^4.1.2",
"uid": "^2.0.0"
},
"devDependencies": {
"@amap/amap-jsapi-types": "^0.0.8",

16
src/map/index.ts

@ -2,7 +2,7 @@ import Emitter from "@finevis/emitter";
import "@amap/amap-jsapi-types";
import { IMapState } from "@store";
import { getOverlayPaths } from "@utils";
import { getOverlayPaths, getUID } from "@utils";
import {
BaseOverlayEditor,
@ -17,9 +17,6 @@ import { PolygonOptions, PolylineOptions, SelectedOptions } from "./constants";
import { Command, EventTypes, OverlayTypes } from "../types/enum";
let uuid = 0;
const getUuid = () => ++uuid + "";
type AMapOverlayEditor =
| AMap.RectangleEditor
| AMap.PolygonEditor
@ -106,6 +103,15 @@ export class MapEditor extends Emitter {
);
}
importOverlays() {
//
}
// 清空所有覆盖物
clearOverlays() {
//
}
_createOverlay(mapState: IMapState) {
const { overlayType } = mapState;
this._currentOverlayEditor = this.getEditorByType(overlayType!);
@ -136,7 +142,7 @@ export class MapEditor extends Emitter {
if (target == null) return;
const type = this._currentOverlayEditor.getType();
const isCreatingOverlay = this._editorStatus === "creating";
let id = getUuid();
let id = getUID();
if (isCreatingOverlay) {
this.overlayMap[id] = { type, target };
} else {

19
src/store/GlobalController.ts

@ -1,7 +1,7 @@
import { message, Popconfirm, Modal } from "antd";
import { registerHotkey, downloadJSON } from "@utils";
import { IStore } from "./type";
import { IStore, IEditorState } from "./type";
import { getGeoJSON } from "./utils";
import { OverlayTypes } from "../types/enum";
import { EditorAction } from "./actions";
@ -29,6 +29,19 @@ export class GlobelController implements IGlobalController {
this._bindOperations();
this._registerHotkeys();
const cached = sessionStorage.getItem("fine-geojson");
if (cached != null) {
this._replaceState(JSON.parse(cached));
}
setInterval(() => {
sessionStorage.setItem(
"fine-geojson",
JSON.stringify(this._store.getState())
);
console.log("updated!");
}, 10000);
}
get mapState() {
@ -86,6 +99,10 @@ export class GlobelController implements IGlobalController {
});
}
private _replaceState(state: IEditorState) {
this._store.dispatch(EditorAction.replaceState(state));
}
private _bindOperations() {
this.saveGeoJSON = this.saveGeoJSON.bind(this);
this.createRectangle = this.createRectangle.bind(this);

8
src/store/actions.ts

@ -1,4 +1,5 @@
import { OverlayTypes } from "@types";
import { IEditorState } from "./type";
export enum ActionTypes {
// AddRect = "addRect",
@ -6,6 +7,7 @@ export enum ActionTypes {
FinishEditOverlay = "finishEditOverlay",
SelectOverlay = "selectOverlay",
DeleteOverlays = "deleteOverlays",
ReplaceState = "replaceState",
}
export type CreatedOverlay = {
@ -40,4 +42,10 @@ export const EditorAction: Record<ActionTypes, ActionCreator> = {
payload: null,
};
},
replaceState(state: IEditorState) {
return {
type: ActionTypes.ReplaceState,
payload: state,
};
},
};

6
src/store/reducers/index.ts

@ -20,9 +20,13 @@ const actionReducers: Record<ActionTypes, ActionReducer> = {
[ActionTypes.FinishEditOverlay]: finishEditOverlay,
[ActionTypes.SelectOverlay]: selectOverlay,
[ActionTypes.DeleteOverlays]: deleteOverlays,
// addRect: undefined
[ActionTypes.ReplaceState]: replaceState,
};
function replaceState(state = initState, payload: IEditorState) {
return payload;
}
export function reducer(state = initState, action: Action) {
const { payload, type } = action;
if (type in actionReducers) {

3
src/types/enum.ts

@ -14,6 +14,9 @@ export enum Command {
CreateOverlay = "createOveraly",
SelectOverlay = "selectOverlay",
DeleteOverlays = "deleteOverlays",
ClearOverlays = "clearOverlays",
OpenProject = "openProject",
OpenGeoJSON = "openGeoJSON",
}
// 地图状态.

5
src/utils/index.ts

@ -1,8 +1,13 @@
import { uid } from "uid";
import { OverlayTypes } from "@types";
export * from "./hotkeys";
export * from "./download";
export function getUID() {
return uid(12);
}
export function getOverlayPaths(target: AMap.MapOverlay, type: OverlayTypes) {
if (type === OverlayTypes.Rectangle) {
const overlay = target as AMap.Rectangle;

12
yarn.lock

@ -1327,6 +1327,11 @@
resolved "https://registry.npmmirror.com/@humanwhocodes/object-schema/download/@humanwhocodes/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45"
integrity sha1-tSBSnsIdjllFoYUd/Rwy6U45/0U=
"@lukeed/csprng@^1.0.0":
version "1.0.1"
resolved "https://registry.npmmirror.com/@lukeed/csprng/-/csprng-1.0.1.tgz#625e93a0edb2c830e3c52ce2d67b9d53377c6a66"
integrity sha512-uSvJdwQU5nK+Vdf6zxcWAY2A8r7uqe+gePwLWzJ+fsQehq18pc0I2hJKwypZ2aLM90+Er9u1xn4iLJPZ+xlL4g==
"@nodelib/fs.scandir@2.1.5":
version "2.1.5"
resolved "https://registry.nlark.com/@nodelib/fs.scandir/download/@nodelib/fs.scandir-2.1.5.tgz?cache=0&sync_timestamp=1622792718463&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40nodelib%2Ffs.scandir%2Fdownload%2F%40nodelib%2Ffs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5"
@ -4487,6 +4492,13 @@ typescript@^4.4.4:
resolved "https://registry.npmmirror.com/typescript/download/typescript-4.5.4.tgz#a17d3a0263bf5c8723b9c52f43c5084edf13c2e8"
integrity sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg==
uid@^2.0.0:
version "2.0.0"
resolved "https://registry.npmmirror.com/uid/-/uid-2.0.0.tgz#1773bec106e96955f1658f20272e2ccea414e8bc"
integrity sha512-hFw+zKBA1szYdbZWj6FjTxZzJnKNf+wTDcsxlJaXS64MCy9LQEmJUVieGYHCKek/WRyFIcs0cEXtGIQmfvHe2A==
dependencies:
"@lukeed/csprng" "^1.0.0"
unbox-primitive@^1.0.1:
version "1.0.1"
resolved "https://registry.nlark.com/unbox-primitive/download/unbox-primitive-1.0.1.tgz#085e215625ec3162574dc8859abee78a59b14471"

Loading…
Cancel
Save