最近工作需要做三維GIS相關(guān)的開發(fā)竟坛,因此接觸了Cesium夯辖,采用的Web容器是Tomcat翰绊,地圖服務(wù)由Geoserver發(fā)布同時(shí)也調(diào)用了在線地形服務(wù)胆屿。Tomcat和Geoserver的安裝部署再次就不再重復(fù)介紹箭养。安裝完Tomcat之后慕嚷,將下載的Geoserver和Cesium都放在Tomcat安裝目錄的webapp目錄下
啟動(dòng)Tomcat之后就可以訪問,本文所采用的IDE是WebStorm毕泌,在WebStorm中打開在Tomcat中部署好的Cesium工程喝检,在Apps目錄下新建一個(gè)HellWorld.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>
<script src="../lib/GeoserverTerrainProvider.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');
var terrainProvider=new Cesium.CesiumTerrainProvider({
url:"https://assets02.agi.com/stk-terrain/world"
});
var viewer=new Cesium.Viewer("cesiumContainer",{
timeline:false,
animation:false,//去除時(shí)間線條和Animation widget;
baseLayerPicker:false,
terrainProvider:terrainProvider
});
var layers=viewer.imageryLayers;
layers.addImageryProvider(new Cesium.WebMapServiceImageryProvider({
url:'http://localhost:8080/geoserver/workspace/wms',
layers:'workspace:geotiff_coverage',
parameters : {
format : 'image/png',
transparent : true,
service : 'WMS',
version : '1.1.0',
request : 'GetMap'
}
}));
viewer._cesiumWidget._creditContainer.style.display="none";
</script>
</body>
</html>
最后在球上顯示的結(jié)果就是一部分貼有影像紋理的三維地形: