zoukankan      html  css  js  c++  java
  • cesium 检测视图改变的代码

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
        <meta name="description" content="Fly to a specified location or view a geographic rectangle.">
        <meta name="cesium-sandcastle-labels" content="Showcases">
        <title>Cesium Demo</title>
        <script type="text/javascript" src="../Sandcastle-header.js"></script>
        <script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script>
        <script type="text/javascript">
        require.config({
            baseUrl : '../../../Source',
            waitSeconds : 60
        });
        </script>
    </head>
    <body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
    <style>
        @import url(../templates/bucket.css);
    
        #viewChanged, #cameraChanged {
            display: none;
            background-color: red;
            color: white;
        }
    </style>
    <div id="cesiumContainer" class="fullSize"></div>
    <div id="loadingOverlay"><h1>Loading...</h1></div>
    <div id="toolbar">
        <div id="viewChanged">View Changed</div>
        <div id="cameraChanged">Camera Changed</div>
    </div>
    <script id="cesium_sandcastle_script">
    function startup(Cesium) {
        'use strict';
    //Sandcastle_Begin
    var viewer = new Cesium.Viewer('cesiumContainer');
    var widget = new Cesium.CesiumWidget('cesiumContainer');
    var scene = viewer.scene;
    var clock = viewer.clock;
    var  timer;
    
    function flyInACity() {
        Sandcastle.declare(flyInACity);
        var camera = scene.camera;
        camera.flyTo({
            destination : Cesium.Cartesian3.fromDegrees(-73.98580932617188, 40.74843406689482, 363.34038727246224),
            complete : function() {
                setTimeout(function() {
                    camera.flyTo({
                        destination : Cesium.Cartesian3.fromDegrees(-73.98585975679403, 40.75759944127251, 186.50838555841779),
                        orientation : {
                            heading : Cesium.Math.toRadians(200.0),
                            pitch : Cesium.Math.toRadians(-50.0)
                        },
                        easingFunction : Cesium.EasingFunction.LINEAR_NONE
                    });
                }, 1000);
            }
        });
    }
    
    Sandcastle.addToolbarMenu([{
        text : 'Fly in a city',
        onselect : function() {
            flyInACity();
            Sandcastle.highlight(flyInACity);
        }
    }]);
    
        /**
         * activates viewchanged Event
         * This event will be fired many times when the camera position or direction is changing
         * @param {Boolean} active
         */
    
            var camera = scene.camera;
            var posX = camera.position.x;
            var posY = camera.position.y;
            var posZ = camera.position.z;
            var dirX = camera.direction.x;
            var dirY = camera.direction.y;
            var dirZ = camera.direction.z;
    
            // tolerance
            var posD = 3;
            var dirD = 0.001;
    
            var listenerFunc = function() {
                var currentCamera = scene.camera;
                var _posX = currentCamera.position.x;
                var _posY = currentCamera.position.y;
                var _posZ = currentCamera.position.z;
                var _dirX = currentCamera.direction.x;
                var _dirY = currentCamera.direction.y;
                var _dirZ = currentCamera.direction.z;
    
    
                if (Math.abs(posX - _posX) > posD ||
                    Math.abs(posY - _posY) > posD ||
                    Math.abs(posZ - _posZ) > posD ||
                    Math.abs(dirX - _dirX) > dirD ||
                    Math.abs(dirY - _dirY) > dirD ||
                    Math.abs(dirZ - _dirZ) > dirD) {
                    posX = _posX;
                    posY = _posY;
                    posZ = _posZ;
                    dirX = _dirX;
                    dirY = _dirY;
                    dirZ = _dirZ;
    
                    if (timer != null) {
                        clearTimeout(timer);
                    }
                    timer = setTimeout(function(){
                        console.log("Wake up Tiling Manager from sleep");
                        timer = null;
                    }, 100 + 100*Math.random());
                }
            };
    
    
        widget.clock.onTick.addEventListener(listenerFunc);
    
    
    
    
    //Sandcastle_End
        Sandcastle.finishedLoading();
    }
    if (typeof Cesium !== "undefined") {
        startup(Cesium);
    } else if (typeof require === "function") {
        require(["Cesium"], startup);
    }
    </script>
    </body>
    </html>
  • 相关阅读:
    windows下 php-cgi.exe 0xc000007b 错误 阿星小栈
    call to undefined function openssl cipher iv length() 报错 PHP7开启OpenSSL扩展失败 阿星小栈
    PHP json_encode返回的json前端获取时出现unicode转码和反斜杠导致无法解析的解决办法
    Warring:POST Content-Length of 625523488 bytes exceeds the limit of 8388608 bytes in Unknown on line 0 阿星小栈
    PHP数组分割成新数组 阿星小栈
    Laravel ajax请求419错误及解决办法(CSRF验证) 阿星小栈
    MySQL said: Authentication plugin 'caching_sha2_password' cannot be loaded... 阿星小栈
    Laravel框架发送邮件 阿星小栈
    PHP 导出Excel三种方式 阿星小栈
    mysql命令 出现ERROR 1054 (42S22): Unknown column 'password' in 'field list'
  • 原文地址:https://www.cnblogs.com/ffjiang/p/6728896.html
Copyright © 2011-2022 走看看