如果我有一个非常大的 KML 文件,如何优化 Google 地球网络插件的加载时间?

发布于 2025-01-04 22:49:26 字数 2033 浏览 2 评论 0原文

我的客户有一个非常大的 KML 文件,它包含大约 6000 多个地标,这些地标必须在地图上显示为 3D 模型。更糟糕的是,KML 文件不包含 COLLADA 文件的 标记,这意味着我必须遍历 KML 文件并附加 COLLADA 文件才能在 google 上显示地球。现在我已经可以遍历每个地标并为其添加 3D 模型。我用一个非常小的 KML 文件(包含不到 100 个地标)对其进行了测试,它按预期工作得很好......但是当我使用非常大的 KML 文件(其中包含 6000 多个地标)时,插件崩溃了并且建议我刷新浏览器,却发现它再次崩溃......:(

对此有什么建议吗? 我可以在 Google Earth 网络插件上放置的地标数量是否有限制? 如何使加载速度更快?

function render3DPoles(polesKmlLink){

                google.earth.fetchKml(ge,polesKmlLink, function(object){
            if(object){
                var item = object.getFeatures().getChildNodes().item(0);
                    var folder = item.getFeatures().getChildNodes();

                var latitude;
                var longitude;

                      for(var i = 0; i<folder.getLength(); i++){

                    var placemark = folder.item(i);

                    latitude = placemark.getGeometry().getLatitude();
                    longitude = placemark.getGeometry().getLongitude();

                        var model = ge.createModel('');
                    var location = ge.createLocation('');

                    model.setLocation(location);
                    var link = ge.createLink('');


                    link.setHref('insert URL of collada file here');
                    model.setLink(link);

                        location.setLatitude(latitude);
                        location.setLongitude(longitude);
                        model.setLocation(location); 
                        placemark.setGeometry(model);

                     ge.getFeatures().appendChild(placemark);
                     }

                     var la = ge.createLookAt('');
                     la.set(latitude,longitude, 25, ge.ALTITUDE_RELATIVE_TO_GROUND,180, 60, 100);
                     ge.getView().setAbstractView(la);

                } else {
                    setTimeout(function() {
                      alert('Bad or null KML.');
                      },0);
                }
            });
        }

My client has a very large KML file, it contains around 6000+ placemarks and these placemarks have to appear as 3D models on the map. What's even worse is that the KML file does not contain that <link> tag for the COLLADA file, which means I have to traverse the KML file and attach a COLLADA file before it can be displayed on google earth. Now I can already traverse and add a 3D model for each placemark. I tested it with a very small KML file(which contains like less than 100 placemarks) and it worked great as expected...but when I used the very large KML file which had like 6000+ placemarks on it, the plugin just crashes and I am advised to refresh the browser, only to find it crashing again... :(

Any advice on this?
Is there a limit to the number of placemarks I can put on google earth web plugin?
How do I make the loading faster?

function render3DPoles(polesKmlLink){

                google.earth.fetchKml(ge,polesKmlLink, function(object){
            if(object){
                var item = object.getFeatures().getChildNodes().item(0);
                    var folder = item.getFeatures().getChildNodes();

                var latitude;
                var longitude;

                      for(var i = 0; i<folder.getLength(); i++){

                    var placemark = folder.item(i);

                    latitude = placemark.getGeometry().getLatitude();
                    longitude = placemark.getGeometry().getLongitude();

                        var model = ge.createModel('');
                    var location = ge.createLocation('');

                    model.setLocation(location);
                    var link = ge.createLink('');


                    link.setHref('insert URL of collada file here');
                    model.setLink(link);

                        location.setLatitude(latitude);
                        location.setLongitude(longitude);
                        model.setLocation(location); 
                        placemark.setGeometry(model);

                     ge.getFeatures().appendChild(placemark);
                     }

                     var la = ge.createLookAt('');
                     la.set(latitude,longitude, 25, ge.ALTITUDE_RELATIVE_TO_GROUND,180, 60, 100);
                     ge.getView().setAbstractView(la);

                } else {
                    setTimeout(function() {
                      alert('Bad or null KML.');
                      },0);
                }
            });
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

过气美图社 2025-01-11 22:49:26

我已经在地球插件中处理过 10,000 个地标和其他 kml 对象,我发现最好的方法是在 javascript 对象中管理数据。在标准 KML 中处理它们常常会使事情崩溃。

事先将 kml 解析为可以作为对象处理的内容,开头

为:

var myModels = {};

如果 id 为“foo”或数字,则添加第一项,执行以下操作:

myModels['foo'] = { 
     description: 'some description for foo', 
     longitude: 100.12345,
     latitude: 45.4567
     linkUrl: 'http://mydomain.com/mymodels/foo.dae', 
     kmlObject: null};

现在查看代码:

http://code.google.com/apis/ajax/playground/?exp=earth#creating_3d_models

您将看到类似以下内容:

var placemark = ge.createPlacemark('');
  placemark.setName('model');
  var model = ge.createModel('');
.......
placemark.setGeometry(model);

现在开始:

myModals['foo'].kmlObject = placemark;

这将为您提供快速参考如果您需要更改或删除模型,则

myModels['foo'].kmlObject 

无需再次遍历树。

我发现更快的一件事是定义 kml 客户端并使用 parseKml 加载它,而不是创建单独的对象并添加它们。

您还可以构建逻辑,仅添加用户正在查看的区域内的 dae 模型,

以循环遍历所有项目,

var i, iModel;

for (i in myModels){
   iModel = myModels[i];

   if(myModels[m].kmlObject == null){  
       'add if statement to check if the models long/lats are in current view with
        ' iModel.longitude,  iModel.latitude
   } 
}

而不是在一次操作中添加所有内容,在单个批次中添加 10-20 个模型并使用 setTimeout一秒钟后启动另一个批处理操作并利用 .executeBatch

https://developers.google.com/earth/documentation/reference/google_earth_namespace#ab26414915202d39cad12bcd5bd99e739

I have dealt with dealing 10,000s of placemarks and other kml objects in the earth plugin and the best way I find is manage the data in a javascript object. dealing with them in standard kml would often crash things.

parse the kml before hand into something that you can handle as an object

start with:

var myModels = {};

for adding the first item if the id is 'foo' or a numeric do something like:

myModels['foo'] = { 
     description: 'some description for foo', 
     longitude: 100.12345,
     latitude: 45.4567
     linkUrl: 'http://mydomain.com/mymodels/foo.dae', 
     kmlObject: null};

now looking at the code from:

http://code.google.com/apis/ajax/playground/?exp=earth#creating_3d_models

you will have something similar to:

var placemark = ge.createPlacemark('');
  placemark.setName('model');
  var model = ge.createModel('');
.......
placemark.setGeometry(model);

now go:

myModals['foo'].kmlObject = placemark;

this will give you a quick reference to the model if you need to change it or remove it with just

myModels['foo'].kmlObject 

no need to traverse the tree again.

one thing I found to be faster was to define kml client side and use parseKml to load it rather then create individual objects and add them.

also you can build in logic to only add the dae model that are within the area the user is looking at

to loop through all the items

var i, iModel;

for (i in myModels){
   iModel = myModels[i];

   if(myModels[m].kmlObject == null){  
       'add if statement to check if the models long/lats are in current view with
        ' iModel.longitude,  iModel.latitude
   } 
}

also rather than add everything in one operation, add 10-20 model in a single batch and use setTimeout to start another batch operation a second later and leverage .executeBatch

https://developers.google.com/earth/documentation/reference/google_earth_namespace#ab26414915202d39cad12bcd5bd99e739

给不了的爱 2025-01-11 22:49:26

虽然没有技术限制,但添加的越多,使用的资源就越多。根据模型和其他数据的复杂性,您可以添加更多或更少的内容,但即使对于简单的标记,一次显示 6000 个也相当多。

针对大型/复杂 KML 的一种解决方案是创建区域化 KML,以便您根据可见区域在任何给定时间仅加载所需的数据(请参阅 http://code.google.com/apis/kml/documentation/regions.html )

While there's no technical limit, the more you add the more resources get used. Depending on the complexity of your models and other data, you will be able to add more or less, but 6000 is quite a lot of to display at once even for simple markers.

One solution for a large/complex KML is to create regionated KMLs instead, such that you are loading just the data you need at any given time, based on visible regions (see http://code.google.com/apis/kml/documentation/regions.html )

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文