cesium 1.52 demo - Polygon.html

<!DOCTYPE html>
<html lang="en">

<head>
    <!-- Use correct character set. -->
    <meta charset="utf-8">
    <!-- Tell IE to use the latest, best version. -->
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <!-- Make the app on mobile take up the full browser screen and disable user scaling. -->
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <title>Polygon</title>

    <!-- The Cesium library. -->
    <script src="../ThirdParty/Cesium/Cesium.js"></script>
    <!-- Style our app. -->
    <style>
        @import url(../ThirdParty/Cesium/Widgets/widgets.css);
        html, body, #cesiumContainer {
            width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden;
        }
    </style>
</head>

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

    <script>
        Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIzNDhhYmQxOC1mYzMwLTRhYmEtOTI5Ny1iNGExNTQ3ZTZhODkiLCJpZCI6NTQ1NCwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTU0MzM3Mzc0NH0.RU6ynAZcwQvdfygt_N_j2rb2lpsuyyROzdaLQg0emAg';
        let viewer = new Cesium.Viewer('cesiumContainer');

        let redPolygon = viewer.entities.add({
            name : 'Red polygon on surface',
            polygon : {
                hierarchy : Cesium.Cartesian3.fromDegreesArray([-115.0, 37.0,
                    -115.0, 32.0,
                    -107.0, 33.0,
                    -102.0, 31.0,
                    -102.0, 35.0]),
                material : Cesium.Color.RED
            }
        });

        let greenPolygon = viewer.entities.add({
            name : 'Green extruded polygon',
            polygon : {
                hierarchy : Cesium.Cartesian3.fromDegreesArray([-108.0, 42.0,
                    -100.0, 42.0,
                    -104.0, 40.0]),  // 平面模型。
                extrudedHeight: 500000.0,  // 拉伸高度。
                material : Cesium.Color.GREEN,
                closeTop : false,  // 封顶,默认true。
                closeBottom : false  // 封底,默认true。
            }
        });

        let orangePolygon = viewer.entities.add({
            name : 'Orange polygon with per-position heights and outline',
            polygon : {
                hierarchy : Cesium.Cartesian3.fromDegreesArrayHeights([-108.0, 25.0, 100000,
                    -100.0, 25.0, 100000,
                    -100.0, 30.0, 100000,
                    -108.0, 30.0, 300000]),
                extrudedHeight: 0,
                perPositionHeight : true,  // 每个特征点的高度,默认false。
                material : Cesium.Color.ORANGE.withAlpha(0.5),
                outline : true,
                outlineColor : Cesium.Color.BLACK
            }
        });

        let bluePolygon = viewer.entities.add({
            name : 'Blue polygon with holes',
            polygon : {
                hierarchy : {
                    positions : Cesium.Cartesian3.fromDegreesArray([-99.0, 30.0,
                        -85.0, 30.0,
                        -85.0, 40.0,
                        -99.0, 40.0]),
                    holes : [{
                        positions : Cesium.Cartesian3.fromDegreesArray([
                            -97.0, 31.0,
                            -97.0, 39.0,
                            -87.0, 39.0,
                            -87.0, 31.0
                        ]),
                        holes : [{
                            positions : Cesium.Cartesian3.fromDegreesArray([
                                -95.0, 33.0,
                                -89.0, 33.0,
                                -89.0, 37.0,
                                -95.0, 37.0
                            ]),
                            holes : [{
                                positions : Cesium.Cartesian3.fromDegreesArray([
                                    -93.0, 34.0,
                                    -91.0, 34.0,
                                    -91.0, 36.0,
                                    -93.0, 36.0
                                ])
                            }]
                        }]
                    }]
                },
                material : Cesium.Color.BLUE.withAlpha(0.5),
                height : 0,
                outline : true // height is required for outline to display
            }
        });

        let cyanPolygon = viewer.entities.add({
            name : 'Cyan vertical polygon with per-position heights and outline',
            polygon : {
                hierarchy : Cesium.Cartesian3.fromDegreesArrayHeights([
                    -90.0, 41.0, 0.0,
                    -85.0, 41.0, 500000.0,
                    -80.0, 41.0, 0.0
                ]),
                perPositionHeight : true,
                material : Cesium.Color.CYAN.withAlpha(0.5),
                outline : true,
                outlineColor : Cesium.Color.BLACK
            }
        });

        viewer.zoomTo(viewer.entities);
    </script>
</body>

</html>

猜你喜欢

转载自blog.csdn.net/weixin_42193179/article/details/85605133