本文介绍 Cesium 的环境搭建及 Hello World Demo 。
Cesium 是一个基于 JavaScript 的开源框架,可用于在浏览器中绘制 3D 的地球,并在其上绘制地图(支持多种格式的瓦片服务),该框架不需要任何插件支持,但是浏览器必须支持 WebGL。
Cesium 支持多种数据可视化方式,可以绘制各种几何图形、导入图片,甚至 3D 模型。同时,Cesium还支持基于时间轴的动态数据展示,例如,我们可以用它绘制卫星运行轨迹。
从官方仓库或者官网下载 CesiumJS
官方仓库:https://github.com/AnalyticalGraphicsInc/cesium
官网下载:https://cesiumjs.org/downloads/
首先官方推荐使用 Nodejs 作为 Web 服务器,安装很简单就不多介绍了。
下载好之后解压即可,在项目根目录,命令行中依次输入以下命令
npm install
node server.js
然后在浏览器中打开 http://localhost:8080/Apps/HelloWorld.html 即可。
我们来看 HelloWorld.html
源码也比较简单。
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Use correct character set. -->
<meta charset="utf-8">
<!-- Tell IE to use the latest, best version. -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- Make the application on mobile take up the full browser screen and disable user scaling. -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<title>Hello World!</title>
<script src="../Build/Cesium/Cesium.js"></script>
<style>
@import url(../Build/Cesium/Widgets/widgets.css);
html, body, #cesiumContainer {
width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden;
}
</style>
</head>
<body>
<div id="cesiumContainer"></div>
<script>
var viewer = new Cesium.Viewer('cesiumContainer');
</script>
</body>
</html>
在 http://localhost:8080/Apps/Sandcastle/index.html 中有一些示例代码,很不错。
评论 (0)