CesiumJS起步

快速开始Quick start guide和 开始起步Getting Started

1. 确认浏览器支持Cesium

打开https://cesiumjs.org/Cesium/Apps/HelloWorld.html, 如果显示以下图片,说明浏览器支持Cesium.

CesiumJS起步_第1张图片
Hello_world_Cesium

否则,需要做一下尝试:

  • 更新浏览器到最新版本,目前运行最好的是Google Chrome,但Firefox, Internet Explorer 11, Opera也可以工作.
  • 升级显卡驱动程序.
    • NVIDIA - 下载驱动
    • AMD or ATI - 下载驱动
    • Intel - 下载驱动
  • 单独测试WebGL支持情况,访问http://get.webgl.org/, 该网站提供了一些解决问题的建议,也可以到 Cesium forum寻求帮助.

2. 安装node和CesiumJS依赖

安装node开发环境,直接使用编译好的安装包安装,以node-v8.11.4版本为例

//下载安装包
$ wget https://nodejs.org/dist/v8.11.4/node-v8.11.4-linux-x64.tar.xz
//解压
$ xz -d node-v8.11.4-linux-x64.tar.xz
$ tar -xf node-v8.11.4-linux-x64.tar
//移动到/opt/目录
$ sudo mv node-v8.11.4-linux-x64 /opt/
//获取安装路径
$ pwd
/opt/node-v8.11.4-linux-x64/bin
//设置软连接
$ ln -s /opt/node-v8.11.4-linux-x64/bin/node /usr/bin/node
$ ln -s /opt/node-v8.11.4-linux-x64/bin/npm /usr/bin/npm
//测试
$ node -v
v8.11.4
$ npm -v
5.6.0
//npm配置信息可以在此指定(采用ini格式):/home/brian/.npmrc

下载CesiumJS并安装依赖包,在根目录下创建‘node_modules’ 目录.

$ wget https://github.com/AnalyticalGraphicsInc/cesium/releases/download/1.48/Cesium-1.48.zip
// 在CesiumJS根目录(package.json所在目录)运行命令,安装依赖
$ npm install
[brian@localhost Cesium-1.48]$ npm install
npm WARN deprecated [email protected]: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
npm WARN deprecated [email protected]: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
npm WARN deprecated [email protected]: All versions below 4.0.1 of Nodemailer are deprecated. See https://nodemailer.com/status/
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: This project is unmaintained
npm WARN deprecated [email protected]: If using 2.x branch, please upgrade to at least 2.1.6 to avoid a serious bug with socket data flow and an import issue introduced in 2.1.0
npm WARN deprecated [email protected]: stop using this version
npm WARN deprecated [email protected]: Use uuid module instead
npm WARN deprecated [email protected]: This project is unmaintained
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
npm WARN deprecated [email protected]: The major version is no longer supported. Please update to 4.x or newer
npm WARN deprecated [email protected]: If using 2.x branch, please upgrade to at least 2.1.6 to avoid a serious bug with socket data flow and an import issue introduced in 2.1.0
npm WARN notice [SECURITY] timespan has the following vulnerability: 1 low. Go here for more details: https://nodesecurity.io/advisories?search=timespan&version=2.3.0 - Run `npm i npm@latest -g` to upgrade your npm version, and then `npm audit` to get more info.
npm WARN notice [SECURITY] minimatch has the following vulnerability: 1 high. Go here for more details: https://nodesecurity.io/advisories?search=minimatch&version=0.2.14 - Run `npm i npm@latest -g` to upgrade your npm version, and then `npm audit` to get more info.
npm WARN notice [SECURITY] tunnel-agent has the following vulnerability: 1 moderate. Go here for more details: https://nodesecurity.io/advisories?search=tunnel-agent&version=0.4.3 - Run `npm i npm@latest -g` to upgrade your npm version, and then `npm audit` to get more info.
npm WARN notice [SECURITY] hoek has the following vulnerability: 1 moderate. Go here for more details: https://nodesecurity.io/advisories?search=hoek&version=2.16.3 - Run `npm i npm@latest -g` to upgrade your npm version, and then `npm audit` to get more info.
npm WARN notice [SECURITY] lodash has the following vulnerability: 1 low. Go here for more details: https://nodesecurity.io/advisories?search=lodash&version=1.0.2 - Run `npm i npm@latest -g` to upgrade your npm version, and then `npm audit` to get more info.
npm WARN notice [SECURITY] minimatch has the following vulnerability: 1 high. Go here for more details: https://nodesecurity.io/advisories?search=minimatch&version=2.0.10 - Run `npm i npm@latest -g` to upgrade your npm version, and then `npm audit` to get more info.

> [email protected] install /data/work/web_wks/CesiumJS/Cesium-1.48/node_modules/uws
> node-gyp rebuild > build_log.txt 2>&1 || exit 0

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 806 packages in 71.849s

3. 启动web server

官方推荐使用 Node.js ,也可以使用其他任何web server. Cesium是完全基于客户端的,不依赖服务器.

$ node server.js
Cesium development server running locally.  Connect to http://localhost:8080/

4. 启动浏览器,调用HelloWorld示例

示例地址:
http://localhost:8080/Apps/HelloWorld.html




  
  
  
  
  
  
  Hello World!
  
  


  

简要对该文件进行分析如下:
在脚本中引用Cesium.js

 

为使用Cesium Viewer widget,需要引入它的CSS文件.

 @import url(../Build/Cesium/Widgets/widgets.css);

创建1个div
In the HTML body, we create a div for the viewer to live.

 

创建1个viewer实例

var viewer = new Cesium.Viewer('cesiumContainer');

5. 下一步

  • tutorials -- 介绍了Cesium的主要功能
  • Cesium Sandcastle -- 提供示例和在线编码
  • reference documentation -- 包括API的细节.

你可能感兴趣的:(CesiumJS起步)