cesium 地图颜色滤镜

实现地图颜色滤镜

这是cesium提供的更改地图颜色的效果

ImageryLayer提供了修改 brightness图层亮度 contrast对比度 hue色相 saturation饱和度 gamma伽玛校正 这些属性

但是用完你会发现,调不出来我想要的颜色,产品想要的一个颜色效果,用这些配置根本达不到要求,所以需要增加一个颜色属性,然后再配合这些属性进行微调

修改源码实现

仿照ImageryLayer源码的原有属性的代码,在其相关地方加入filterRGB属性用于设置颜色

这里为了使用方便,对颜色值进行一个调整

上面实现了一种滤镜颜色效果,进一步优化,再增加一种灰度反色滤镜效果。

业务端调用

ts 复制代码
  // 部分代码,业务端调用时修改这些属性就可以了
  let layersLength = this.viewerCesium.imageryLayers.length;
  if (layersLength === 0) return false;

  for (let j = 0; j < layersLength; j++) {
    let imageryLayer = this.viewerCesium.imageryLayers.get(j);
    imageryLayer.alpha = mapBottomParam.alpha;
    imageryLayer.brightness = mapBottomParam.brightness;
    imageryLayer.contrast = mapBottomParam.contrast;
    imageryLayer.saturation = mapBottomParam.saturation;

    if (mapBottomParam.filterColor) {
      const color = Color.fromCssColorString(mapBottomParam.filterColor);
      if (mapMode === 1) {
        // @ts-ignore
        imageryLayer.color = new Cartesian3(color.red, color.green, color.blue);
        // @ts-ignore
        imageryLayer.colorEnable = true;
        // @ts-ignore
        imageryLayer.filterColorEnable = false;
        imageryLayer.gamma = 0.3;
      } else if (mapMode === 3) {
        // @ts-ignore
        imageryLayer.filterColor = new Cartesian3(color.red, color.green, color.blue);
        // @ts-ignore
        imageryLayer.filterColorEnable = true;
        // @ts-ignore
        imageryLayer.colorEnable = false;
      }
    }
  }

效果

相关推荐
古夕8 分钟前
第三方 SSO 接入实践:redirect_uri 编码、回调一致性与跨项目联调
前端·vue.js
朦胧之10 分钟前
页面白屏卡住排查方法
前端·javascript
用户5936087414011 分钟前
Playwright 黑魔法:用 ClipboardEvent 绕过 React 富文本编辑器
前端
石山岭41 分钟前
自己动手写了一个 Android 虚拟定位 App:GPSSimulate 技术实
android·前端
犇驫聊AI1 小时前
Chrome DevTools MCP + Claude Code 自定义skills生成接口代码生成器
前端·javascript
kyriewen1 小时前
别再这样写 async/await 了:我在 Code Review 中见过最多的 8 个错误
前端·javascript·面试
hoLzwEge1 小时前
node-linker VS shamefully-hoist
前端·前端框架
袋鱼不重2 小时前
解决 Web 端图片预览与下载颜色不一致的一种工程方案
前端·后端
风止何安啊2 小时前
教你用 JS + AI 实现简单的爬虫,零门槛爬取网页信息
前端
cidy_982 小时前
codebase-memory-mcp 新手完全教程:让 AI 真正「理解」你的代码库
前端