前言
cesium 官網的api文檔介紹地址cesium官網api,里面詳細的介紹 cesium 各個類的介紹,還有就是在線例子:cesium 官網在線例子,這個也是學習 cesium 的好素材。
內容概覽
1.基於cesium 實現地形圖 Terrain 效果
2.源代碼 demo 下載
本篇實現 cesium 加載地形圖 Terrain 功能,效果圖如下:
- cesium 支持地形圖數據格式
Quantized-mesh ,Cesium團隊提供的開發的格式
Heightmap,Google Earth Enterprise - cesium 加載地形圖類 CesiumTerrainProvider
cesium 中添加地形數據,我們創建一個 CesiumTerrainProvider, 指定一個 URL 地址和一些配置的選項,然后講它分配給一個 viewer.terrainProvider。在這個實例中,我們可以使用 createWorldTerrain 輔助功能創建一個 Cesium 世界地形。
核心代碼:
//Cesium動態疊加地形圖 MapConfig.terrainObj = {url:"//assets.agi.com/stk-terrain/world",requestWaterMask:false,requestVertexNormals:false,proxyUrl:""}; MapConfig.terrainObj = {url:"http://localhost:8180/cesium/worldTerrain",requestWaterMask:false,requestVertexNormals:false,proxyUrl:""}; /** * 添加地形圖圖層 * @method addTerrainLayer * @param url 地形圖url proxyUrl 代理請求url * @return */ addTerrainLayer: function (terrainObj) { if (terrainObj.url && terrainObj.url.replace(/(^s*)|(s*$)/g, "").length >0) { var provider ={}; if(terrainObj.proxyUrl && terrainObj.proxyUrl.length>0) provider = {proxy:new Cesium.DefaultProxy(terrainObj.proxyUrl),url:terrainObj.url,requestWaterMask:terrainObj.requestWaterMask,requestVertexNormals:terrainObj.requestVertexNormals}; else provider = {url:terrainObj.url,requestWaterMask:terrainObj.requestWaterMask,requestVertexNormals:terrainObj.requestVertexNormals}; var terrainProvider = new Cesium.CesiumTerrainProvider(provider); this.cesiumViewer.terrainProvider = terrainProvider; } }
RequestWaterMask 和 requestVertexNormals 的配置選項,是告訴 Cesium 需要額外的獲取水和照明效果。默認情況下他們設置是 false。
更多的詳情見:GIS之家小專欄
文章尾部提供源代碼下載,對本專欄感興趣的話,可以關注一波