简体   繁体   English

KML DOM走路很慢! 如何避免走路的孩子?

[英]KML DOM Walking is SLOW! How To Avoid Walking Children?

I have been having some problems with performance related to navigating a KML DOM that I get from a KMZ file on a web server (using fetchKml). 与浏览从Web服务器上的KMZ文件获得的KML DOM有关的性能一直存在一些问题(使用fetchKml)。 I am using the gex.dom.walk approach described and discussed here: 我正在使用此处描述和讨论的gex.dom.walk方法:

https://developers.google.com/earth/articles/domtraversal https://developers.google.com/earth/articles/domtraversal
http://code.google.com/p/earth-api-utility-library/wiki/GEarthExtensionsDomReference http://code.google.com/p/earth-api-utility-library/wiki/GEarthExtensionsDomReference

Essentially, I am just trying to turn on/off visibility of folders when a folder name matches some criteria from a GUI click event. 本质上,当文件夹名称与GUI单击事件中的某些条件匹配时,我只是试图打开/关闭文件夹的可见性。 As I said, this works but performance is not great. 就像我说的那样,这行得通,但是性能并不理想。 It maybe takes 30 - 60 seconds for the visibility settings to be updated in the application. 在应用程序中更新可见性设置可能需要30到60秒。 I read in the links above that you can turn off the walking of children nodes and I have attempted to do this with the object literal approach below. 我在上面的链接中读到,您可以关闭对子节点的行走,而我尝试使用下面的对象文字方法来实现。 The code that I have included doesn't produce any javascript errors but it doesn't improve performance. 我包含的代码不会产生任何javascript错误,但不会提高性能。 I'm not sure if I am creating the object literal correctly and setting the walk children property properly. 我不确定是否要正确创建对象文字并正确设置walk children属性。 Any advice? 有什么建议吗? A good example of turning off the walk children property with the use of gex.dom.walk would be very helpful. 一个很好的例子,可以使用gex.dom.walk关闭walk children属性。 I couldn't find an example online. 我找不到在线示例。

These folders have a number of placemarks in them (100s) and I have 25 folders. 这些文件夹中有许多地标(100s),我有25个文件夹。 So, I would like to avoid walking them and suspect this is at least part of the culprit for the performance issues. 因此,我想避免走路,并怀疑这至少是造成性能问题的罪魁祸首。 The KMZ file is about 250 Kb and the KML inside is about 7.5 Mb. KMZ文件约为250 Kb,内部KML约为7.5 Mb。 This file will grow over time somewhat, as well. 随着时间的流逝,该文件也会有所增加。

I have also read about Gzip compression and will have to do a bit more research on that. 我还阅读了有关Gzip压缩的信息,对此将需要做更多的研究。 I suspect that might help, too. 我怀疑这可能也会有所帮助。

Thanks for any direct response or related tips! 感谢您的任何直接回复或相关提示!

function visibilityKml(context) {

    //this is called by click events on the GUI
    //if a menu item click, traverse the KML DOM to process the visibility request
    //
    //
    var gex = new GEarthExtensions(ge);
    var walkStatus = {
        walkChildren : true
    };
    gex.dom.walk({
        rootObject: ge,
        visitCallback: function(walkStatus) {
            // 'this' is the current DOM node being visited.
            if ('getType' in this && this.getType() == 'KmlFolder') {
                  if ( context.match("AXYZ") && this.getName().match("AXYZ") && this.getVisibility() == false) {
                    this.setVisibility(true);
                  }
                  else if ( context.match("AXYZ") && this.getName().match("BXYZ") && this.getVisibility() == true) {
                    this.setVisibility(false);
                  }
                  else if ( context.match("BXYZ") && this.getName().match("BXYZ") && this.getVisibility() == false) {
                    this.setVisibility(true);
                  }
                  else if ( context.match("BXYZ") && this.getName().match("AXYZ") && this.getVisibility() == true) {
                    this.setVisibility(false);
                  }
                  else if ( context.match("All XYZ") && this.getName().match("XYZ") && this.getVisibility() == false) {
                    this.setVisibility(true);
                  }
                  if ( this.getName().match("XYZ") ) {
                    this.walkChildren = false;
                  }
            }
        } 
    });
}

First: In your KML file, you need to edit these lines 第一:在您的KML文件中,您需要编辑以下行

OLD

<Folder>
      <name>Name of Folder</name>
      <Placemark>
      ..........
      </Placemark>
 </Folder>

NEW

<Folder id="unique_id">
      <name>Name of Folder</name>
      <Placemark>
      ..........
      </Placemark>
 </Folder>

Second: When you wish to toggle the visibility of this folder, use the Accessors 第二:当你想切换此文件夹中的知名度,利用存取器

Depending on how you load your KML (eg fetch,parse,networklink) you use a different Accessor. 根据您加载KML的方式(例如,提取,解析,网络链接),您可以使用其他访问器。 I am going to presume you are using fetchKml() so I suggest you look into using getElementByUrl() 我假设您正在使用fetchKml()所以建议您考虑使用getElementByUrl()

So, you end up doing something like this: (you need the # symbol) 因此,您最终会执行以下操作:(您需要使用#符号)

var url = 'http://www.domain.com/yourFile.kml';
var folder = ge.getElementByUrl(url + '#' + 'unique_id');
folder.setVisibility(true|false);

Hope that helps! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM