cesium根据相应区域坐标和对应x轴,y轴数据着色

1.获取区域坐标,x轴数,y轴数(westSouthEastNorth,xNum,yNum)

2.计算当前数据的经纬度是否在区域内 booleanPointInPolygon (temp)

3.在区域内为红色,不在则为无色

4.cesium添加图元

    /**区域着色 */

    const addColor = (westSouthEastNorth: any, xNum: any, yNum: any, temp: any) => {

        const labels = viewer.value.scene.primitives.add(new Cesium.LabelCollection());

        for (let i = 0; i < xNum; i++) {

            for (let j = 0; j < yNum; j++) {

                if (i == 0) {

                    let lat = Math.abs(westSouthEastNorth[3] - westSouthEastNorth[1]) / xNum * (j + 0.5)

                    labels.add({

                        position: Cesium.Cartesian3.fromDegrees(westSouthEastNorth[0] - 0.4, westSouthEastNorth[1] - lat - 0.15, 0),

                        text: String(yNum - j),

                        font: '18px sans-serif',

                        fillColor: Cesium.Color.GREY,

                        outlineColor: Cesium.Color.GREY,

                        show: true

                    });

                }

                let lng = Math.abs(westSouthEastNorth[0] - westSouthEastNorth[4]) / xNum * i

                let lat = Math.abs(westSouthEastNorth[5] - westSouthEastNorth[1]) / yNum * j

                let lng2 = Math.abs(westSouthEastNorth[0] - westSouthEastNorth[4]) / xNum * (i + 1)

                let lat2 = Math.abs(westSouthEastNorth[5] - westSouthEastNorth[1]) / yNum * (j + 1)

                const row = temp.find((item: any) => {

                    let pt = turf.point([item.longitude, item.latitude]);

                    let poly = turf.polygon([[

                        [westSouthEastNorth[0] + lng, westSouthEastNorth[1] - lat2],

                        [westSouthEastNorth[0] + lng, westSouthEastNorth[1] - lat],

                        [westSouthEastNorth[0] + lng2, westSouthEastNorth[1] - lat],

                        [westSouthEastNorth[0] + lng2, westSouthEastNorth[1] - lat2],

                        [westSouthEastNorth[0] + lng, westSouthEastNorth[1] - lat2],

                    ]]);

                    return turf.booleanPointInPolygon(pt, poly);

                })

                instances.value.push(new Cesium.GeometryInstance({

                    geometry: new Cesium.RectangleGeometry({

                        rectangle: Cesium.Rectangle.fromDegrees(westSouthEastNorth[0] + lng, westSouthEastNorth[1] - lat2, westSouthEastNorth[0] + lng2, westSouthEastNorth[1] - lat),

                        vertexFormat: Cesium.PerInstanceColorAppearance.VERTEX_FORMAT

                    }),

                    attributes: {

                        color: row ? Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromCssColorString(row.color)) : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.RED.withAlpha(0))

                    }

                }));

            }

            let lng = Math.abs(westSouthEastNorth[4] - westSouthEastNorth[2]) / xNum * (i + 0.5)

            labels.add({

                position: Cesium.Cartesian3.fromDegrees(westSouthEastNorth[2] + lng - 0.15, westSouthEastNorth[3] - 0.4, 0),

                text: String(i + 1),

                font: '18px sans-serif',

                fillColor: Cesium.Color.GREY,

                outlineColor: Cesium.Color.GREY,

                show: true

            });

        }

        viewer.value.scene.primitives.add(new Cesium.Primitive({

            geometryInstances: instances.value,

            appearance: new Cesium.PerInstanceColorAppearance()

        }))

    }

欢迎补充,一起进步。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值