Cesium如何绘制光墙

光墙效果

可见下图里黄田社区的闪烁光墙效果
在这里插入图片描述

如何实现

绘制闪烁光墙createAoiByCesium代码如下:

	function createAoiByCesium (option) {
        var color = option.color ? option.color : Cesium.Color.RED
        var maxHeight = option.maxHeight ? option.maxHeight : 10
        var minHeight = option.minHeight ? option.minHeight : 0
        var maxHeightArray = []
        var minHeightArray = []

        var c = document.createElement('canvas')
        c.width = 20
        c.height = 20
        var ctx = c.getContext('2d')

        var grd = ctx.createLinearGradient(0, 20, 0, 0)
        grd.addColorStop(0, 'rgba(' + color.red * 255 + ',' + color.green * 255 + ',' + color.blue * 255 + ',1)')
        grd.addColorStop(1, 'rgba(' + color.red * 255 + ',' + color.green * 255 + ',' + color.blue * 255 + ',0)')

        ctx.fillStyle = grd
        ctx.fillRect(0, 0, 20, 20)

        var config = null
        if (option.hasHeight) {
            var positions = []
            option.positions.forEach((x, index) => {
                if (index % 3 == 2) {
                    minHeightArray.push(x)
                    maxHeightArray.push(x + (isNaN(option.wallHeight) ? 0 : option.wallHeight))
                } else {
                    positions.push(x)
                }
            })
            config = {
                wall: {
                    show: option.show == false ? false : true,
                    positions: Cesium.Cartesian3.fromDegreesArray(positions),
                    material: new Cesium.ImageMaterialProperty({
                        image: c,
                    }),
                },
            }
        } else {
            for (var i = 0; i < option.positions.length / 2; i++) {
                minHeightArray.push(minHeight)
                maxHeightArray.push(maxHeight)
            }
            config = {
                wall: {
                    show: option.show == false ? false : true,
                    positions: Cesium.Cartesian3.fromDegreesArray(option.positions),
                    material: new Cesium.ImageMaterialProperty({
                        image: c,
                    }),
                },
            }
        }
        config.wall.maximumHeights = maxHeightArray
        config.wall.minimumHeights = minHeightArray
        var entity = _cesium.entities.add(config)

        entity.wall.material.color = new Cesium.CallbackProperty(function(time, x) {
            var alp = 0.5 * Math.abs(Math.sin(new Date().getTime() / 500)) + 0.1
            return color.withAlpha(alp)
        }, false)
        return entity
    }

调用createAoiByCesium

	data.forEach(bound => {
        var entity = createAoiByCesium({
            color: new Cesium.Color(27/255, 230/255, 248/255, 0.5),
            show: true,
            positions: flattenDeep(bound), // 格式需要为一维数组[114.112, 22.223, 40, 114.113, 22.224, 40]
            wallHeight: 150,
            hasHeight: true,
        })
        entity.tag = 'areaDsLines'
        if (!window.shiningWalls) {
            window.shiningWalls = []
        }
        window.shiningWalls.push(entity)
    })

data的数据格式如下所示:

[
	[114.112, 22.223, 40],
	[114.113, 22.224, 40],
	[114.114, 22.225, 40]
	...
]
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值