javascript - How to filter markers using gmaps4rails gem -


i using gmaps4rails gem, rails 4.0.8, underscore.js , can't seem marker filter working correctly. filter, 1 category @ time (refreshes whole map) , not save markers hidden.

my code based on this example.

the code posted below:

$(document).ready(function(){   handler = gmaps.build('google');   handler.buildmap({ internal: {id: 'map'}}, function(){     var markers_json = <%=raw @hash.to_json %>;     var markers = handler.addmarkers(markers_json);     handler.bounds.extendwith(markers);     handler.fitmaptobounds();   }); });  // show markers  function show(category) {    handler.buildmap({ internal: {id: 'map'}}, function(){   var markers_json = <%=raw @hash.to_json %>;   var markers = _.map(markers_json, function(marker_json){     var marker = handler.addmarker(marker_json);     _.extend(marker, marker_json);     return marker;   });    _.each(markers, function(marker, index){     var pin = markers[index];     if (pin.cat == category) {       marker.show();     }    });    handler.bounds.extendwith(markers);   handler.fitmaptobounds();  });  // check checkbox, using consulting testing document.getelementbyid(category+'box').checked = true;  }  // hide markers function hide(category) { // similar show, except uses marker.hide();  }  function boxclick(box,category) {   if (box.checked) {     show(category);   } else {     hide(category);   } } 

i'm not sure how save array of markers , when try buildmap after (so there aren't 3 instances of it) end breaking map. i've been trying different ways filter working driving me crazy.

any suggestions or direction help. thank you!


Comments

Popular posts from this blog

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

node.js - Using Node without global install -

java - JavaScript + Thymeleaf - select onchange -