使用Google地球我有一個加載的kml圖層,顯示美國每個縣的多邊形。點擊一個氣球時彈出一些關於狀態的相關信息(名稱,哪個狀態,區域等)當用戶單擊多邊形時,我希望信息也可以在其他地方的DIV元素上彈出。無法將事件偵聽器附加到kml圖層的多邊形
這是我的代碼到目前爲止。
var ge;
google.load("earth", "1");
function init() {
google.earth.createInstance('map3d', initCB, failureCB);
}
function initCB(instance) {
ge = instance;
ge.getWindow().setVisibility(true);
ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
ge.getNavigationControl().setStreetViewEnabled(true);
ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);
//here is where im loading the kml file
google.earth.fetchKml(ge, href, function (kmlObject) {
if (kmlObject) {
// show it on Earth
ge.getFeatures().appendChild(kmlObject);
} else {
setTimeout(function() {
alert('Bad or null KML.');
}, 0);
}
});
function recordEvent(event) {
alert("click");
}
// Listen to the mousemove event on the globe.
google.earth.addEventListener(ge.getGlobe(), 'click', recordEvent);
}
function failureCB(errorCode) {}
google.setOnLoadCallback(init);
我的問題是,當我改變ge.getGlobe()
到kmlObject或ge.getFeatures()
這是行不通的。
我的第一個問題是,當用戶點擊kml圖層的多邊形時,我應該如何將ge.getGlobe()更改爲能夠獲取點擊偵聽器?
之後我打算使用getDescription()
或getBalloonHtml()
來獲取多邊形氣球信息。我是否在正確的軌道上?
嘿,這非常有幫助,非常感謝你......我結束了第一個選擇 – RidinAGrvyTrain