From 45c05a33342803c260e9743d2099ef9cd2b1f04c Mon Sep 17 00:00:00 2001 From: amercader Date: Wed, 11 Apr 2012 18:47:15 +0100 Subject: [PATCH] [view/map] Ignore empty fields and replace non-crossbrowser commands --- src/view-map.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/view-map.js b/src/view-map.js index e1705f1e..cf1d5ae8 100644 --- a/src/view-map.js +++ b/src/view-map.js @@ -239,15 +239,18 @@ my.Map = Backbone.View.extend({ // // Each feature will have a popup associated with all the document fields. // - _add: function(doc){ + _add: function(docs){ var self = this; - if (!(doc instanceof Array)) doc = [doc]; + if (!(docs instanceof Array)) docs = [docs]; - doc.forEach(function(doc){ + _.every(docs,function(doc){ var feature = self._getGeometryFromDocument(doc); - if (feature instanceof Object){ + if (typeof feature === 'undefined'){ + // Empty field + return true; + } else if (feature instanceof Object){ // Build popup contents // TODO: mustache? html = '' @@ -266,24 +269,25 @@ my.Map = Backbone.View.extend({ var msg = 'Wrong geometry value'; if (except.message) msg += ' (' + except.message + ')'; my.notify(msg,{category:'error'}); - _.breakLoop(); + return false; } } else { my.notify('Wrong geometry value',{category:'error'}); - _.breakLoop(); + return false; } + return true; }); }, // Private: Remove one or n features to the map // - _remove: function(doc){ + _remove: function(docs){ var self = this; - if (!(doc instanceof Array)) doc = [doc]; + if (!(docs instanceof Array)) docs = [docs]; - doc.forEach(function(doc){ + _.each(doc,function(doc){ for (key in self.features._layers){ if (self.features._layers[key].cid == doc.cid){ self.features.removeLayer(self.features._layers[key]);