使用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