Javascript Cesiumjs:如何从GeoJsonDataSource迭代数据
谁能告诉我如何从GeoJsonDataSource获取位置数据?以下是我正在做的:Javascript Cesiumjs:如何从GeoJsonDataSource迭代数据,javascript,cesium,Javascript,Cesium,谁能告诉我如何从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 onl
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);
// []
非常感谢你的帮助
GeoJsonDataSource.fromUrl
返回仍在加载数据过程中的新实例(isLoading属性将为true)。在触发loadingEvent
事件之前,无法使用数据源中的数据。在这种情况下,自己创建新实例并使用loadUrl
更容易。这仍然是一个异步操作;但它返回的承诺在数据准备就绪时得到解决。参见铯的例子这样做。这是一种常见的模式,不仅在铯中,而且在JavaScript中也是如此。您可以阅读更多有关铯使用的promise系统的信息
下面是一小段代码,向您展示了如何进行迭代
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);
var dataSource=new Cesium.GeoJsonDataSource();
dataSource.loadUrl('../../SampleData/ne_10m_us_states.topojson')。然后(函数(){
var entities=dataSource.entities.entities;
对于(变量i=0;i
几个可能是打字错误的问题:l.2x
->entity1
?l、 3assocArray
->array1
?l、 6x
->entity1
?@dgiugg感谢您的回复。抱歉,这是一个问题的输入错误,x应该是entity1。在服务器上的项目中,当我检查第2行中entity1.entities的成员或第6行中assocArray的成员时,它们中的re是500个数据实例。