From d37d092490b6a4f3dd161f692ef6e811fa4e87b3 Mon Sep 17 00:00:00 2001 From: Azimkhan Date: Wed, 28 Jan 2015 00:36:27 +0600 Subject: [PATCH 1/2] Update leaflet.forms.js --- leaflet/static/leaflet/leaflet.forms.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/leaflet/static/leaflet/leaflet.forms.js b/leaflet/static/leaflet/leaflet.forms.js index d7b4ba4b..3443e5bb 100644 --- a/leaflet/static/leaflet/leaflet.forms.js +++ b/leaflet/static/leaflet/leaflet.forms.js @@ -167,7 +167,11 @@ L.GeometryField = L.Class.extend({ _setView: function () { // Change view extent if (this.drawnItems.getLayers().length > 0) { - this._map.fitBounds(this.drawnItems.getBounds()); + var bounds = this.drawnItems.getBounds(); + if (!bounds._southWest.equals(bounds._northEast)) + this._map.fitBounds(bounds); + else + this._map.setView(bounds._northEast, this.default_zoom); } // Else keep view extent set by django-leaflet template tag }, From 4625c0a6c4589238fa57bf38b7786a75be36bfd1 Mon Sep 17 00:00:00 2001 From: Mathieu Leplatre Date: Fri, 17 Apr 2015 11:59:42 +0200 Subject: [PATCH 2/2] Add comment on @Azimkhan fix --- leaflet/static/leaflet/leaflet.forms.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/leaflet/static/leaflet/leaflet.forms.js b/leaflet/static/leaflet/leaflet.forms.js index 3443e5bb..08d0d2e1 100644 --- a/leaflet/static/leaflet/leaflet.forms.js +++ b/leaflet/static/leaflet/leaflet.forms.js @@ -168,6 +168,8 @@ L.GeometryField = L.Class.extend({ // Change view extent if (this.drawnItems.getLayers().length > 0) { var bounds = this.drawnItems.getBounds(); + // In case of points, fitBounds() fails. + // https://github.com/makinacorpus/django-leaflet/issues/90 if (!bounds._southWest.equals(bounds._northEast)) this._map.fitBounds(bounds); else