[view/map,bugfix,refactor][s]: correct bug due to misinterpretation (?) of Backbone reset and refactor so we redraw on initialize.
* Bug: dataset.currentDocuments.reset was being interpreted as empty rather than a re-fill of new documents and was therefore not re-adding currentDocuments items to the list of features. Fixed this. * Discovered bug during a refactor. Refactor removed listener for query:done as this will be covered by currentDocuments.reset or similar. This also means we can initialize the view with a dataset already containing data and it will render w/o need to call query() again.
This commit is contained in:
@@ -88,7 +88,7 @@ my.Map = Backbone.View.extend({
|
|||||||
</div> \
|
</div> \
|
||||||
',
|
',
|
||||||
|
|
||||||
// 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.
|
// If not found, the user will need to define the fields via the editor.
|
||||||
latitudeFieldNames: ['lat','latitude'],
|
latitudeFieldNames: ['lat','latitude'],
|
||||||
longitudeFieldNames: ['lon','longitude'],
|
longitudeFieldNames: ['lon','longitude'],
|
||||||
@@ -154,7 +154,7 @@ my.Map = Backbone.View.extend({
|
|||||||
this.render();
|
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.
|
// Also sets up the editor fields and the map if necessary.
|
||||||
render: function() {
|
render: function() {
|
||||||
@@ -176,22 +176,11 @@ my.Map = Backbone.View.extend({
|
|||||||
$('#editor-field-type-latlon').attr('checked','checked').change();
|
$('#editor-field-type-latlon').attr('checked','checked').change();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.redraw();
|
||||||
this.model.bind('query:done', function() {
|
|
||||||
if (!self.geomReady){
|
|
||||||
self._setupGeometryField();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!self.mapReady){
|
|
||||||
self._setupMap();
|
|
||||||
}
|
|
||||||
self.redraw();
|
|
||||||
});
|
|
||||||
|
|
||||||
return this;
|
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:
|
// Actions can be:
|
||||||
//
|
//
|
||||||
@@ -199,23 +188,27 @@ my.Map = Backbone.View.extend({
|
|||||||
// * add: Add one or n features (documents)
|
// * add: Add one or n features (documents)
|
||||||
// * remove: Remove one or n features (documents)
|
// * remove: Remove one or n features (documents)
|
||||||
// * refresh: Clear existing features and add all current documents
|
// * refresh: Clear existing features and add all current documents
|
||||||
//
|
redraw: function(action, doc){
|
||||||
redraw: function(action,doc){
|
|
||||||
var self = this;
|
var self = this;
|
||||||
action = action || 'refresh';
|
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 (this.geomReady && this.mapReady){
|
||||||
if (action == 'reset'){
|
if (action == 'reset' || action == 'refresh'){
|
||||||
this.features.clearLayers();
|
this.features.clearLayers();
|
||||||
|
this._add(this.model.currentDocuments.models);
|
||||||
} else if (action == 'add' && doc){
|
} else if (action == 'add' && doc){
|
||||||
this._add(doc);
|
this._add(doc);
|
||||||
} else if (action == 'remove' && doc){
|
} else if (action == 'remove' && doc){
|
||||||
this._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){
|
if (this.visible){
|
||||||
this._zoomToFeatures();
|
this._zoomToFeatures();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ test('Lat/Lon geom fields', function () {
|
|||||||
});
|
});
|
||||||
$('.fixtures').append(view.el);
|
$('.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();
|
dataset.query();
|
||||||
|
|
||||||
// Check that all markers were created
|
// Check that all markers were created
|
||||||
|
|||||||
Reference in New Issue
Block a user