<< Click to Display Table of Contents >> Navigation: 3D API 應用範例 > 地下管線設施 |
<說明>
在本範例中,我們將示範如何將您立體管線於圖台上展示,說明如下:
<範例>
var earth_ = null;
function documentLoad() { SuperGIS.Initialize("/ServerGate/", function () { SuperGIS.ServerEarth.Initialize(InitEarth); }); }
function InitEarth() { var pBody = new SuperGIS.Windows.HTMLContainer(document.body);
var sHost = location.href; var idx = sHost.indexOf("/", 8); if (idx >= 0) sHost = sHost.substring(0, idx); CreateHTML5Earth(pBody, function (pEarth) { EarthLoaded(pEarth); });
function EarthLoaded(pEarth) { earth_ = pEarth; pEarth.Scene.BackgroundColor = pEarth.CreateColor(0, 0, 0, 1); pEarth.SetupSystem(true, s_WGS84); pEarth.SetupSkin(pEarth.CreateEnvelope(-180, 180, -90, 90, s_WGS84), sHost + "/ServerGate/Skin1.jpg"); pEarth.MajorGraticule.Visible = false; pEarth.MinorGraticule.Visible = false;
// 指定向量磚服務的 WMTS 網址, 欲加入的圖層名稱, 及 callback function 名稱 VLayer = new SuperGIS.VectorLayer(getDataServicePath() + 'project_line/SimpleWMTS.aspx', pEarth, { layer: '管線' }, PipeFinish); VLayer.setPickable(true); // 設定此圖層可利用 Picking 點選
pEarth.SetViewpoint(120.656, 24.160, 500, 0, 50, true);
var pTObj = pEarth.GetObject(); pTObj.addEventListener("click", QueryAttribute, false, true); // 引入 click 事件
var pCam = pEarth.GetCamera(); pCam.addEventListener("changed", CameraChanged, false); // Camera 狀態改變時觸發 }
// 在 callback 中設定每個 feature 的符號樣式 function PipeFinish(array) { var rv = 128, gv = 255, bv = 128; for (var i = 0; i < array.length; i++) { var mark = array[i]; var depth = mark.GetFieldValue("高");
var LSym = null;
if (depth == 1) { var fc = earth_.CreateColor(0.75, 0.5, 0.5, 0.5); LSym = earth_.CreateRoundPipeSymbol(earth_.CreateModelMaterial(0, fc), 1, 1); // 圓形管線符號, 末兩參數: 管徑, ratio } else { var fc = earth_.CreateColor(0.5, 0.75, 0.5, 0.5); LSym = earth_.CreateSquarePipeSymbol(earth_.CreateModelMaterial(0, fc), 1.5, 1); // 方形管線符號 }
mark.ReplaceZ = -depth; // 設定高程 (公尺, 負值為地下) mark.DDDSymbol = LSym; } }
var pInfoWindow = null; function QueryAttribute(tEvent) { if (pInfoWindow != null) { pInfoWindow.close(); pInfoWindow = null; }
if (tEvent.button == 2) // 使按右鍵無作用 return;
var pScene = earth_.GetScene(); var pCamera = earth_.GetCamera(); var pGlobe = earth_.GetGlobe();
var CurPosition = pScene.PositionFromDevice(new SuperGIS.DDDCore.Vector3(tEvent.x, tEvent.y, 0)); var pPick = earth_.PlacemarkObjects.Picking(SuperGIS.DDDCore.RenderPriority.Unknown, pCamera.EyeAt, pCamera.Ray(CurPosition), 0); if (pPick != null) { var pm = pPick.Target; var feaData = pm.GetFieldValues();
var infoStr = '<table border="1">'; for (var f in feaData) { infoStr += "<tr><td>"; infoStr += f; infoStr += "</td><td>"; infoStr += feaData[f]; infoStr += "</td></tr>"; } infoStr += '</table>';
var CurLocation = pGlobe.RayTest(pCamera.EyeAt, pCamera.Ray(CurPosition), 1, true); pt = pGlobe.GeodeticFromCartesian(CurLocation);
// infoStr 為 Content 內容 // pt 為視窗出現的空間坐標 // 支援的 option 有 maxWidth (視窗最大寬度); pixelOffsetX/pixelOffsetY: X/Y 方向的視窗位移 pInfoWindow = new SuperGIS.InfoWindow(infoStr, pt, { maxWidth: 250, pixelOffsetX: 100, pixelOffsetY: 0 }); // 建立屬性視窗 pInfoWindow.open(earth_, document.getElementById("example"));
SuperGIS.Event.addListener(pInfoWindow, "closeclick", OnCloseClick); // 監聽屬性視窗的 close 事件 SuperGIS.Event.addListener(pInfoWindow, "content_changed", OnContentChange); // 監聽屬性視窗的 content change 事件 SuperGIS.Event.addListener(pInfoWindow, "position_changed", OnPositionChange); // 監聽屬性視窗的 position change 事件 } }
function CameraChanged(tEvent) { // Camera 狀態改變就關掉視窗 if (pInfoWindow != null) { pInfoWindow.close(); pInfoWindow = null; } } }
|
© 2017 Supergeo Technologies Inc.