import * as Cesium from 'cesium'
export default function modifyMap(viewer: Cesium.Viewer) {
// 获取地图影像图层
const baseLayer = viewer.imageryLayers.get(0)
// 设置两个变量,用来判断是否进行颜色的翻转和过滤
const options = {
invertColor: true,
filterRGB: [0, 50, 100]
}
// 更改地图着色器代码
const baseFragShader: string[] = (viewer.scene.globe as any)._surfaceShaderSet
.baseFragmentShaderSource.sources
for (let i = 0; i < baseFragShader.length; i++) {
// console.log(baseFragShader[i])
// console.log('------')
const strS = 'color = czm_saturation(color, textureSaturation);\n#endif\n'
let strT = 'color = czm_saturation(color, textureSaturation);\n#endif\n'
if (options.invertColor) {
strT += `
color.r = 1.0 - color.r;
color.g = 1.0 - color.g;
color.b = 1.0 - color.b;
`
}
if (options.filterRGB.length > 0) {
strT += `
color.r = color.r * ${options.filterRGB[0]}.0/255.0;
color.g = color.g * ${options.filterRGB[1]}.0/255.0;
color.b = color.b * ${options.filterRGB[2]}.0/255.0;
`
}
baseFragShader[i] = baseFragShader[i].replace(strS, strT)
}
}
Cesium修改地图颜色代码
最新推荐文章于 2025-02-11 15:06:44 发布