javascript - google map - close infowindow when click on map -


i'm struggling close action infowindows in rails app.

my js:

<script type="text/javascript">    $(document).ready(function(){     var raw_markers = <%=raw @hash.to_json %>;      function createsidebarli(json){       return json.sidebar;       //return ("<li>" + json.titre + ' ' + json.address + "</li>");     };      function bindlitomarker($li, marker){       $li.on('click', function(){         handler.getmap().setzoom(14);         marker.setmap(handler.getmap()); //because clusterer removes map property marker         marker.panto();         google.maps.event.trigger(marker.getserviceobject(), 'click');       });     };      function bindlitomarkermouseover($li, marker){       $li.on('mouseover', function(){         handler.getmap().setzoom(14);         marker.setmap(handler.getmap()); //because clusterer removes map property marker         marker.panto();         google.maps.event.trigger(marker.getserviceobject(), 'click');         //marker.serviceobject.seticon("/assets/marker_sprite.png");       });     };      function createsidebar(json_array){       _.each(json_array, function(json){         var $li = $( createsidebarli(json) );         $li.appendto('#markers_list');         bindlitomarker($li, json.marker);         bindlitomarkermouseover($li, json.marker);       });     };      //handler = gmaps.build('google', { builders: { marker: infoboxbuilder} });     handler = gmaps.build('google');     handler.buildmap({ internal: {id: 'map'}}, function(){        var markers = handler.addmarkers(raw_markers);        _.each(raw_markers, function(json, index){         var marker = markers[index];         json.marker = marker;         //google.maps.event.addlistener(marker.getserviceobject(), 'mouseover', function(){           //google.maps.event.trigger(marker.getserviceobject(), 'click');         //});       });        google.maps.event.addlistener(map, "click", function(){         closeinfowindow();       });         createsidebar(raw_markers);       handler.bounds.extendwith(markers);       handler.fitmaptobounds();     });    });  </script> 

i'm calling gmap event close them if user click on map doesn't work. think have change put call i'm not sure, tried everywhere.

somebody has idea ?

ps: i'm using gmaps4rails has nothing js normally.

declare function:

function closeinfowindow(handler){   if(handler.currentinfowindow()) {     handler.currentinfowindow().close();   } } 

and call it:

closeinfowindow(handler); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -