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

8
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),
];
}

Loading…
Cancel
Save