//--------geojson
var geojsonOptions={ //让地图贴地
clamToGround:true
};
var neighborhoodsPromise = Cesium.GeoJsonDataSource.load('./assets/china_zz_20191009.json',geojsonOptions); //加载资源
var neighborhoods;
neighborhoodsPromise.then(function (dataSource) { //把数据加到场景里面去
viewer.dataSources.add(dataSource);
neighborhoods = dataSource.entities;
var neighborhoodsEntities = dataSource.entities.values;
for (var i = 0; i < neighborhoodsEntities.length; i++) {
var entity = neighborhoodsEntities[i];
if(Cesium.defined(entity.polygon)){
entity.name = entity.properties.neighborhood;
entity.polygon.material = Cesium.Color.fromRandom({ //修改每一个多边形得材质
red: 1,
maximumGreen: 1,
maximumBlue: 1,
alpha : 1.0
});
entity.polygon.classificationType = Cesium.ClassificationType.TERRAIN; //区块直接贴在地面上
var polyPostions = entity.polygon.hierarchy.getValue(Cesium.JulianDate.now()).positions; //从多边形上取出他的顶点
var polyCenter = Cesium.BoundingSphere.fromPoints(polyPostions).center; //通过顶点构建一个包围球
polyCenter = Cesium.Ellipsoid.WGS84.scaleToGeodeticSurface(polyCenter); //把包围球得中心做贴地得偏移
entity.position = polyCenter;
entity.label = { //创建一个标签,在中心点位置
text : entity.name,
showBackground : true,
scale:0.6,
horizontalOrigin:Cesium.HorizontalOrigin.CENTER,
verticalOrigin:Cesium.verticalOrigin.BOTTOM,
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(10.0,8000.0),
disableDepthTestDistance:100.0
};
}
}
})
Cesium加载geojson数据展示区块
最新推荐文章于 2024-08-08 22:44:32 发布