Cesium之Sandbox
2022/6/4 23:50:20
本文主要是介绍Cesium之Sandbox,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
var Sandbox = Sandbox || {};//定义一个变量Sandbox,它是类?还是变量? (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) { 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之Sandbox的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23增量更新怎么做?-icode9专业技术文章分享
- 2024-11-23压缩包加密方案有哪些?-icode9专业技术文章分享
- 2024-11-23用shell怎么写一个开机时自动同步远程仓库的代码?-icode9专业技术文章分享
- 2024-11-23webman可以同步自己的仓库吗?-icode9专业技术文章分享
- 2024-11-23在 Webman 中怎么判断是否有某命令进程正在运行?-icode9专业技术文章分享
- 2024-11-23如何重置new Swiper?-icode9专业技术文章分享
- 2024-11-23oss直传有什么好处?-icode9专业技术文章分享
- 2024-11-23如何将oss直传封装成一个组件在其他页面调用时都可以使用?-icode9专业技术文章分享
- 2024-11-23怎么使用laravel 11在代码里获取路由列表?-icode9专业技术文章分享
- 2024-11-22怎么实现ansible playbook 备份代码中命名包含时间戳功能?-icode9专业技术文章分享