码迷,mamicode.com
首页 > 其他好文 > 详细

cesium 检测视图改变的代码

时间:2017-04-18 18:41:10      阅读:1630      评论:0      收藏:0      [点我收藏+]

标签:cloc   ntc   doctype   spec   osx   style   ejs   change   dem   

<!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>

 

cesium 检测视图改变的代码

标签:cloc   ntc   doctype   spec   osx   style   ejs   change   dem   

原文地址:http://www.cnblogs.com/ffjiang/p/6728896.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!