• Cesium之Sandbox


    var Sandbox = Sandbox || {};//定义一个变量Sandbox,它是类?还是变量?左边是全局变量,右边是??哪里来的对象 如果是null,那么赋值为{}
    (function() {
        "use strict";
        /*global Cesium,console*/
    
        /**
         * @constructor
         */
        Cesium.Sandbox = function() {
            var canvas = document.getElementById("glCanvas");
            var scene = new Cesium.Scene(canvas);
            var primitives = scene.getPrimitives();
            var ellipsoid = Cesium.Ellipsoid.WGS84;
    
            // TODO: make multiple tile providers available
            var bing = new Cesium.BingMapsTileProvider({
                server : "dev.virtualearth.net",
                mapStyle : Cesium.BingMapsStyle.AERIAL
            });
    
            var cb = new Cesium.CentralBody(scene.getCamera(), ellipsoid);
            cb.dayTileProvider = bing;
            cb.nightImageSource = "Images/land_ocean_ice_lights_2048.jpg";
            cb.specularMapSource = "Images/earthspec1k.jpg";
            cb.cloudsMapSource = "Images/earthcloudmaptrans.jpg";
            cb.bumpMapSource = "Images/earthbump1k.jpg";
            cb.showSkyAtmosphere = true;
            cb.showGroundAtmosphere = true;
    
            primitives.setCentralBody(cb);
    
            scene.getCamera().getControllers().addSpindle();
            scene.getCamera().getControllers().get(0).mouseConstrainedZAxis = true;
    
            scene.getCamera().getControllers().addFreeLook();
    
            scene.getCamera().frustum.near = 100.0;
    
            this._scene = scene;
            this._ellipsoid = ellipsoid;
    
            scene.setAnimation(function() {
                var camera = scene.getCamera();
                var cameraPosition = new Cesium.Cartesian4(camera.position.x, camera.position.y, camera.position.z, 1.0);
                var v = camera.transform.multiplyWithVector(cameraPosition).getXYZ();
                scene.setSunPosition(v);
    
                //  In case of canvas resize
                canvas.width = canvas.clientWidth;
                canvas.height = canvas.clientHeight;
                scene.getContext().setViewport({
                    x : 0,
                    y : 0,
                    width : canvas.width,
                    height : canvas.height
                });
    
                scene.getCamera().frustum.aspectRatio = canvas.clientWidth / canvas.clientHeight;
    
                var s = Cesium.Sandbox.getCurrentCodeSnippet();
                if (s && s.animate) {
                    s.animate();
                }
            });
    
            (function tick() {
                try {
                    scene.render();
                } catch (e) {
                    // Live editing can create invalid states, e.g., a conic sensor with inner half-angle
                    // greater than outer half-angle, which cause exceptions.  We swallow the exceptions
                    // to avoid losing the animation frame.
                    console.log(e.message);
                }
    
                Cesium.requestAnimationFrame(tick);
            }());
    
            canvas.oncontextmenu = function(e) {
                e.preventDefault();
            };
            canvas.onselectstart = function(e) {
                e.preventDefault();
            };
        };
    
        Cesium.Sandbox.prototype.getScene = function() {
            return this._scene;
        };
    
        Cesium.Sandbox.prototype.getEllipsoid = function() {
            return this._ellipsoid;
        };
    
        Cesium.Sandbox.prototype.clearScene = function() {
            var scene = this._scene;
            scene.getPrimitives().removeAll();
            scene.getAnimations().removeAll();
        };
    }());

    在main.js中引用

    Editor.js

    /*global Sandbox,ace,require,define*/
    
        /**
         * Constructs an instance of a Javascript Ace editor.
         *
         * @param {String} id The id of the DOM element to be converted to an editor
         *
         * @constructor
         */
        Sandbox.Editor = function(id) {//数组中的对象1
            define('ace/mode/cesium', function(require, exports, module) {
                var oop = require("pilot/oop");
                var TextMode = require("ace/mode/text").Mode;
                var Tokenizer = require("ace/tokenizer").Tokenizer;
                var WorkerClient = require("ace/worker/worker_client").WorkerClient;
                var CesiumHighlightRules = require("ace/mode/cesium_highlight_rules").CesiumHighlightRules;

      这里Cesium也是一个变量。。。?Cesium也是一个{}?

    js 中{},[]中括号,大括号使用详解:

    一、{ } 大括号,表示定义一个对象,大部分情况下要有成对的属性和值,或是函数。

    如:var LangShen = {"Name":"Langshen","AGE":"28"};
    上面声明了一个名为“LangShen”的对象,多个属性或函数用,(逗号)隔开,因为是对象的属性,

    参考:https://www.jb51.net/article/27119.htm

    该写法,在JSON数据结构中经常用,除此之外,我们平时写函数组的时候,也经常用到,如:

    var LangShen = {
      Name = function(){
        return "LangShen";
      },
      Age = function(){
        return "28";
      }
    }

    function中又包含着function。。。

    Cesium对象新加的的属性名AxisAlignedBoundingBox,是一个函数属性,在js中函数其实就是类。

    函数属性如何初始化?

    https://wenku.baidu.com/view/6921fecac2c708a1284ac850ad02de80d4d80634.html

  • 相关阅读:
    Codeforces Round #321 (Div. 2) D. Kefa and Dishes 状压dp
    Codeforces Round #406 (Div. 2) D. Legacy 线段树建模+最短路
    HDU 4897 Little Devil I 树链剖分+线段树
    HDU 5405 Sometimes Naive 树链剖分+bit*****
    HDU 5274 Dylans loves tree 树链剖分+线段树
    BZOJ 2243: [SDOI2011]染色 树链剖分+线段树区间合并
    HDU 5544 Ba Gua Zhen dfs+高斯消元
    HDU 3949 XOR 线性基
    BZOJ 2460: [BeiJing2011]元素 线性基
    Educational Codeforces Round 18 C. Divide by Three DP
  • 原文地址:https://www.cnblogs.com/2008nmj/p/16342977.html
Copyright © 2020-2023  润新知