[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){
@@ -275,16 +278,20 @@ my.Map = Backbone.View.extend({
feature.properties.cid = doc.cid; feature.properties.cid = doc.cid;
try { try {
self.features.addGeoJSON(feature); self.features.addGeoJSON(feature);
} catch (except) { } catch (except) {
var msg = 'Wrong geometry value'; wrongSoFar += 1;
if (except.message) msg += ' (' + except.message + ')'; var msg = 'Wrong geometry value';
if (except.message) msg += ' (' + except.message + ')';
if (wrongSoFar <= 10) {
my.notify(msg,{category:'error'}); my.notify(msg,{category:'error'});
return false; }
} }
} else { } else {
my.notify('Wrong geometry value',{category:'error'}); wrongSoFar += 1
return false; if (wrongSoFar <= 10) {
my.notify('Wrong geometry value',{category:'error'});
}
} }
return true; return true;
}); });
@@ -317,13 +324,17 @@ 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
return { var lon = doc.get(this.state.get('lonField'));
type: 'Point', var lat = doc.get(this.state.get('latField'));
coordinates: [ if (lon && lat) {
doc.attributes[this.state.get('lonField')], return {
doc.attributes[this.state.get('latField')] type: 'Point',
] coordinates: [
}; doc.attributes[this.state.get('lonField')],
doc.attributes[this.state.get('latField')]
]
};
}
} }
return null; return null;
} }