appendChild kmz works only in second time when I r

2019-09-04 07:21发布

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条回答
beautiful°
2楼-- · 2019-09-04 07:50

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); } }

查看更多
登录 后发表回答