2

我必须使用 google earth 插件在我的网站中显示大型 kml 文件。模型似乎总是正确下载但未显示:有时我必须右键单击插件 5 或 6 次才能看到正在显示的模型。之后,如果我重新加载页面,它会正确显示。

我正在使用以下代码:

<script type="text/javascript" >
google.load("earth", "1");
var ge;
function init() {
    google.earth.createInstance('map3D', initCB, failureCB);
}

function initCB(instance) {
    ge = instance;
    ge.getWindow().setVisibility(true);
    ge.getNavigationControl().setVisibility(ge.VISIBILITY_SHOW);

    google.earth.fetchKml(ge, "<?php echo $kmz ?>", function(kmlObject) {
        if (kmlObject)
            {
                var la = ge.createLookAt('');
                la.set(<?php echo $lat ?>, <?php echo $long ?>, <?php echo $alt+500 ?>, ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 45, 10);
                ge.getView().setAbstractView(la);

                ge.getFeatures().appendChild(kmlObject);


            }
    });


 }
     function failureCB(errorCode) {
        alert("failure");
}

google.setOnLoadCallback(init);  
</script>

我也尝试使用 createNetworkLink 但问题仍然存在。我应该改变什么才能让它工作?

谢谢!

4

1 回答 1

1

It is simply the model taking time to load into the plug-in that is causing the problem. I have tested it in a number of browsers on a few OSs and the behaviour is the same in all cases.

The reason it works on subsequent page reloads is that the plug-in is caching the data so it isn't actually fetching the data a second time.

The zooming out, zooming in isn't doing anything to load the model any faster - it is simply passing the time until it loads.

On every test I have done the model always loads - but can take between 2 and 10 seconds to display...

There isn't a great deal you can do about this other than to try and optimise the .dae and image file within your KMZ archive to reduce the file size. This will make the model load and display faster than it currently does.

于 2013-01-05T23:12:21.933 回答