1

我使用谷歌地图 api v3 设计了一个功能齐全的地图,但是我想使用谷歌地球插件创建完全相同的地图。地图可以在这里找到

我已经设法在 GE - 各大洲和地区加载了 kml 文件。我怎么无法让点击事件工作。不知道这是如何工作的以下是我目前拥有的

google.earth.addEventListener(kmlLayer,'click',function(kmlEvent) {
            kmlEvent.preventDefault(); 
            console.log("help");


            $('#balloon').html("");
            kmlClick = true;
            var surveyid = kmlEvent.featureData.id;

            if(!updateSurveyFlag){
                updateSurveyView(surveyid, updateSurveyFlag);
            }
            console.log("help2");
            $.ajax({
                url : 'http://' + top.location.host + '/mcmap/feed/kml.php?action=kmlclick',
                data : "id=" + surveyid,
                dataType : 'json',
                success : function(data) {

控制台记录帮助后没有任何执行。我想使用 GE,因为性能比 GM 好得多,但前提是我使用网络链接。如果我使用了 fetch kml 方法,则使用此问题中提到的扩展进行放大会很慢

4

1 回答 1

0

很可能是您对 jquery 的调用$('#balloon').html("");失败了。可能是您尝试在 jquery 正确加载之前调用代码。

要解决此问题,请确保在加载完成后对 jquery 进行任何调用。

另外,另一方面,我会尝试通过用命名方法替换匿名函数来分离调用。这种分离不会改变功能,它只是通过避免过度嵌套来保持代码更清晰。

// called when jquery and the document have finished loading
$(function() {
  google.earth.addEventListener(kmlLayer,'click', myEventListener);
});

// custom event listener
var myEventListener = function(kmlEvent) {
  kmlEvent.preventDefault(); 
  console.log("help");
  $('#balloon').html(""); // should work now as jquery is ready.
  kmlClick = true;
  var surveyid = kmlEvent.featureData.id;
  if(!updateSurveyFlag) {
    updateSurveyView(surveyid, updateSurveyFlag);
  }

  console.log("help2");

  // etc...
}
于 2012-11-29T00:41:42.993 回答