diff --git a/src/view-map.js b/src/view-map.js index 5b2f3433..30370038 100644 --- a/src/view-map.js +++ b/src/view-map.js @@ -88,7 +88,7 @@ my.Map = Backbone.View.extend({ \ ', - // These are the default field names that will be used if found. + // These are the default (case-insensitive) names of field that are used if found. // If not found, the user will need to define the fields via the editor. latitudeFieldNames: ['lat','latitude'], longitudeFieldNames: ['lon','longitude'], @@ -154,7 +154,7 @@ my.Map = Backbone.View.extend({ this.render(); }, - // Public: Adds the necessary elements to the page. + // ### Public: Adds the necessary elements to the page. // // Also sets up the editor fields and the map if necessary. render: function() { @@ -176,22 +176,11 @@ my.Map = Backbone.View.extend({ $('#editor-field-type-latlon').attr('checked','checked').change(); } } - - this.model.bind('query:done', function() { - if (!self.geomReady){ - self._setupGeometryField(); - } - - if (!self.mapReady){ - self._setupMap(); - } - self.redraw(); - }); - + this.redraw(); return this; }, - // Public: Redraws the features on the map according to the action provided + // ### Public: Redraws the features on the map according to the action provided // // Actions can be: // @@ -199,23 +188,27 @@ my.Map = Backbone.View.extend({ // * add: Add one or n features (documents) // * remove: Remove one or n features (documents) // * refresh: Clear existing features and add all current documents - // - redraw: function(action,doc){ + redraw: function(action, doc){ var self = this; action = action || 'refresh'; + // try to set things up if not already + if (!self.geomReady){ + self._setupGeometryField(); + } + if (!self.mapReady){ + self._setupMap(); + } if (this.geomReady && this.mapReady){ - if (action == 'reset'){ + if (action == 'reset' || action == 'refresh'){ this.features.clearLayers(); + this._add(this.model.currentDocuments.models); } else if (action == 'add' && doc){ this._add(doc); } else if (action == 'remove' && doc){ this._remove(doc); - } else if (action == 'refresh'){ - this.features.clearLayers(); - this._add(this.model.currentDocuments.models); } - if (action != 'reset' && this.autoZoom){ + if (this.autoZoom){ if (this.visible){ this._zoomToFeatures(); } else { diff --git a/test/view-map.test.js b/test/view-map.test.js index aa07f9a8..cf709a53 100644 --- a/test/view-map.test.js +++ b/test/view-map.test.js @@ -49,7 +49,7 @@ test('Lat/Lon geom fields', function () { }); $('.fixtures').append(view.el); - //Fire query, otherwise the map won't be initialized + // Not really needed but fire query to test that resetting works! dataset.query(); // Check that all markers were created