//视图
var viewer = new Cesium.Viewer('map', {
animation: false,
baseLayerPicker: false,
fullscreenButton: false,
geocoder: false,
homeButton: false,
infoBox: false,
sceneModePicker: false,
selectionIndicator: false,
timeline: false,
navigationHelpButton: false,
scene3DOnly: true,
sceneMode: 3,
navigationInstructionsInitiallyVisible: false,
showRenderLoopErrors: false,
imageryProvider: new Cesium.UrlTemplateImageryProvider({
url: 'http://www.google.cn/maps/vt?lyrs=s@198&gl=en&x={x}&y={y}&z={z}',
credit: '',
tilingScheme: new Cesium.WebMercatorTilingScheme(),
maximumLevel: 18,
show: false
})
});
//场景
var scene = viewer.scene;
//隐藏版权信息
viewer._cesiumWidget._creditContainer.style.display = "none";
//解决图标遮挡
viewer.scene.globe.depthTestAgainstTerrain = false;
//添加entity
var entity=viewer.entities.add({
id:data.datas[i].site_id,//站点id
name:"air",
position:Cesium.Cartesian3.fromDegrees(Number(data.datas[i].lng), Number( data.datas[i].lat),0),
billboard:{
// position:Cesium.Cartesian3.fromDegrees(Number(data.datas[i].lat),Number(data.datas[i].lng),10),
verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
image:'../images/marker/house-green1.png'
},
label: {
text: data.datas[i].pm25,
font: '14px Helvetica',
showBackground: true,
// backgroundColor: Cesium.Color.LIME,
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
// outlineWidth: 1,
horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
verticalOrigin: Cesium.VerticalOrigin.TOP,
pixelOffset : new Cesium.Cartesian2(0.0,-25),
pixelOffsetScaleByDistance : new Cesium.NearFarScalar(1.5e2, 3.0, 1.5e7, 0.5)
}
});
viewer.zoomTo(entity);
//移除所有要素
viewer.entities.removeAll()
//注销掉原来的tileset
tileset = tileset && tileset.destroy();
//添加Geojson(点)并添加图标
var promise = Cesium.GeoJsonDataSource.load("../data/point.json");
promise.then(function (dataSource) {
viewer.dataSources.add(dataSource);
var entities = dataSource.entities.values;
for (var i = 0; i < entities.length; i++) {
var entity = entities[i];
entity.billboard.image = '../images/marker/house01.png';
}
});
//移除全部数据源
var len = viewer.dataSources.length;
if(len > 0){
console.log(len)
for(var n = 0; n < len; n++){
//每删除一条viewer.dataSources,len就会减少1
viewer.dataSources.remove(viewer.dataSources.get(0));
}
}
//定位
viewer.zoomTo(viewer.entities);