i need to filter my google maps markers. right now, i generate a map with the help of the jquery-ui-map plugin. this is my markup:
<div id="map_canvas" class="map" style="width:100%; height:600px"></div>
<ul id="verkaufsstellen">
<li data-gmapping='{"id":"2","latlng":{"lat":52.4885039,"lng":13.3530732},"tags":"Salatfritz"}'>
<div class="info-box"><div class="box-inner"><p><strong>ÄHRENSACHE</strong><br />Apostel-Paulus Str. 40 - 10823 Berlin</p><i>vertreibt: Salatfritz</i></div></div>
</li>
<li data-gmapping='{"id":"5","latlng":{"lat":52.524268,"lng":13.40629},"tags":"Bierbier"}'>
<div class="info-box"><div class="box-inner"><p><strong>Bier, Bier Test</strong><br />Ein wunderbarer Testeintrag</p><i>vertreibt: Bierbier</i></div></div>
</li>
</ul>
and thats my js:
if ($("#map_canvas").length){
$('#map_canvas').gmap({'zoom':24,'scrollwheel':false,styles:[{stylers:[{lightness:7},{saturation:-100}]}],option:[{scrollwheel:false}]}).bind('init', function(ev, map) {
$("[data-gmapping]").each(function(i,el) {
var data = $(el).data('gmapping');
$('#map_canvas').gmap('addMarker', {'id': data.id, 'tags':data.tags, 'position': new google.maps.LatLng(data.latlng.lat, data.latlng.lng), 'bounds':true }, function(map,marker) {
$(el).click(function() {
$(marker).triggerEvent('click');
});
}).click(function() {
$('#map_canvas').gmap('openInfoWindow', { 'content': $(el).find('.info-box').html() }, this);
});
});
});
$('#map_canvas').gmap('find', 'markers', { 'tags': 'Salatfritz' }, function(marker, found) {
marker.setVisible(found);
});
}
so the last part of the js-code is something i foudn on the documentation, which isn't that good or maybe i'm to stupid to figure it out.
my aim is to filter after the "tags" - so i need a simple list, where i could on one link ant just the markers with this special tag are shown.
maybe u have got some good advice for getting it done?
Your passing the tag(s) as a string, but you have to pass them in an array in order to make it work.
Assuming you'll need multiple tags on an instance, you'd do something like:
<li data-gmapping='{"id":"2","latlng":{"lat":52.4885039,"lng":13.3530732},"tags":"Salatfritz,Bierbier"}'><!--MORE STUFF--></li>
and then:
var tagArray = data.tags.split(",");
$('#map_canvas').gmap('addMarker', {'id': data.id, 'tags':tagArray, 'position': new google.maps.LatLng(data.latlng.lat, data.latlng.lng), 'bounds':true }, function(map,marker) {
/*DO STUFF*/
});
Now you should be able to find the marker by either doing
$('#map_canvas').gmap('find', 'markers', { 'tags': 'Salatfritz' }, function(marker, found) {
marker.setVisible(found);
});
or
$('#map_canvas').gmap('find', 'markers', { 'tags': 'Bierbier' }, function(marker, found) {
marker.setVisible(found);
});
hope that helps.