From 2f4029bbd884d6b88c1d5b30c1bcd1df68e35a02 Mon Sep 17 00:00:00 2001 From: muerwre Date: Mon, 26 Nov 2018 17:44:45 +0700 Subject: [PATCH] redux: map centering from saga --- src/modules/Editor.js | 9 ++++++--- src/modules/Poly.js | 2 ++ src/redux/user/sagas.js | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/modules/Editor.js b/src/modules/Editor.js index 2c882c5..ce34bd4 100644 --- a/src/modules/Editor.js +++ b/src/modules/Editor.js @@ -220,11 +220,14 @@ export class Editor { 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(); - - if (route && bounds && Object.values(bounds)) this.map.map.fitBounds(bounds); + if (bounds && Object.values(bounds)) this.map.map.fitBounds(bounds); }; setInitialData = () => { diff --git a/src/modules/Poly.js b/src/modules/Poly.js index bec868e..4bd21db 100644 --- a/src/modules/Poly.js +++ b/src/modules/Poly.js @@ -159,4 +159,6 @@ export class Poly { clearArrows = () => this.arrows.clearLayers(); dumpData = () => this.latlngs; + + isEmpty = () => !this.latlngs || Object.values(this.latlngs).length < 0; } diff --git a/src/redux/user/sagas.js b/src/redux/user/sagas.js index edb0468..6a90173 100644 --- a/src/redux/user/sagas.js +++ b/src/redux/user/sagas.js @@ -66,6 +66,7 @@ function* mapInitSaga() { if (map) { yield editor.setData(map); + yield editor.fitDrawing(); yield put(setChanged(false)); if (mode && mode === 'edit') {