Skip to content

There is a problem with the calculation of the surface with holes #185

@DoubleYellowEgg

Description

@DoubleYellowEgg

I use the bounding rectangle in the following json as the external coordinate, and each face inside as the hole. The calculated triangular face will show the following situation

https://geo.datav.aliyun.com/areas_v3/bound/100000.json

Image

    const allPositions = []

    const coordinates = json.features[0].geometry.coordinates
    const coordinatess = []
    const holes = coordinates.map(coords => {
        const coord = coords[0]
        const positions = coord.map(coord => {
            return Cesium.Cartesian3.fromDegrees(coord[0], coord[1])
        })
        const hole = new Cesium.PolygonHierarchy(positions)
        coordinatess.push(coord)
        allPositions.push(...positions)
        return hole
    })

    const rect = Cesium.Rectangle.fromCartesianArray(allPositions)

    const interval = 0.001

    const wallPositions = [
        Cesium.Cartesian3.fromRadians(rect.west - interval, rect.north + interval, 0),
        Cesium.Cartesian3.fromRadians(rect.west - interval, rect.south - interval, 0),
        Cesium.Cartesian3.fromRadians(rect.east + interval, rect.south - interval, 0),
        Cesium.Cartesian3.fromRadians(rect.east + interval, rect.north + interval, 0),
    ]



    const wall = [
        [Cesium.Math.toDegrees(rect.west - interval), Cesium.Math.toDegrees(rect.north + interval)],
        [Cesium.Math.toDegrees(rect.west - interval), Cesium.Math.toDegrees(rect.south - interval)],
        [Cesium.Math.toDegrees(rect.east + interval), Cesium.Math.toDegrees(rect.south - interval)],
        [Cesium.Math.toDegrees(rect.east + interval), Cesium.Math.toDegrees(rect.north + interval)],
        [Cesium.Math.toDegrees(rect.west - interval), Cesium.Math.toDegrees(rect.north + interval)]
    ]

    const geojson = {
        type: 'Feature',
        geometry: {
            type: 'Polygon',
            coordinates: [
                wall,
                ...coordinatess
            ]
        }
    }

    var triangles = turf.tesselate(geojson);

    triangles.features.forEach(feature => {
        const coord = feature.geometry.coordinates[0]
        const positions = coord.map(coord => {
            return Cesium.Cartesian3.fromDegrees(coord[0], coord[1])
        })
        const hole = new Cesium.PolygonHierarchy(positions)
        const entity = viewer.entities.add({
            polygon: {
                hierarchy: hole,
                material: new Cesium.Color(Math.random(), Math.random(), Math.random(), 0.6)
            }
        })

        entity._feature = feature

    })

    const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
    handler.setInputAction((movement) => {


        const pickObject = viewer.scene.pick(movement.position)

        console.log(pickObject)

    }, Cesium.ScreenSpaceEventType.LEFT_CLICK)

    console.log(triangles)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions