我解決了這個用jQuery
HTML代碼,我選擇我的類別:
<div id="optionbar-r"><u>(Un)mark to hide/show markers</u><br>
<form id="checkbox">
<input type="checkbox" name="status" value="1" checked>cat1<br>
<input type="checkbox" name="status" value="2" checked>cat2<br>
<input type="checkbox" name="status" value="3" checked>cat3<br>
<input type="checkbox" name="status" value="4" checked>cat4<br>
</form>
</div>
標記
var marker = new gm.Marker({
position: placemark.latlng,
icon: placemark.style.icon,
category: stat
});
的.js代碼中的標記獲取所選
//checkbox elements are in div optionbar-r
var checkbox = document.getElementById("optionbar-r");
$ ("#optionbar-r").click(function() {
markerclusterer.clearMarkers();//clear clusters
var selected = new Array();
//put every checked box into array
$('#optionbar-r input:checked').each(function() {
selected.push($(this).attr('value'));
});
//iterate over markersArray and set visibility if category is in array
for(var i=0; i < markersArray.length-1; i++) {
if($.inArray(markersArray[i].category, selected) >= 0) {
markersArray[i].setVisible(true);
markerclusterer.addMarker(markersArray[i]);//recluster all visible markers
} else {
markersArray[i].setVisible(false);
}
}
});
所以基本上你需要從簇中刪除所有的標記並且只需要從你想要顯示的類別中重新設置標記