[view/map][s]: make map view much more robust regarding bad or missing data in location fields.

This commit is contained in:
Rufus Pollock
2012-04-21 23:52:22 +01:00
parent 793fde4617
commit 24295e78a2

View File

@@ -256,9 +256,12 @@ my.Map = Backbone.View.extend({
if (!(docs instanceof Array)) docs = [docs];
var count = 0;
var wrongSoFar = 0;
_.every(docs,function(doc){
count += 1;
var feature = self._getGeometryFromDocument(doc);
if (typeof feature === 'undefined'){
if (typeof feature === 'undefined' || feature === null){
// Empty field
return true;
} else if (feature instanceof Object){
@@ -277,14 +280,18 @@ my.Map = Backbone.View.extend({
try {
self.features.addGeoJSON(feature);
} catch (except) {
wrongSoFar += 1;
var msg = 'Wrong geometry value';
if (except.message) msg += ' (' + except.message + ')';
if (wrongSoFar <= 10) {
my.notify(msg,{category:'error'});
return false;
}
}
} else {
wrongSoFar += 1
if (wrongSoFar <= 10) {
my.notify('Wrong geometry value',{category:'error'});
return false;
}
}
return true;
});
@@ -317,6 +324,9 @@ my.Map = Backbone.View.extend({
return doc.attributes[this.state.get('geomField')];
} else if (this.state.get('lonField') && this.state.get('latField')){
// We'll create a GeoJSON like point object from the two lat/lon fields
var lon = doc.get(this.state.get('lonField'));
var lat = doc.get(this.state.get('latField'));
if (lon && lat) {
return {
type: 'Point',
coordinates: [
@@ -325,6 +335,7 @@ my.Map = Backbone.View.extend({
]
};
}
}
return null;
}
},