【Cesium】实现动态扩散圆圈---预警效果

该文章介绍了如何使用CesiumJavaScript库创建动态扩散预警效果,包括点击屏幕生成扩散圆圈、调整扩散范围、速度、颜色和波纹数量等功能。核心代码展示了事件监听、CircleRippleMaterialProperty的使用,以及动态绑定视图模型来改变扩散参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Cesium预警效果---动态扩散圆圈。用户可动态调整扩散范围、扩散速度、波纹数量以及扩散效果的颜色。如下视频所示。

cesium动态扩散圆---预警

 一、核心代码:只包含js代码,不包含html部分。

function getCircleWave(viewer) {
    // 注册屏幕点击事件
    viewer.screenSpaceEventHandler.setInputAction((evt) => {
        var ray = viewer.camera.getPickRay(evt.position);
        var cartesian = viewer.scene.globe.pick(ray, viewer.scene);
        var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
        var lng = Cesium.Math.toDegrees(cartographic.longitude); // 经度值
        var lat = Cesium.Math.toDegrees(cartographic.latitude); // 纬度值
        // 添加动态扩散模型
        circleWave({ viewer, lng, lat});
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
}

//可动态调整扩散范围、扩散速度以及扩散效果的颜色。用户也可自行增加调整透明度、波纹数量等功能
function circleWave({ viewer, lng, lat} = {}) {
    let entity;
    const viewModel = {
        color1: "Red",
        colors: ["White", "Red", "Green", "Blue", "Yellow", "Gray", "YELLOWGREEN", "VIOLET", "TEAL", "PINK", "MIDNIGHTBLUE", "LIME", "BLACK"],
        widthSize1: 500.0,
        speedSize1: 5.0,
    };

    Cesium.knockout.track(viewModel);
    const toolbar = document.getElementById("toolbar-wave");
    Cesium.knockout.cleanNode(toolbar);
    Cesium.knockout.applyBindings(viewModel, toolbar);
    Cesium.knockout
        .getObservable(viewModel, "color1")
        .subscribe(function (newValue) {
            const a = new Cesium.CircleRippleMaterialProperty({
                color: getColor(newValue, 0.9),
                speed: viewModel.speedSize1,
                count: 4,
                gradient: 0.2
            });
            entity.ellipse.material = a;
            params['color'] = newValue;
        });

    Cesium.knockout
        .getObservable(viewModel, "widthSize1")
        .subscribe(function (newValue) {
            entity.ellipse.semiMinorAxis = parseFloat(newValue);
            entity.ellipse.semiMajorAxis = parseFloat(newValue);
        });

    Cesium.knockout
        .getObservable(viewModel, "speedSize1")
        .subscribe(function (newValue) {
            const a = new Cesium.CircleRippleMaterialProperty({
                color: getColor(viewModel.color1, viewModel.alpha1),//扩散效果颜色
                speed: parseFloat(newValue), //扩散速度
                count: 4,  //扩散波纹数量
                gradient: 0.2
            });
            entity.ellipse.material = a;
        });

  
    entity = viewer.entities.add({
        position: Cesium.Cartesian3.fromDegrees(lng, lat),
        name: "波纹圆",
        ellipse: {
            semiMinorAxis: viewModel.widthSize1,
            semiMajorAxis: viewModel.widthSize1,
            material: new Cesium.CircleRippleMaterialProperty({
                color: getColor(viewModel.color1, 0.9),
                speed: viewModel.speedSize1,
                count: 4,
                gradient: 0.2
            })
        }
    })
}

function getColor(colorName, alpha) {
        const color = Cesium.Color[colorName.toUpperCase()];
        return Cesium.Color.fromAlpha(color, parseFloat(alpha));
    }

二、源码下载:附带cesium框架,一键运行。

 Cesium实现动态扩散预警-Javascript文档类资源-CSDN文库

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

鱼遇雨愈愉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值