gpt4 book ai didi

javascript - KML DOM 行走很慢!如何避免 child 走路?

转载 作者:行者123 更新时间:2023-11-28 02:28:11 27 4
gpt4 key购买 nike

我在导航从 Web 服务器上的 KMZ 文件(使用 fetchKml)获取的 KML DOM 时遇到了一些性能问题。我正在使用此处描述和讨论的 gex.dom.walk 方法:

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

本质上,我只是想在文件夹名称与 GUI 单击事件中的某些条件匹配时打开/关闭文件夹的可见性。正如我所说,这可行,但性能不是很好。应用程序中的可见性设置更新可能需要 30 - 60 秒。我在上面的链接中读到,您可以关闭子节点的行走,并且我尝试使用下面的对象文字方法来执行此操作。我包含的代码不会产生任何 JavaScript 错误,但不会提高性能。我不确定我是否正确创建了对象文字并正确设置了 walk 子属性。有什么建议吗?使用 gex.dom.walk 关闭 walk child 属性的一个很好的例子将非常有帮助。我在网上找不到示例。

这些文件夹中有许多地标(100 个),我有 25 个文件夹。因此,我想避免步行它们,并怀疑这至少是性能问题的部分罪魁祸首。 KMZ 文件大约 250 Kb,里面的 KML 大约 7.5 Mb。该文件也会随着时间的推移而有所增长。

我还阅读了有关 Gzip 压缩的内容,并且需要对此进行更多研究。我怀疑这也可能有帮助。

感谢您的直接回复或相关提示!

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

最佳答案

首先:在您的 KML 文件中,您需要编辑这些行

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

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

第二:当您希望切换此文件夹的可见性时,请使用 Accessors

根据您加载 KML 的方式(例如获取、解析、网络链接),您可以使用不同的访问器。我假设您正在使用 fetchKml() 所以我建议您考虑使用 getElementByUrl()

所以,你最终会做这样的事情:(您需要 # 符号)

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

希望有帮助!

关于javascript - KML DOM 行走很慢!如何避免 child 走路?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14573627/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com