【问题标题】:GM markers on/off based on categories & checkboxes基于类别和复选框的 GM 标记开/关
【发布时间】:2013-07-04 11:05:18
【问题描述】:

我正在尝试在不同类别中添加标记,然后使用复选框将它们显示在地图上。我遵循了 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>

【问题讨论】:

  • 地图再次运行,但没有包含不同的类别(类别数组),也没有 push.markers...

标签: javascript google-maps checkbox filter google-maps-markers


【解决方案1】:

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

$('#mustB').click(function () {
boxclick(this, 'must');
}); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-15
    • 2016-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-14
    相关资源
    最近更新 更多