2014-10-16 2 views
1

누구나 GeoJsonDataSource에서 위치 데이터를 가져 오는 방법을 말해 줄 수 있습니까? 내가하는 일은 다음과 같습니다.Cesiumjs : GeoJsonDataSource에서 데이터를 반복하는 방법

entity1 = Cesium.GeoJsonDataSource.fromUrl('../../SampleData/markersdata.geojson'); 
var array1 = entity1.entities.entities;  //According to document, this should an array of entity instances, but it only returns an empty array. 
console.log(array1); 
// [] 
//If I do this: 
var assocArray = entity1.entities._entities;  //This returns an associative array 
var markersArr = assocArray.values;   //I expect this returns an array of values, but it still returns empty array. 
console.log(markersArr); 
// [] 

도움을 주셔서 감사합니다.

+0

몇 가지 질문이 있습니다. l.2'x'->'entity1'? l.3'assocArray' ->'array1'? l.6'x'->'entity1'? – dgiugg

+0

@dgiugg 답장을 보내 주셔서 감사합니다. 죄송합니다.이 질문에 오타가 있었는데 x는 entity1이어야합니다. 서버의 프로젝트에서 2 행의 entity1.entities 또는 6 행의 assocArray 멤버를 확인할 때 re는 500 개의 데이터 인스턴스입니다. – Robert

답변

6

GeoJsonDataSource.fromUrl은 아직 데이터를로드하는 중 인 새 인스턴스를 반환합니다 (isLoading 속성은 true입니다). loadingEvent 이벤트가 발생할 때까지 데이터 소스의 데이터를 사용할 수 없습니다. 이 경우 새 인스턴스를 직접 만들고 loadUrl을 사용하는 것이 더 쉽습니다. 이것은 여전히 ​​비동기 작업입니다. 그러나 데이터가 준비되면 해결 된 약속을 반환합니다. 이 작업의 예는 Cesium의 GeoJSON Sandcastle demo을 참조하십시오. 이것은 세슘뿐만 아니라 일반적으로 일반적인 패턴입니다. Cesium here에 의해 사용 된 약속 시스템에 대해 더 많이 읽을 수 있습니다.

다음은 반복 방법을 보여주는 작은 코드 조각입니다.

var dataSource = new Cesium.GeoJsonDataSource(); 
dataSource.loadUrl('../../SampleData/ne_10m_us_states.topojson').then(function() { 
    var entities = dataSource.entities.entities; 
    for (var i = 0; i < entities.length; i++) { 
     var entity = entities[i]; 
     ... 
    } 
}); 
viewer.dataSources.add(dataSource); 
관련 문제