Repository: yagoferrer/map-tools
Pull request #266 (2015-04-26 22:54:20)

#237


Patch:
diff --git a/examples/code.snippet/tags.snippet.html b/examples/code.snippet/tags.snippet.html
index 6e102f2..18e04bd 100644
--- a/examples/code.snippet/tags.snippet.html
+++ b/examples/code.snippet/tags.snippet.html
@@ -23,7 +23,5 @@
   };
 
   map.addMarker(parks, options);
-
-  var find = map.findMarker({tags: 'parks'});
-  map.updateMarker(find, {visible: false});
+  map.updateMarker({tags: 'parks'}, {visible: false});
 </code></pre></div>
diff --git a/examples/tags.html b/examples/tags.html
index 71ddf18..89dff19 100644
--- a/examples/tags.html
+++ b/examples/tags.html
@@ -38,13 +38,13 @@ Icons generated using: http://mapicons.nicolasmollet.com/
           '.places click': function (e) {
             e.preventDefault();
             placesVisible = !placesVisible;
-            map.updateMarker(map.findMarker({tags: 'places'}), {visible: placesVisible});
+            map.updateMarker({tags: 'places'}, {visible: placesVisible});
           },
 
           '.parks click': function (e) {
             e.preventDefault();
             parksVisible = !parksVisible;
-            map.updateMarker(map.findMarker({tags: 'parks'}), {visible: parksVisible});
+            map.updateMarker({tags: 'parks'}, {visible: parksVisible});
           }
         }
       });
diff --git a/lib/map-tools/updateMarker.js b/lib/map-tools/updateMarker.js
index caff367..bcc0425 100644
--- a/lib/map-tools/updateMarker.js
+++ b/lib/map-tools/updateMarker.js
@@ -12,39 +12,47 @@ module.exports = function (global, that) {
   function update(args, options) {
 
     var visibilityFlag = false;
-
-    var type = Object.prototype.toString.call(args);
     var preparedOptions = utils.prepareOptions(options, config.customMarkerOptions);
-
-
     if (preparedOptions.defaults && preparedOptions.defaults.hasOwnProperty('visible') && that.events.indexOf('marker_visibility_changed') > -1) {
       visibilityFlag = true;
     }
 
 
     var result;
+    var type = Object.prototype.toString.call(args);
 
     if (type === '[object Object]') {
-      result = customUpdate(findMarker(args), preparedOptions);
+      if (Object.keys(args).length === 1 && args.tags) {
+        var filter = require('map-tools/filter')(global, that, 'markers');
+        result = bulkUpdate(filter(args), preparedOptions);
+
+      } else {
+        result = customUpdate(findMarker(args), preparedOptions);
+      }
     }
     if (type === '[object Array]') {
-      var marker, results = [], instance, x;
-      for (x in args) {
-        if (args.hasOwnProperty(x)) {
-          marker = args[x];
-          instance = customUpdate(findMarker(marker), preparedOptions);
-          results.push(instance);
-        }
-      }
-      result = results;
+      result = bulkUpdate(args, preparedOptions);
     }
 
-
     if (visibilityFlag) {
       countVisible();
     }
 
     return result;
+  }
+
+  function bulkUpdate(args, options) {
+
+    var marker, results = [], instance, x;
+    for (x in args) {
+      if (args.hasOwnProperty(x)) {
+        marker = args[x];
+        instance = customUpdate(findMarker(marker), options);
+        results.push(instance);
+      }
+    }
+
+    return results;
 
   }
 


Test patch:
diff --git a/test/functional/tags.Spec.js b/test/functional/tags.Spec.js
index 834fa87..a571cde 100644
--- a/test/functional/tags.Spec.js
+++ b/test/functional/tags.Spec.js
@@ -122,5 +122,22 @@ describe('Given the Tag Feature', function () {
 
     });
 
+
+    describe('when calling updateMarker() with tags', function () {
+
+      it('should find the Marker and update one tag for another', function() {
+        map.addMarker({
+          lat: 42,
+          lng: 1,
+          title: 'Andorra',
+          tags: 'myTag'
+        });
+
+        map.updateMarker({tags: 'myTag'}, {tags: 'myTag2'});
+      });
+
+
+    });
+
   });
 });