0
我試圖在地標上添加事件,但收到錯誤「文檔未定義」。當我嘗試提醒地標名稱時,它們工作正常,爲什麼不是事件呢?geoxml3在地標上添加事件
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
var geoXml = new geoXML3.parser({
map: this.map,
singleInfoWindow:true,
afterParse: this.useTheData
});
geoXml.parseKmlString(<my kml string>);
google.maps.event.addListener(this.map, "bounds_changed", RefreshMap);
google.maps.event.addListener(this.map, "center_changed", RefreshMap);
google.maps.event.addListener(this.map, "zoom_changed", RefreshMap);
},
useTheData: function(doc) {
for (var i = 0; i < doc[0].placemarks.length; i++) {
docs[0].placemarks[i].events.add("click", function() {alert("event!!");});
//alert(docs[0].placemarks[i].name);
}
}
click event not working for me。我有'doc [0] .placemarks [i]'而不是'doc [0] .placemarks [i] .marker'。當我點擊多邊形時,如何讓它像kmllayer一樣工作? – shorif2000
多邊形沒有.marker屬性,它有一個.polygon屬性,其中包含對與該地標關聯的google.maps.Polygon的引用。 – geocodezip