Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 按id编辑获取的KML元素_Javascript_Html_Dom_Kml_Google Earth Plugin - Fatal编程技术网

Javascript 按id编辑获取的KML元素

Javascript 按id编辑获取的KML元素,javascript,html,dom,kml,google-earth-plugin,Javascript,Html,Dom,Kml,Google Earth Plugin,也许有人知道为什么函数getObjectById(id)在Google earth中不起作用?我已将kml提取到DOM,但随后我尝试查找id为的元素,但它不返回任何内容 我在谷歌地球api游乐场玩,也许它不支持额外的图书馆 这是我的密码: <script src="http://www.google.com/jsapi?key=ABQIAAAAuPsJpk3MBtDpJ4G8cqBnjRRaGTYH6UMl8mADNa0YKuWNNa8VNxQCzVBXTx2DYyXGsTOxpWhvIG

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

我在谷歌地球api游乐场玩,也许它不支持额外的图书馆

这是我的密码:

<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
var url='1〕http://kml-samples.googlecode.com/svn/trunk/kml/NetworkLink/placemark.kml';
google.earth.fetchKml(ge,url,finished);
}
函数故障回调(错误代码){
}
函数getObjectById(id){
var foundObject=null;
//遍历DOM,查找具有给定ID的对象。
gex.dom.walk({
rootObject:ge,
visitCallback:函数(){
if('getId'在this&&this.getId()==id中){
foundObject=这个;
return false;//停止行走。
}
}
});
返回对象;
}
函数按钮单击(){
getObjectById(“p”);
警报(“找到:+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);

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

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

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

我是这样做的:您是否正确加载gex?ie在您的init(instance)函数中,是否先加载ge,然后加载gex:ge=instance;gex=新齿轮的伸长量(ge);为什么不使用我在回答中提到的功能呢?默认插件支持这些功能,因此不需要加载扩展(除非您在其他地方使用它们)。我正在使用这些功能,也许有一种方法可以显示所选项目,如“警报(对象)”?我找不到一种方法来检查它是否在我的应用程序上工作,因为服务器是Ubuntu:)它完成了工作:)也许你知道一种快速的方法来设置fethed kml的视图?我是根据这个方法来做的:你正确加载了gex吗?ie在您的init(instance)函数中,是否先加载ge,然后加载gex:ge=instance;gex=新齿轮的伸长量(ge);为什么不使用我在回答中提到的功能呢?默认插件支持这些功能,因此不需要加载扩展(除非您在其他地方使用它们)。我正在使用这些功能,也许有一种方法可以显示所选项目,如“警报(对象)”?我找不到一种方法来检查它是否在我的应用程序上运行,因为服务器是Ubuntu:)它完成了任务:)也许你知道一种快速设置fethed kml视图的方法吗?