From 1dbd8bf9579329e01bd71810da81a7984e2c8ac6 Mon Sep 17 00:00:00 2001 From: amercader Date: Mon, 16 Apr 2012 11:04:05 +0200 Subject: [PATCH] [view/map] Make auto zoom configurable --- css/map.css | 7 ++++++- src/view-map.js | 25 +++++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/css/map.css b/css/map.css index c8adde77..ed5edbd7 100644 --- a/css/map.css +++ b/css/map.css @@ -18,6 +18,11 @@ } .data-map-container .editor select { - width: 100%; + width: 100%; } +.data-map-container .editor .editor-options { + margin-top: 10px; + border-top: 1px solid gray; + padding: 5px 0; +} diff --git a/src/view-map.js b/src/view-map.js index 412dee7c..32b11e6a 100644 --- a/src/view-map.js +++ b/src/view-map.js @@ -75,6 +75,11 @@ my.Map = Backbone.View.extend({
\ \
\ +
\ + \ +
\ \ \ \ @@ -92,7 +97,8 @@ my.Map = Backbone.View.extend({ // Define here events for UI elements events: { 'click .editor-update-map': 'onEditorSubmit', - 'change .editor-field-type': 'onFieldTypeChange' + 'change .editor-field-type': 'onFieldTypeChange', + 'change #editor-auto-zoom': 'onAutoZoomChange' }, @@ -120,7 +126,7 @@ my.Map = Backbone.View.extend({ // If the div was hidden, Leaflet needs to recalculate some sizes // to display properly self.map.invalidateSize(); - if (self._zoomPending) { + if (self._zoomPending && self.autoZoom) { self._zoomToFeatures(); self._zoomPending = false; } @@ -130,6 +136,7 @@ my.Map = Backbone.View.extend({ self.visible = false; }); + this.autoZoom = true; this.mapReady = false; this.render(); @@ -198,10 +205,12 @@ my.Map = Backbone.View.extend({ this.features.clearLayers(); this._add(this.model.currentDocuments.models); } - if (this.visible){ - this._zoomToFeatures(); - } else { - this._zoomPending = true; + if (action != 'reset' && this.autoZoom){ + if (this.visible){ + this._zoomToFeatures(); + } else { + this._zoomPending = true; + } } } }, @@ -244,6 +253,10 @@ my.Map = Backbone.View.extend({ } }, + onAutoZoomChange: function(e){ + this.autoZoom = !this.autoZoom; + }, + // Private: Add one or n features to the map // // For each document passed, a GeoJSON geometry will be extracted and added