Browse Source

fix: 修复导出geojson圆形坐标不对问题

master
Cmen 3 years ago
parent
commit
d9188bcb25
  1. 8
      src/store/actions/index.ts
  2. 8
      src/store/utils/getGeoJSON.ts

8
src/store/actions/index.ts

@ -25,6 +25,7 @@ export class EditorAction {
mapEditor: IMapEditor | null = null; mapEditor: IMapEditor | null = null;
store: IStore; store: IStore;
id: string; id: string;
autoSaveTimer: number = -1;
constructor(store: IStore) { constructor(store: IStore) {
this.store = store; this.store = store;
@ -60,9 +61,7 @@ export class EditorAction {
this._openProject(JSON.parse(cached)); this._openProject(JSON.parse(cached));
} }
setInterval(() => { this.autoSaveTimer = setTimeout(() => this.saveTemp(), AutoCacheInterval);
this.saveTemp();
}, AutoCacheInterval);
} }
// ---------- public methods ------------- // ---------- public methods -------------
@ -125,8 +124,10 @@ export class EditorAction {
} }
async saveTemp() { async saveTemp() {
clearTimeout(this.autoSaveTimer);
await setItem(this.id, JSON.stringify(this._getMapOptions())); await setItem(this.id, JSON.stringify(this._getMapOptions()));
message.success("暂存成功~"); message.success("暂存成功~");
this.autoSaveTimer = setTimeout(() => this.saveTemp(), AutoCacheInterval);
} }
clearOverlays() { clearOverlays() {
@ -209,6 +210,7 @@ export class EditorAction {
private _bindActions() { private _bindActions() {
this.saveGeoJSON = this.saveGeoJSON.bind(this); this.saveGeoJSON = this.saveGeoJSON.bind(this);
this.saveTemp = this.saveTemp.bind(this);
this.saveProject = this.saveProject.bind(this); this.saveProject = this.saveProject.bind(this);
this.openGeoJSON = this.openGeoJSON.bind(this); this.openGeoJSON = this.openGeoJSON.bind(this);
this.openProject = this.openProject.bind(this); this.openProject = this.openProject.bind(this);

8
src/store/utils/getGeoJSON.ts

@ -116,17 +116,17 @@ function getCirclePath(center: GeoJSON.Position, radius: number) {
return path; return path;
} }
// todo: 转换并不是很准确, 需要好好研究一下.
function getLngLatWithDistance( function getLngLatWithDistance(
center: GeoJSON.Position, center: GeoJSON.Position,
distance: number, distance: number,
direction: number direction: number
) { ) {
distance /= EarthRadius; distance /= EarthRadius * Math.PI * 2;
const [lng, lat] = center; const [lng, lat] = center;
// 差不多的数字...
return [ return [
lng + distance * Math.cos(direction), lng + distance * 360 * Math.cos(direction),
lat + distance * Math.sin(direction), lat + distance * 320 * Math.sin(direction),
]; ];
} }

Loading…
Cancel
Save