Repository: yagoferrer/map-tools
Pull request #248 (2015-04-22 15:22:13)

Fixes: #247


Patch:
diff --git a/README.md b/README.md
index bff542a..3380ace 100644
--- a/README.md
+++ b/README.md
@@ -11,8 +11,8 @@
 
 ## Benefits
 - Less Code: The [Google Maps API](https://developers.google.com/maps/documentation/javascript/reference) it is of considerable size. You'll be writing way **less** code with map-tools.js
-- It helps you to keep a reference of things: For example use map.findMarker() to find the Marker(s) your are looking for.
 - More Fun: Add [Marker animations](#animate-markers), use [handlebars style](#info-window) variables.
+- Easy To Use: Intuitive APIs, easy to understand.
 - Non Intrusive: it extends the API; you can use any other native methods, properties and events anywhere.
 - Query elements on the Map to update their options using [Crossfilter](#crossfilter-support-for-markers)
 - [TopoJSON Support](#topojson-support): Add Topo/GeoJSON files, set styles and find references easier. 
@@ -316,7 +316,7 @@ The default **event** is `click` but you can change it with the `event` property
 ```
 Now you can use the power of Crossfilter to update Markers. In this example it finds the city with larger population, Madrid, and makes the marker to bounce.
 ```javascript
-var marker = map.findMarker('population', {limit: 1});
+var marker = map.filterMarker('population', {limit: 1});
 map.updateMarker(marker, {move: 'bounce'});
 ```
 
diff --git a/examples/code.snippet/data.querying.snippet.html b/examples/code.snippet/data.querying.snippet.html
index 32c2aee..8a32c31 100644
--- a/examples/code.snippet/data.querying.snippet.html
+++ b/examples/code.snippet/data.querying.snippet.html
@@ -1,7 +1,7 @@
 <div class="map-panel" ><pre class="language-javascript"><code class="language-javascript">
   // Click Event
   .click(function(){
-    var filter = map.findMarker('population', {limit: 1});
+    var filter = map.filterMarker('population', {limit: 1});
     map.updateMarker(filter, {move: 'bounce'});
   });
 
diff --git a/examples/code.snippet/update.marker.snippet.html b/examples/code.snippet/update.marker.snippet.html
index 408fb1d..1c256f6 100644
--- a/examples/code.snippet/update.marker.snippet.html
+++ b/examples/code.snippet/update.marker.snippet.html
@@ -8,7 +8,7 @@
   }, {filters: ['cityName']});
 
   // Update Marker Using Crossfilter
-  var marker = map.findMarker({cityName: 'barcelona'}, {limit: 1});
+  var marker = map.filterMarker({cityName: 'barcelona'}, {limit: 1});
 	map.updateMarker(marker, {move: 'drop'});
 
   // Using instance
diff --git a/examples/data.querying.html b/examples/data.querying.html
index 2caad8e..5f48cab 100644
--- a/examples/data.querying.html
+++ b/examples/data.querying.html
@@ -28,7 +28,7 @@
 		    position: 'right center',
 		    events: {
 			    '.top click': function (e) {
-            var marker = map.findMarker('population', {limit: 1});
+            var marker = map.filterMarker('population', {limit: 1});
 				    map.updateMarker(marker, {move: 'bounce'});
 				    e.preventDefault();
 			    }
diff --git a/examples/info.window.html b/examples/info.window.html
index e4562dd..6d7f89b 100644
--- a/examples/info.window.html
+++ b/examples/info.window.html
@@ -45,19 +45,33 @@
   var marker;
 
   function addMarker() {
-    marker = map.addMarker({
+    marker = map.addMarker([{
       lat: 41.3833,
       lng: 2.1833,
       title: 'Barcelona',
       infoWindow: {
         open: {on: 'mouseover'},
-        close: {on: 'mouseout', duration: 3000},
+        close: {on: 'mouseout', duration: 2000},
         content: '<p>{city}</p>'
       },
       data: {
         city: 'Barcelona!'
       }
-    });
+    },
+      {
+        lat: 42.5000,
+        lng: 1.5167,
+        title: 'Andorra',
+        infoWindow: {
+          open: {on: 'mouseover'},
+          close: {on: 'mouseout', duration: 2000},
+          content: '<p>{city}</p>'
+        },
+        data: {
+          city: 'Andorra'
+        }
+      }
+    ]);
   }
 
 </script>
diff --git a/examples/update.marker.html b/examples/update.marker.html
index 9b8e672..6831ac9 100644
--- a/examples/update.marker.html
+++ b/examples/update.marker.html
@@ -33,7 +33,7 @@
 				position: 'right center',
 				events: {
 					'.update-crossfilter click': function (e) {
-						var marker = map.findMarker({cityName: 'barcelona'}, {limit: 1});
+						var marker = map.filterMarker({cityName: 'barcelona'}, {limit: 1});
 						map.updateMarker(marker, {move: 'drop'});
 						e.preventDefault();
 					},
diff --git a/lib/map-tools/index.js b/lib/map-tools/index.js
index 7ade1cb..b355dd0 100644
--- a/lib/map-tools/index.js
+++ b/lib/map-tools/index.js
@@ -19,7 +19,7 @@ module.exports = function (global) {
     this.addPanel = require('map-tools/addPanel')(global, that);
     this.updateMarker = require('map-tools/updateMarker')(global, that).update;
     this.filterFeature = require('map-tools/filter')(global, that, 'json');
-    this.findMarker = require('map-tools/filter')(global, that, 'markers');
+    this.filterMarker = require('map-tools/filter')(global, that, 'markers');
     this.addGroup = require('map-tools/groups')(global, that).addGroup;
     this.updateGroup = require('map-tools/groups')(global, that).updateGroup;
     this.updateMap = require('map-tools/updateMap')(global, that);
diff --git a/lib/map-tools/infoWindow.js b/lib/map-tools/infoWindow.js
index 6031e05..1bffd42 100644
--- a/lib/map-tools/infoWindow.js
+++ b/lib/map-tools/infoWindow.js
@@ -8,35 +8,40 @@ module.exports = function (global, that) {
 
   var timer = false;
 
-  function infoWindow(marker, options)
+  function infoWindow(map, marker, args)
   {
-    if (!marker.infoWindow.instance) {
-      if (options.content) {
-        options.content = options.content.replace(/\{(\w+)\}/g, function (m, variable) {
-          return marker.data[variable] || '';
-        });
 
-        marker.infoWindow.content = options.content;
+      if (marker.infoWindow.content) {
+
+        if (marker.infoWindow.content.indexOf('{') > - 1) {
+          marker.infoWindow.content = args.content.replace(/\{(\w+)\}/g, function (m, variable) {
+            return marker.data[variable] || '';
+          });
+        }
+
+
+
       }
 
-       marker.infoWindow.instance = new global.google.maps.InfoWindow(options);
-    }
+      var options = utils.clone(args);
+      options.content = marker.infoWindow.content;
 
-    that.infoWindow = marker.infoWindow.instance;
-  }
+      that.infoWindow = new global.google.maps.InfoWindow(options);
+      that.infoWindow.open(map, marker);
+
+  };
 
   function open(marker, options, map) {
     close();
-    infoWindow(marker, options);
-    marker.infoWindow.instance.open(map, marker);
+    infoWindow(map, marker, options);
   }
+
   function isOpen(infoWindow){
     var map = infoWindow.getMap();
     return (map !== null && typeof map !== "undefined");
   }
 
   function close() {
-
     clearTimeout(timer);
     if (that.infoWindow && isOpen(that.infoWindow)) {
       that.infoWindow.close();
@@ -44,16 +49,14 @@ module.exports = function (global, that) {
   }
 
   function addEvents(marker, options, map) {
-
     var args = utils.prepareOptions(options, config.customInfoWindowOptions);
     var openOn = (args.custom && args.custom.open && args.custom.open.on) ?  args.custom.open.on : 'click';
     var closeOn = (args.custom && args.custom.close && args.custom.close.on) ? args.custom.close.on : 'click';
 
-
     // Toggle Effect when using the same method to Open and Close.
     if (openOn === closeOn) {
       global.google.maps.event.addListener(marker, openOn, function () {
-        if (!marker.infoWindow.instance || !isOpen(marker.infoWindow.instance)) {
+        if (!that.infoWindow || !isOpen(that.infoWindow)) {
           open(marker, args.defaults, map);
         } else {
           close();
@@ -62,6 +65,7 @@ module.exports = function (global, that) {
 
     } else {
 
+
       global.google.maps.event.addListener(marker, openOn, function () {
         open(marker, args.defaults, map);
       });
@@ -69,9 +73,11 @@ module.exports = function (global, that) {
 
       global.google.maps.event.addListener(marker, closeOn, function () {
         if (args.custom.close.duration) {
+
           timer = setTimeout(function(){
             close();
           }, args.custom.close.duration);
+
         } else {
           close();
         }
@@ -81,6 +87,6 @@ module.exports = function (global, that) {
 
   return {
     addEvents: addEvents
-  };
-};
+  }
+}
 
diff --git a/lib/map-tools/updateMarker.js b/lib/map-tools/updateMarker.js
index 991ad46..f811fb8 100644
--- a/lib/map-tools/updateMarker.js
+++ b/lib/map-tools/updateMarker.js
@@ -40,7 +40,7 @@ module.exports = function (global, that) {
       }
 
       if (options.custom.infoWindow && options.custom.infoWindow.content) {
-        marker.infoWindow.instance.setContent(options.custom.infoWindow.content);
+        marker.infoWindow.content = options.custom.infoWindow.content;
       }
     }
 


Test patch:
diff --git a/test/functional/updateMarker.Spec.js b/test/functional/updateMarker.Spec.js
index aca3f72..2e40e45 100644
--- a/test/functional/updateMarker.Spec.js
+++ b/test/functional/updateMarker.Spec.js
@@ -22,7 +22,7 @@ describe('when calling updateMarker()', function () {
     expect(mapTools.maps.mymap.markers.all[uid].visible).to.be.true;
     expect(mapTools.maps.mymap.markers.all[uid].position.lat()).to.eql(100);
     expect(mapTools.maps.mymap.markers.all[uid].position.lng()).to.eql(30);
-    expect(mapTools.maps.mymap.markers.all[uid].infoWindow.instance.content).to.eql('click me');
+    expect(mapTools.maps.mymap.markers.all[uid].infoWindow.content).to.eql('click me');
   });
 
   it('should invoke multiple Markers options setters for each property passed', function () {