开发者

Google Earth Plugin: setTour() AFTER setAbstractView() is done rendering

开发者 https://www.devze.com 2023-02-25 11:51 出处:网络
Using the Google Earth Plugin, I am attempting to load a KML file, look for and render its LookAt component, and after the view has finished rendering, load the tour

Using the Google Earth Plugin, I am attempting to load a KML file, look for and render its LookAt component, and after the view has finished rendering, load the tour controls.

I am not fluent in javascript, and am not sure if the problem I am running into is javascript idiocy (mine) or ignorance of the way the GEP works. When reading the docs, did not see any "endevent" that the GEP gives for go.getView().setAbstractView()...

So, I tried the simplest thing I could think of... a timeout. It loads the kml and renders the kml LookAt, but does not load tour controls at all. If I delete the if / timeout structure, the GEP cancels rendering the setAbstractView and immediately loads the tour controls. Any ideas?

            function whenloaded(kmlObject) {
                    if (!kmlObject) {
                            setTimeout(function() {
                                    alert('Bad or Null KML file');
                            }, 0);
                            return;
                    }

                    ge.getFeatures().appendChild(kmlObject);

                    if (kmlObject.getAbstractView() !== null) {
               开发者_如何学Go             ge.getView().setAbstractView(kmlObject.getAbstractView());
                    }

                    // Walk the DOM looking for a KmlTour
                    walkKmlDom(kmlObject, function() {
                            if (this.getType() == 'KmlTour') {
                                    tour = this;
                                    return false; // stop the DOM walk here.
                            }
                    });

            }

            var url = 'url/to/file.kml';

            google.earth.fetchKml(ge, url, whenloaded());

            if (timeout !== null)
                    ge.getTourPlayer().setTour(tour);

            // wait for 5000 ms
            timeout = window.setTimeout(function() {
                    vcTimeout = null;
            }, 5000); 


Yeah, it was javascript... the corrected js is answered in the GEP group here, but this timeout method is still much too naive.

0

精彩评论

暂无评论...
验证码 换一张
取 消