Cesium入門6 - Adding Imagery - 添加圖層
Cesium中文網:http://cesiumcn.org/ | 國內快速訪問:http://cesium.coinidea.com/
Cesium應用程序另一個關鍵元素是Imagery(圖層)。瓦片圖集合根據不同的投影方式映射到虛擬的三維數字地球表面。依賴於相機指向地表的方向和距離,Cesium會去請求和渲染不同層級的圖層詳細信息。
多種圖層能夠被添加、移除、排序和適應到Cesium中。
Cesium提供了一系列方法用於處理圖層,比如顏色自適應,圖層疊加融合。一些樣例代碼如下:
- Adding basic imagery添加基本圖層
- Adjusting imagery colors自適應圖層顏色
- Manipulating and ordering imagery layers控制調整圖層順序
- Splitting imagery layers切割圖層
Cesium提供了各種接口支持各樣的圖層數據源。
支持的圖層格式
- wms
- TMS
- WMTS (with time dynamic imagery)
- ArcGIS
- Bing Maps
- Google Earth
- Mapbox
- OpenStreetMap
注意:不同的數據源需要不同的認證 - 需要確保自己能夠有權限訪問到這些數據源,自然地需要注冊特定的認證才可以
默認地,Cesium使用Bing Maps作為默認的圖層。這個圖層被打包進Viewer中用於演示。Cesium需要您自己創建ion account然后生成一個access key用於訪問圖層數據。
在接下來的例子中,將使用Cesium ion中的Sentinel-2圖層。
-
去Cesium ion頁面,將Sentinel-2圖層加入到自己的assets中。點擊在導航欄中點擊“Asset Depot”
-
點擊“Add to my assets”。Sentinel-2將在你個人用戶中的asset列表(My Assets)中出現,此時將在個人的app中圖層數據源變得可用。
-
代碼級別:我們創建一個IonImageryProvider,將assetId傳給對應的Sentinel-2圖層。然后我們將ImageryProvider添加到viewer.imageryLayers。
// Remove default base layer
viewer.imageryLayers.remove(viewer.imageryLayers.get(0));
// Add Sentinel-2 imagery
viewer.imageryLayers.addImageryProvider(new Cesium.IonImageryProvider({ assetId : 3954 }));
基於上述的代碼,我們的Cesium應用程序在縮進zoom in的時候會看到如下圖層:
關於圖層的更多信息:請訪問Imagery Layers Tutorial
Cesium中文網交流QQ群:807482793
Cesium中文網:http://cesiumcn.org/ | 國內快速訪問:http://cesium.coinidea.com/