我正在从您的示例中学习Google Maps API3。顺便说一句,他们非常有帮助。我有一个问题。在您的示例中,http://www.geocodezip.com/v3_GenericMapBrowser.asp?filename=flights090414.xml如何使IRS中的标记与折线一起关闭?但我希望保持能够使用您创建的xml文件中的数据单击标记的功能。我知道它在以下代码片段中的某处。非常感谢你的帮助。
// A function to create the marker and set up the event window function
function createMarker(latlng,name,html,icon) {
var contentString = html;
var marker = new google.maps.Marker({
position: latlng,
icon: getMarkerImage(icon),
shadow: iconShadow,
map: map,
title: name,
zIndex: Math.round(latlng.lat()*-100000)<<5
});
/*
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(contentString);
infowindow.open(map,marker);
$("#tabs").tabs();
});
*/
bindInfoWindow(marker, map, infowindow, contentString);
// save the info we need to use later for the side_bar
gmarkers.push(marker);
// add a line to the side_bar html
side_bar_html += '<a href="javascript:myclick(' + (gmarkers.length-1) +
')">' + name + '<\/a><br>';
}
// This function picks up the click and opens the corresponding info
window
function myclick(i) {
google.maps.event.trigger(gmarkers[i], "click");
}
function togglePoly(poly_num) {
if (document.getElementById('poly'+poly_num)) {
if (document.getElementById('poly'+poly_num).checked) {
gpolys[poly_num].setMap(map);
} else {
gpolys[poly_num].setMap(null);
}
}
}
function createClickablePolyline(poly, html, label, point, length) {
gpolys.push(poly);
var poly_num = gpolys.length - 1;
if (!html) {html = "";}
else { html += "<br>";}
length = length * 0.000621371192; // convert meters to miles
html += "length="+length.toFixed(2)+" miles";
// html += poly.getLength().toFixed(2)+" m;
"+(poly.getLength()*3.2808399).toFixed(2)+" ft; ";
// html += (poly.getLength()*0.000621371192).toFixed(2)+" miles";
var contentString = html;
google.maps.event.addListener(poly,'click', function(event) {
infowindow.setContent(contentString);
if (event) {
point = event.latLng;
}
infowindow.setPosition(point);
infowindow.open(map);
// map.openInfoWindowHtml(point,html);
});
if (!label) {
label = "polyline #"+poly_num;
}
label = "<a
href='javascript:google.maps.event.trigger(gpolys["+poly_num+"],\"
click \");'>"+label+"</a>";
// add a line to the sidebar html
side_bar_html += '<input type="checkbox" id="poly'+poly_num+'"
checked="checked" onclick="togglePoly('+poly_num+');">' + label + '<br
/>';
}
答案 0 :(得分:0)
您还可以尝试循环gmarkers
删除/添加侦听器。一些选项是google.maps.event.removeListener(listenerHandle);
和google.maps.event.clearListeners(objectListened, 'event');