appendChild kmz works only in second time when I run a tour (tour is into the same kmz)

家住魔仙堡 提交于 2019-12-25 02:15:07

问题


I have a KMZ file for GE plugin. This file have lots of PNG into, and several kml (poligons, lines, placemarks, etc).

The function to run this tour is:

function loadKmztour(href){
google.earth.fetchKml(ge, kmlURL, function(kmlObject) {
     if (kmlObject){
        ge.getFeatures().appendChild(kmlObject);
        walkKmlDom(kmlObject, function(context) {
            if (this.getType() == 'KmlTour') {
                ge.getTourPlayer().setTour(this);
                ge.getTourPlayer().play();
            }
        });
    });

}

It runs well, but only the second time when I run the tour. When I run it for first time, it run only the tours but doesn't show the poligons, placemarks and png, but if I click the tour for second time, it work fine.

How can I force the kmz info to load at first time?

Thank you for any help. Best Regards, Shunsho.

UPDATE: Sometimes, the kmz poligons and placemarks load at the first time...but it work only sometimes...I think that maybe the tour started to run before the kmz is appended, so the problem is how I can force to wait the appendChild and then run the tour...Thanks!


回答1:


try to wait until the kml is loaded before playing the tour. I use this code:

var interval = setInterval(function wait() { var streamingPercent = ge.getStreamingPercent(); if(streamingPercent > 98) { ge.getTourPlayer().setTour(tour); ge.getTourPlayer().play(); clearInterval(interval); } }



来源:https://stackoverflow.com/questions/13243301/appendchild-kmz-works-only-in-second-time-when-i-run-a-tour-tour-is-into-the-sa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!