redux: map centering from saga

This commit is contained in:
muerwre 2018-11-26 17:44:45 +07:00
parent 5d14a753f7
commit 2f4029bbd8
3 changed files with 9 additions and 3 deletions

View file

@ -220,11 +220,14 @@ export class Editor {
if (owner) this.owner = owner; if (owner) this.owner = owner;
if (!route || route.length <= 1) return; // if (!route || route.length <= 1) return;
};
fitDrawing = () => {
if (this.poly.isEmpty()) return;
const bounds = this.poly.poly.getBounds(); const bounds = this.poly.poly.getBounds();
if (bounds && Object.values(bounds)) this.map.map.fitBounds(bounds);
if (route && bounds && Object.values(bounds)) this.map.map.fitBounds(bounds);
}; };
setInitialData = () => { setInitialData = () => {

View file

@ -159,4 +159,6 @@ export class Poly {
clearArrows = () => this.arrows.clearLayers(); clearArrows = () => this.arrows.clearLayers();
dumpData = () => this.latlngs; dumpData = () => this.latlngs;
isEmpty = () => !this.latlngs || Object.values(this.latlngs).length < 0;
} }

View file

@ -66,6 +66,7 @@ function* mapInitSaga() {
if (map) { if (map) {
yield editor.setData(map); yield editor.setData(map);
yield editor.fitDrawing();
yield put(setChanged(false)); yield put(setChanged(false));
if (mode && mode === 'edit') { if (mode && mode === 'edit') {