学习cesium,关于图层界面的切换

最近学习cesium的3D引擎,有关图层切换的例子比较少,在官网上看见了一些例子加以自己的理解。投机了一种近似于图层切换的效果。

这种图层切换每次点击按钮时,会把其他的数据和实体给删除。然后再创建或加载一个新的

闲话不多说我们直接上代码

Sandcastle.addToolbarButton('Basic styling', function() {
                viewer.dataSources.add(Cesium.GeoJsonDataSource.load(URL, {
                    stroke: Cesium.Color.HOTPINK,
                    fill: Cesium.Color.PINK.withAlpha(0.5),
                    strokeWidth: 3
                }));
            });
            Sandcastle.addToolbarButton('按钮',function() {

                var position = Cesium.Cartesian3.fromDegrees(116.39053344726561,39.89604077881996, 0.0);
                var hpr = new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(135), 0.0, 0.0);
                var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);

                var model = viewer.entities.add({
                    id:'01',
                    position : position,
                    orientation : orientation,
                    model : {
                        uri : URL,
                        minimumPixelSize : 128,
                        maximumScale : 20000
                    }
                });

   
            },"toolbar");

            Sandcastle.reset = function() {
                viewer.dataSources.removeAll();
                viewer.entities.removeById('01')//根据id删除entity

                //设置相机为home为起点
                viewer.camera.lookAt(Cesium.Cartesian3.fromDegrees(116.39053344726561,39.89604077881996, 2631.082799425431), new Cesium.Cartesian3(0.0, -4790.0, 3930.0));
                viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
            };

//Sandcastle_End
            Sandcastle.finishedLoading();

  

转载于:https://www.cnblogs.com/xiada-zhihua/p/11259958.html

你可能感兴趣的:(javascript)