0

我试图在不同的类别中有标记,然后使用复选框在地图上显示它们。我遵循了2 年前@Sonia在 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);
}
}

*发现的问题:

  • 地图没有开始
  • 标记声明是否适用于类别;之后是否正确调用了标记类别?
  • 不确定函数 toggleMarkers() 语法是否正确,因为不存在对代码的进一步添加
  • 这是 100 多个标记图的示例,仅显示一个类别,其余类别采用相同的方法

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>
4

1 回答 1

0

我拿走了 jQuery 语句,没有它它也能完美运行:D

$('#mustB').click(function () {
boxclick(this, 'must');
}); 
于 2013-07-19T19:35:36.973 回答