Cesium-GeoJson数据的显示和隐藏

结果展示

在这里插入图片描述

相关代码

// -------------------------- 加载GeoJson数据 ------------------------------

var fireLayer = null;
var borderLayer = null;
var roadLayer = null;

viewer.dataSources.add(Cesium.GeoJsonDataSource.load('Assets/muli/muli_geojson/fire.geojson', {
    
    
    stroke: Cesium.Color.RED.withAlpha(0.5),
    strokeWidth: 2.3,
    fill: Cesium.Color.RED.withAlpha(0.1),
    clampToGround: true
})).then(data => {
    
    
    fireLayer = data;
});

viewer.dataSources.add(Cesium.GeoJsonDataSource.load('Assets/muli/muli_geojson/road.geojson', {
    
    
    stroke: Cesium.Color.CORAL.withAlpha(0.5),
    strokeWidth: 2.3,
    fill: Cesium.Color.CORAL.withAlpha(0.4),
    clampToGround: true
})).then(data => {
    
    
    roadLayer = data;
});

viewer.dataSources.add(Cesium.GeoJsonDataSource.load('Assets/muli/muli_geojson/border.geojson', {
    
    
    stroke: Cesium.Color.RED.withAlpha(0.5),
    strokeWidth: 2.3,
    fill: Cesium.Color.RED.withAlpha(0.5),
    clampToGround: true
})).then(data => {
    
    
    borderLayer = data;
});

// ------------------------- 图层的显式控制 ----------------------------------
checkboxFire = document.getElementById("checkboxFire");
checkboxFire.checked = true;
checkboxFire.addEventListener("click", () => {
    
    
    fireLayer.show = checkboxFire.checked;
    borderLayer.show = checkboxFire.checked;
});

checkboxRoad = document.getElementById("checkboxRoad");
checkboxRoad.checked = true;
checkboxRoad.addEventListener("click", () => {
    
    
    roadLayer.show = checkboxRoad.checked;
});

如果您觉得这篇文章对您有帮助,欢迎给我的 github项目 点一个⭐ ο(=•ω<=)ρ⌒☆

猜你喜欢

转载自blog.csdn.net/Apple_Coco/article/details/108825245
今日推荐