平面坐標系模型
在部分項目中,三維數數據是根據平面坐標系進行建模的,並且以為某些需求,還不能轉為經緯度坐標系,所以就需要一些手段——將模型的坐標通過計算轉換后,將場景放置在了經線0°的位置(本初子午線)。
1.iDesktop中的操作
加載模型數據到平面場景中,確認無誤后,生成場景緩存(s3m),並且通過查詢坐標值找到模型的中心點。
2.Webgl中的操作(代碼)
iServer中將該工作空間發布為三維服務。發布后用由於Cesium不支持加載平面坐標系三維,所以在iserver中預覽會沒有任何模型,甚至報錯。
在webgl中加載發布的模型,首先viewer的sceneMode場景模式要設置為哥倫布模式(Cesium.SceneMode.COLUMBUS_VIEW)。然后再通過scene.open()添加模型。
代碼:
viewer = new Cesium.Viewer(‘cesiumContainer’);
viewer.scene.mode = Cesium.SceneMode.COLUMBUS_VIEW;
此時模型已經添加到場景中,但是Cesium無法識別平面坐標系坐標,無法定位到模型位置,因此需要對剛才在idesktop中獲取的中心點進行轉換。然后設置camera屬性,飛到模型中心。
轉換代碼:
var point = new Cesium.Cartesian3(X, Y, Z);
var pointCartographic = scene.camera._projection.unproject(point);
var pointCX = Cesium.Math.toDegrees(pointCartographic.longitude);
var pointCY = Cesium.Math.toDegrees(pointCartographic.latitude);
到此webgl已經可以加載平面坐標系模型並且展示,如果想完全模擬idesktop中的平面場景,可以通過替換球面背景圖來實現。
3.部分三維分析功能無法使用
截至2019/01/16,如果跟圖層操作較為密切的功能是無法實現的,如:地形挖方(需要地形數據),陰影分析,光照分析,控高分析(需要地形數據)等
正常使用且常用的:可視域分析,通視分析,天際線分析,場景飛行,測量;
4.完整代碼
// 加載平面場景模型 function onload(Cesium) { //初始化viewer部件 viewer = new Cesium.Viewer('cesiumContainer'); var scene = viewer.scene; var widget = viewer.cesiumWidget; viewer.scene.mode = Cesium.SceneMode.COLUMBUS_VIEW; viewer._cesiumWidget._creditContainer.style.display = 'none'; try { //打開所發布三維服務下的所有圖層 var url5 = "http://localhost:8090/iserver/services/3D-a701-a7-01/rest/realspace"; var promise = scene.open(url5); Cesium.when.all(promise, function(layers) { layers.forEach(function(item, index) { item.ignoreNormal = true // 獲取或者設置是否在GPU中自動計算法線 item.clearMemoryImmediately = true // 是否及時釋放內存 }) var point = new Cesium.Cartesian3(4057.48, 1554.01, 10); var pointCartographic = scene.camera._projection.unproject(point); var pointCX = Cesium.Math.toDegrees(pointCartographic.longitude); var pointCY = Cesium.Math.toDegrees(pointCartographic.latitude); //設置相機位置,定位至模型 scene.camera.flyTo({ destination: Cesium.Cartesian3.fromDegrees(pointCX, pointCY, pointCartographic.height), orientation: { heading: 0, pitch: 0, roll: 0 } }); }, function(e) { if (widget._showRenderLoopErrors) { var title = '加載SCP失敗,請檢查網絡連接狀態或者url地址是否正確?'; widget.showErrorPanel(title, undefined, e); } }); } catch (e) { if (widget._showRenderLoopErrors) { var title = '渲染時發生錯誤,已停止渲染。'; widget.showErrorPanel(title, undefined, e); } } }