我正在尝试将标记放在不同的类别中。然后使用复选框将它们显示在地图上。我已经按照@Sonia 2年前在stackoverflow上找到的方法。
我的样本js是这样的:
var map;
var marker;
var image = [];
image['must']='icons/star.png';
var markerMust = [];
function initialize() {
var myOptions = {
center: new google.maps.LatLng(35.0086, 24.928),
zoom: 12,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
map = new google.maps.Map(document.getElementById('map_canvas'),myOptions);
marker = new google.maps.Marker({
position: new google.maps.LatLng(34.957825, 25.041315),
map: map,
title: 'placename',
clickable: true,
category: 'must',
icon: 'icons/star.png'
});
markerMust.push(marker);
$('#mustB').click(function () {
boxclick(this, 'must');
});
} //map initialization ends here
var i;
function toggleMarkers(markerMust) {
for (i=0; i<markerMust.length i++) {
if (markerMust[i].category == category) {
markerMust[i].setVisible(true);
}
}
document.getElementById(category+"box").checked = true;
}
function boxclick(box, category){
if (box.checked){
toggleMarkers(markerMust);
}
}
*确定的问题:
HTML:
<html>
<body onload="initialize()">
<div id="map_canvas" style="width:1200px; height:800px;"></div>
<form action="#">
Must Visit: <input type ="checkbox" id="mustB" onclick="boxclick(this,'must')">
</body>
</html>
答案 0 :(得分:0)
我拿走了jQuery语句,没有它就完美地运行了:D
$('#mustB').click(function () {
boxclick(this, 'must');
});