欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Cesium-GeoJson数据的显示和隐藏

程序员文章站 2022-07-12 18:23:00
...

结果展示

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项目 点一个⭐ ο(=•ω<=)ρ⌒☆