CesiumJS 案例 P19:添加矩形、监听鼠标左击、监听鼠标右击、监听鼠标移动-一、添加矩形

时间:2024-11-06 08:19:37
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>RectangleGraphics - 添加矩形</title>
        <link rel="stylesheet" href="../js/Cesium-1.112/Build/Cesium/Widgets/widgets.css" />
        <style>
            * {
                margin: 0;
                padding: 0;
                box-sizing: border-box;
            }

            html,
            body {
                width: 100%;
                height: 100%;
            }

            .container {
                width: 100%;
                height: 100%;
            }
        </style>
    </head>

    <body>
        <div id="container"></div>
    </body>

    <script src="../js/Cesium-1.112/Build/Cesium/Cesium.js"></script>
    <script>
        const viewer = new Cesium.Viewer("container");

        const west = 0; // 西经(西经为负)
        const south = 0; // 南纬(南纬为负)
        const east = 10; // 东经(东经为正)
        const north = 10; // 北纬(北纬为正)

        // 添加矩形
        const rectangle = viewer.entities.add({
            rectangle: {
                coordinates: Cesium.Rectangle.fromDegrees(west, south, east, north),
                material: Cesium.Color.BLUE.withAlpha(0.5), // 半透明的蓝色
            },
        });
    </script>
</html>