diff --git a/src/store/actions/index.ts b/src/store/actions/index.ts index bdfd612..327b45a 100644 --- a/src/store/actions/index.ts +++ b/src/store/actions/index.ts @@ -25,6 +25,7 @@ export class EditorAction { mapEditor: IMapEditor | null = null; store: IStore; id: string; + autoSaveTimer: number = -1; constructor(store: IStore) { this.store = store; @@ -60,9 +61,7 @@ export class EditorAction { this._openProject(JSON.parse(cached)); } - setInterval(() => { - this.saveTemp(); - }, AutoCacheInterval); + this.autoSaveTimer = setTimeout(() => this.saveTemp(), AutoCacheInterval); } // ---------- public methods ------------- @@ -125,8 +124,10 @@ export class EditorAction { } async saveTemp() { + clearTimeout(this.autoSaveTimer); await setItem(this.id, JSON.stringify(this._getMapOptions())); message.success("暂存成功~"); + this.autoSaveTimer = setTimeout(() => this.saveTemp(), AutoCacheInterval); } clearOverlays() { @@ -209,6 +210,7 @@ export class EditorAction { private _bindActions() { this.saveGeoJSON = this.saveGeoJSON.bind(this); + this.saveTemp = this.saveTemp.bind(this); this.saveProject = this.saveProject.bind(this); this.openGeoJSON = this.openGeoJSON.bind(this); this.openProject = this.openProject.bind(this); diff --git a/src/store/utils/getGeoJSON.ts b/src/store/utils/getGeoJSON.ts index 91076ee..86f6f68 100644 --- a/src/store/utils/getGeoJSON.ts +++ b/src/store/utils/getGeoJSON.ts @@ -116,17 +116,17 @@ function getCirclePath(center: GeoJSON.Position, radius: number) { return path; } -// todo: 转换并不是很准确, 需要好好研究一下. function getLngLatWithDistance( center: GeoJSON.Position, distance: number, direction: number ) { - distance /= EarthRadius; + distance /= EarthRadius * Math.PI * 2; const [lng, lat] = center; + // 差不多的数字... return [ - lng + distance * Math.cos(direction), - lat + distance * Math.sin(direction), + lng + distance * 360 * Math.cos(direction), + lat + distance * 320 * Math.sin(direction), ]; }