[英]Google Maps API3 - Making Google Markers Clickable, Polylines are already clickable (turn on and off via radiobox)
我正在從您的示例中學習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
/>';
}
您還可以嘗試在gmarkers
刪除/添加偵聽器的循環。 google.maps.event.removeListener(listenerHandle);
是幾個選項google.maps.event.removeListener(listenerHandle);
和google.maps.event.clearListeners(objectListened, 'event');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.