viewer_changeview.vue 4.08 KB
<!--
 * @Author: jiangbotao
 * 限制在一定高度上的视角变化
 * 当到一定尺度后开始可以改变视角
 * @Date: 2019-12-03 21:30:29
 * @LastEditors: jiangbotao
 * @LastEditTime: 2019-12-04 20:25:49
 * @FilePath: \WebGL_Webpack_Vue\components\viewer6.vue
 -->
<template>
	<div>
		<div id="cesiumContainer" v-bind:style="styleObject"></div>
		<div id='loadingbar' class="spinner">
			<div class="spinner-container container1">
				<div class="circle1"></div>
				<div class="circle2"></div>
				<div class="circle3"></div>
				<div class="circle4"></div>
			</div>
			<div class="spinner-container container2">
				<div class="circle1"></div>
				<div class="circle2"></div>
				<div class="circle3"></div>
				<div class="circle4"></div>
			</div>
			<div class="spinner-container container3">
				<div class="circle1"></div>
				<div class="circle2"></div>
				<div class="circle3"></div>
				<div class="circle4"></div>
			</div>
		</div>
        <div id="toolbar" style="position: absolute;left: 5px;top: 5px;display: none;">
            <select id="imageryOptions" class="selectpicker show-tick form-control">
                <!--<option disabled selected value>&#45;&#45;选择服务类型&#45;&#45;</option>-->
                <option selected value="WGS">自定义影像&地形-平面场景</option>
                <option value="MEC">倾斜数据-三维场景</option>
            </select>
        </div>
	</div>
</template>

<script>
import URL_CONFIG from './../config/urlConfig.vue';
const Cesium=window.Cesium;
export default {
    data: function() {
        return {
            styleObject:{
                width: '100%',
                position: 'absolute',
                top: '0px',
                bottom: '0px',
                left: '0px',
                backgroundColor: '#000000'
            },
            smviewer:{}
        }
    },
    mounted: function(){
        this.smviewer=new Cesium.Viewer('cesiumContainer', {
            animation: true
        });
        $(".cesium-widget-credits")[0].style.visibility="hidden";
		$(".cesium-viewer-animationContainer")[0].style.visibility="hidden";
        var scenecamera=null;
        this.smviewer.imageryLayers.addImageryProvider(new Cesium.BingMapsImageryProvider({
            url : 'https://dev.virtualearth.net',
            mapStyle : Cesium.BingMapsStyle.AERIAL,
            key : 'AhLx52IuZUuca_C3zK2TzBG2eu1vihUkayqc_e4MISbXZyn5Zw_X--odRqrweVap'
        }));
        this.smviewer.scene.screenSpaceCameraController.maximumZoomDistance=100000;	
        this.smviewer.scene.screenSpaceCameraController.enableTilt=false;
        var scene = this.smviewer.scene;		
        scene.camera.setView({
            destination : new Cesium.Cartesian3(-1312359.8872867103, 5363468.852567853, 3218043.8251359267),
            orientation : {
                heading : 0.003361064609361364,
                pitch : -1.5310712877149566,
                roll : 0
            }
        });
        var stviewer = this.smviewer;
        scene.postRender.addEventListener(function(){
            scenecamera=scene.camera;
            var position = scene.camera.position;
            var cartographic = Cesium.Cartographic.fromCartesian(position);
            
            var height = cartographic.height;
            if(height<10000){
                stviewer.scene.screenSpaceCameraController.enableTilt=true;
            }else{
                stviewer.scene.screenSpaceCameraController.enableTilt=false;
                scene.camera.setView({
                    destination: Cesium.Cartesian3(scenecamera.position.x, scenecamera.position.y, scenecamera.position.z),
                    orientation: {
                        heading: scenecamera.heading,
                        pitch: -1.5310712877149566,
                        roll: 0.000000
                    }
                });
            }
        })
        //添加下拉菜单,点击选项切换地图服务
        $('#imageryOptions').change(function() {
            console.log(scene.camera)
        });
        $('#toolbar').show();
            $('#loadingbar').remove();
        }
}
</script>

<style>

</style>