|
|
@ -1,7 +1,13 @@ |
|
|
|
import { IMapEditor } from "@map"; |
|
|
|
import { IMapEditor } from "@map"; |
|
|
|
import { Action } from "redux"; |
|
|
|
import { Action } from "redux"; |
|
|
|
import { message, Modal } from "antd"; |
|
|
|
import { message, Modal } from "antd"; |
|
|
|
import { registerHotkey, downloadJSON, openUpload } from "@utils"; |
|
|
|
import { |
|
|
|
|
|
|
|
registerHotkey, |
|
|
|
|
|
|
|
downloadJSON, |
|
|
|
|
|
|
|
openUpload, |
|
|
|
|
|
|
|
getItem, |
|
|
|
|
|
|
|
setItem, |
|
|
|
|
|
|
|
} from "@utils"; |
|
|
|
|
|
|
|
|
|
|
|
import { getGeoJSON } from "../utils"; |
|
|
|
import { getGeoJSON } from "../utils"; |
|
|
|
import { OverlayTypes, EventTypes } from "@types"; |
|
|
|
import { OverlayTypes, EventTypes } from "@types"; |
|
|
@ -12,13 +18,19 @@ import { initState } from "../initState"; |
|
|
|
|
|
|
|
|
|
|
|
export { ActionTypes, StoreAction } from "./StoreAction"; |
|
|
|
export { ActionTypes, StoreAction } from "./StoreAction"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const CacheFileName = "default"; |
|
|
|
|
|
|
|
const AutoCacheInterval = 30000; |
|
|
|
|
|
|
|
|
|
|
|
export class EditorAction { |
|
|
|
export class EditorAction { |
|
|
|
mapEditor: IMapEditor | null = null; |
|
|
|
mapEditor: IMapEditor | null = null; |
|
|
|
store: IStore; |
|
|
|
store: IStore; |
|
|
|
|
|
|
|
id: string; |
|
|
|
|
|
|
|
|
|
|
|
constructor(store: IStore) { |
|
|
|
constructor(store: IStore) { |
|
|
|
this.store = store; |
|
|
|
this.store = store; |
|
|
|
this._bindActions(); |
|
|
|
this._bindActions(); |
|
|
|
this._registerHotkeys(); |
|
|
|
this._registerHotkeys(); |
|
|
|
|
|
|
|
this.id = CacheFileName; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
get mapOptions() { |
|
|
|
get mapOptions() { |
|
|
@ -42,16 +54,17 @@ export class EditorAction { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
mapReady() { |
|
|
|
async mapReady() { |
|
|
|
const cached = sessionStorage.getItem("fine-geojson"); |
|
|
|
const cached = await getItem(this.id); |
|
|
|
if (cached != null) { |
|
|
|
if (cached != null) { |
|
|
|
this._openProject(JSON.parse(cached)); |
|
|
|
this._openProject(JSON.parse(cached)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setInterval(() => { |
|
|
|
setInterval(() => { |
|
|
|
this.saveTemp(); |
|
|
|
this.saveTemp(); |
|
|
|
}, 10000); |
|
|
|
}, AutoCacheInterval); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ---------- public methods -------------
|
|
|
|
// ---------- public methods -------------
|
|
|
|
createRectangle() { |
|
|
|
createRectangle() { |
|
|
|
this.createOverlay(OverlayTypes.Rectangle); |
|
|
|
this.createOverlay(OverlayTypes.Rectangle); |
|
|
@ -108,15 +121,12 @@ export class EditorAction { |
|
|
|
|
|
|
|
|
|
|
|
saveProject() { |
|
|
|
saveProject() { |
|
|
|
const mapOptions = this._getMapOptions(); |
|
|
|
const mapOptions = this._getMapOptions(); |
|
|
|
downloadJSON(mapOptions, "fine.fjd"); |
|
|
|
downloadJSON(mapOptions, "fine.fgd"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
saveTemp() { |
|
|
|
async saveTemp() { |
|
|
|
sessionStorage.setItem( |
|
|
|
await setItem(this.id, JSON.stringify(this._getMapOptions())); |
|
|
|
"fine-geojson", |
|
|
|
message.success("暂存成功~"); |
|
|
|
JSON.stringify(this._getMapOptions()) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
console.log("saved!"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
clearOverlays() { |
|
|
|
clearOverlays() { |
|
|
@ -152,7 +162,7 @@ export class EditorAction { |
|
|
|
} |
|
|
|
} |
|
|
|
openProject() { |
|
|
|
openProject() { |
|
|
|
openUpload({ |
|
|
|
openUpload({ |
|
|
|
accept: ".fjd", |
|
|
|
accept: ".fgd", |
|
|
|
onReady: (content) => { |
|
|
|
onReady: (content) => { |
|
|
|
this._openProject(JSON.parse(content)); |
|
|
|
this._openProject(JSON.parse(content)); |
|
|
|
}, |
|
|
|
}, |
|
|
|