Ragazzi, io ho una seria di checkbox che hanno un determinato valore, al click vorrei che nella mappa mi fossero mostrati solo le checkbox selezionate, e fino a qui ci sono, funziona benissimo, il problema sta nel rimuovere il marker dalla mappa come posso fare?
E' ovvio che deve eliminare solo i marker appartenete alla checkbox in seguito deselezionata.
codice:
<input class="chek" type="checkbox" value="1" />Alberghi
<input class="chek" type="checkbox" value="3" />Case Vacanze
<input class="chek" type="checkbox" value="4" />Shopping
<input class="chek" type="checkbox" value="5" />Ristorazione
<script type="text/javascript">
(function() {
window.onload = function(){
var latlng = new google.maps.LatLng(37.8530665, 15.287916300000006);
var options = {
zoom: 14,
center: latlng,
backgroundColor: '#fff',
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map_canvas'), options);
$(".chek").click(function() {
var id_checkbox = $(this).val();
var markers = [];
function AddMarker(lat,name,icon,id) {
marker = new google.maps.Marker({
animation: google.maps.Animation.DROP,
position: lat,
map: map,
icon: icon,
title: name
});
markers[id] = marker;
}
if($(this).is(':checked')) {
$.post("ajax.php",{ type:id_checkbox,page: "mapHome" }, function(data) {
for (i=0; i < data.marker.length; i++) {
var lat = new google.maps.LatLng(data.marker[i].latitude, data.marker[i].longitude);
AddMarker(lat, data.marker[i].nome, data.marker[i].marker, data.marker[i].id_cat);
}// ciclo for
},"json");//ajax
} else {
//devo rimuovere marker
}
});
}
})();
</script>