チェックボックスをクリックしてもグループマーカーは表示されませんが、すべてのマーカーとすべてのグループが表示されます。「T^T」で検索するとかなり時間がかかります。
<script type="text/javascript">
//<![CDATA[
var customIcons = {
"01": {
icon: 'http://labs.google.com/ridefinder/images/mm_20_purple.png',
shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
},
"02": {
icon: 'http://labs.google.com/ridefinder/images/mm_20_green.png',
shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
},
"03": {
icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png',
shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
},
"04": {
icon: 'http://labs.google.com/ridefinder/images/mm_20_brown.png',
shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
}
};
function load() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(13.754059,100.493317),
zoom: 13,
mapTypeId: 'roadmap'
});
var infoWindow = new google.maps.InfoWindow;
// Change this depending on the name of your PHP file
downloadUrl("dbxml.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var name_place = markers[i].getAttribute("name_place");
var id_category = markers[i].getAttribute("id_category");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("latitude")),
parseFloat(markers[i].getAttribute("longitude")));
var html = "<b>" + name_place ;
var icon = customIcons[id_category] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon,
shadow: icon.shadow
});
bindInfoWindow(marker, map, infoWindow, html);
}
});
}
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
}
var markerGroups = { "01": [], "02": [] , "03": [] , "04": [] };}
function toggleGroup(id_category) {
for (var i = 0; i < markerGroups[id_category].length; i++) {
var marker = markerGroups[id_category][i];
markerGroups[id_category].push(marker);
if (marker.isHidden()) {
marker.show();
} else {
marker.hide();
}
}
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
//]]>
これはチェックボックスです
<p>
<label>
<input type="checkbox" id="01" onclick="toggleGroup('01')"CHECKED/>
</label>
01
<label>
<input type="checkbox" id="02" onclick="toggleGroup('02')" CHECKED/>
</label>
02
<label>
<input type="checkbox" id="03" onclick="toggleGroup('03')" CHECKED/>
</label>
03
<label>
<input type="checkbox" id="04" onclick="toggleGroup('04')" CHECKED/>
</label>
04</p>
すべてのマーカーを表示していますが、「チェックボックス」をクリックすると、グループごとにマーカーが表示されません。