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