2012-12-02 3 views
1

어쩌면 누군가 getObjectById (id) 함수가 Google 어스에서 작동하지 않는 이유가 있을지 모릅니다. DOM에 kml을 가져 왔지만, id가있는 요소를 찾으려고 시도했지만 아무 것도 반환하지 않습니다.가져온 KML 요소를 id로 편집하십시오.

Google 어스 API 놀이터에서 놀고 있는데, 아마도 여분의 lybrary를 지원하지 않습니까? 여기

내 코드입니다 :

<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")처럼 보인다; 당신이 가장 가능성 중 하나 getElementByUrl() 또는 getElementById()

당신이 fetchKml는을 사용하고 있기 때문에, 당신이 같은 getElementByUrl()를 사용한다고 생각 사용해야합니다, 나는 getObjectById() 있다고 생각하지 않습니다, 첫째 ...

답변

1

작동하지 않습니다 이 :이에 따라 그 일을했다

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

See this page for details

+0

: (https://developers.google.com/earth/articles/domtraversal) – sauletasmiestas

+0

[구글 어스 DOM 액세스] 당신입니다 제대로 gex로드? 즉 init (인스턴스) 함수에서 먼저 ge을로드 한 다음 gex를 다음과 같이로드합니다. ge = instance; gex = new GEarthExtensions (ge); – lifeIsGood

+0

왜 내가 응답에서 언급 한 함수를 사용하지 않는가? 그들은 기본 플러그인에서 지원되므로 Extension을로드 할 필요가 없다. (다른 곳에서 사용하지 않는 한) – lifeIsGood

관련 문제