Cesium加载各种类型数据的图层(JS实现)

x33g5p2x  于2022-04-27 转载在 其他  
字(1.9k)|赞(0)|评价(0)|浏览(530)

加载geoserver发布的WMS服务

geoserver发布服务详见:https://blog.csdn.net/weixin_43598687/article/details/124102651

var provider1 = new Cesium.WebMapServiceImageryProvider({
    url:'http://localhost:8080/geoserver/test/wms',			//wms服务路径
    layers: 'test:dem',																//图层名
    parameters: {
    service : 'WMS',									//服务类型
        format: 'image/png',					//格式
        srs: 'EPSG:4326',							//坐标系
        transparent: true,						//是否透明
    }

});

tifLayer = viewer.imageryLayers.addImageryProvider(provider1);

移除图层

viewer.imageryLayers.remove(tifLayer);

加载KMZ/KML文件

var options = {
     camera : viewer.scene.camera,
     canvas : viewer.scene.canvas,
     clampToGround: true //开启贴地
 };
 viewer.dataSources.add(Cesium.KmlDataSource.load('./static/lith.kmz', options)).then(function(dataSource){
     viewer.clock.shouldAnimate = false;
     var rider = dataSource.entities.getById('tour');
     viewer.flyTo(rider).then(function(){
         viewer.trackedEntity = rider;
         viewer.selectedEntity = viewer.trackedEntity;
         viewer.clock.multiplier = 30;
         viewer.clock.shouldAnimate = true;
     });
 });

移除图层

datasource = viewer.dataSources.get(viewer.dataSources.length-1);
viewer.dataSources.remove(datasource, true);

加载JSON文件

let smcPromise = Cesium.GeoJsonDataSource.load('./static/ALL.json',{
    clampToGround : true,   //开启贴地
});
smcPromise.then(function (dataSource){
    viewer.dataSources.add(dataSource);
});

移除图层

datasource = viewer.dataSources.get(viewer.dataSources.length-1);
viewer.dataSources.remove(datasource, true);

在指定经纬度添加标签和地名

label1 = viewer.entities.add({
id:'name1',
name:'name1',
position:Cesium.Cartesian3.fromDegrees(103.769601,33.264294),		//经纬度
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,			//开启贴地
billboard:{			//加载图片图标
    image: './static/roadLabel.png',
    height: 40,
    width: 40,
    heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
    pixelOffset : new Cesium.Cartesian2(0, 0),		//偏移量
},
label:{
    text:'text',
    font:'16pt 宋体',
    fillColor:Cesium.Color.WHITE,
    style: Cesium.LabelStyle.FILL,
    outlineWidth : 1,
    heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
    pixelOffset : new Cesium.Cartesian2(60, 0)
},
});

相关文章