gpt4 book ai didi

javascript - 按 id 编辑获取的 KML 元素

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

也许有人知道为什么函数 getObjectById(id) 在 Google 地球中不起作用?我已将 kml 提取到 DOM,但随后我尝试找到带有 id 的元素,但它没有返回任何内容。

我正在 google Earth api Playground 中玩,也许它不支持额外的库?

这是我的代码:

<script src="http://www.google.com/jsapi?key=ABQIAAAAuPsJpk3MBtDpJ4G8cqBnjRRaGTYH6UMl8mADNa0YKuWNNa8VNxQCzVBXTx2DYyXGsTOxpWhvIG7Djw" type="text/javascript"></script>
<script src="http://earth-api-utility-library.googlecode.com/svn/tags/extensions-0.2.1/dist/extensions.pack.js" type="text/javascript"></script>
<script type="text/javascript">

................


// fetch the KML
var url = 'http://kml-samples.googlecode.com/svn/trunk/kml/NetworkLink/placemark.kml';
google.earth.fetchKml(ge, url, finished);
}

function failureCallback(errorCode) {
}

function getObjectById(id) {
var foundObject = null;

// Traverse the DOM, looking for the object with the given ID.
gex.dom.walk({
rootObject: ge,
visitCallback: function() {
if ('getId' in this && this.getId() == id) {
foundObject = this;
return false; // Stop the walk.
}
}
});

return foundObject;
}

function buttonClick() {
getObjectById("p");
alert("Found:" +foundObject);
}

KML 已加载,按钮可以工作,但看起来像 getObjectById("p");不起作用...

最佳答案

首先,我认为没有 getObjectById(),您很可能需要使用 getElementByUrl()getElementById()

由于您使用的是 fetchKml,我认为您应该像这样使用 getElementByUrl() :

var url = 'http://kml-samples.googlecode.com/svn/trunk/kml/NetworkLink/placemark.kml';
var object = ge.getElementByUrl(url + '#' + id);

See this page for details

关于javascript - 按 id 编辑获取的 KML 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13672782/

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