線段沿線高程

<< 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.getElementById("example"));

 

         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), "");

             pEarth.MajorGraticule.Visible = false;

             pEarth.MinorGraticule.Visible = false;

 

             Dtm = new SuperGIS.DTMLayer("http://203.66.168.227/TGOS3D_WMTS/World/SimpleWMTS_GLOBE_W_D.aspx?apikey=mcXodoZFWJaUJRFS5H3gCec83a570/QupBX5ROqlSmu9vZW61YOYMe86Om9zQ2g2pVSGtjfLi5gex++mKHMFNK95UFUwZD3TtpSdH73WhL5KMv0WZVPMe5rB4KiLpaRrReusEFx+W10=&appid=BHvpiOJ5Wp41CsxemFMNWQ==",

                                               pEarth, { layer: 'Map' }, null);

 

             // 指定圖磚服務的 WMTS 網址, 欲加入的圖層名稱, dtm layer 及 callback function 名稱

             //Tile = new SuperGIS.TileLayer(getDataServicePath() + 'TC_fly/SimpleWMTS.aspx',

               //                                pEarth, { layer: 'TC' }, Dtm, null);

             Tile = new SuperGIS.TileLayer("http://203.66.168.227/TGOS3D_WMTS/World/SimpleWMTS_GLOBE_W.aspx?apikey=mcXodoZFWJaUJRFS5H3gCec83a570/QupBX5ROqlSmu9vZW61YOYMe86Om9zQ2g2pVSGtjfLi5gex++mKHMFNK95UFUwZD3TtpSdH73WhL5KMv0WZVPMe5rB4KiLpaRrReusEFx+W10=&appid=BHvpiOJ5Wp41CsxemFMNWQ==",

                                               pEarth, { layer: 'Map' }, Dtm, null);

 

             pEarth.SetViewpoint(120.789, 24.160, 3000, 0, 50, true);

 

             pEarth.addEventListener("mousedown", QueryElevation, false);

             pEarth.addEventListener("mousemove", MouseMove, false);

 

             var pCam = pEarth.GetCamera();

             pCam.addEventListener("changed", CameraChanged, false); // Camera 狀態改變時觸發

         }

 

         function getElevation(x, y)

         {

             var pCam = earth_.GetCamera();

             var earthPos = earth_.CreateLatLonAlt(y, x, 0);

 

             var cartesian = earth_.GetGlobe().CartesianFromGeodetic(earthPos);

 

             var vx = cartesian.X;

             var vy = cartesian.Y;

             var vz = cartesian.Z;

 

             var ElevationPeyeat = earth_.CreateVector3(vx * 2, vy * 2, vz * 2);

 

             var ElevationPray = earth_.CreateVector3(vx * -1, vy * -1, vz * -1);

 

             var pPick = earth_.Objects.Picking(1, ElevationPeyeat, ElevationPray, 0);

             if (pPick == null)

                 return null;

 

             var rloc = pPick.GetLocate();

             var globeLoc = earth_.GetGlobe().GeodeticFromCartesian(rloc);

 

             var elevation = globeLoc.Altitude;

             return elevation;

         };

 

 

         var pInfoWindow = null;

         var nClick = 1;

         var pFirst = null;

         function QueryElevation(tEvent) {

             if (tEvent.button != 2) // 用右鍵進行

                 return;

 

             earth_.Invalidate();

             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_.Objects.Picking(SuperGIS.DDDCore.RenderPriority.Unknown, pCamera.EyeAt, pCamera.Ray(CurPosition), 0);

             if (pPick == null)

                 return;

 

             var rloc = pPick.GetLocate();

             var globeLoc = pGlobe.GeodeticFromCartesian(rloc);

             if (nClick == 1) // 記下第 1 點

             {

                 pFirst = globeLoc;

                 nClick++;

                 return;

             }

             if (nClick == 2)

                 nClick--;

 

             var x1 = pFirst.X;

             var y1 = pFirst.Y;

             var x2 = globeLoc.X;

             var y2 = globeLoc.Y;

 

             var dx = (x2 - x1) / 9;

             var dy = (y2 - y1) / 9;

 

             var infoStr = '<table border="1">';

               // 從起點到終點間內插共取 10 點 (含起終點) 來算高程

             for (var i = 0; i < 10; i++)

             {

                 var tx = x1 + dx * i;

                 var ty = y1 + dy * i;

                 var ele = getElevation(tx, ty);

 

                 infoStr += "<tr><td>";

                 infoStr += "#" + parseInt(i + 1);

                 infoStr += "</td><td>";

                 infoStr += parseFloat(tx).toFixed(5) + ", " + parseFloat(ty).toFixed(5);

                 infoStr += "</td><td>";

                 infoStr += parseFloat(ele).toFixed(1) + "公尺";

                 infoStr += "</td></tr>";

             }

             infoStr += '</table>';

 

             if (pInfoWindow != null) {

                 pInfoWindow.close();

                 pInfoWindow = null;

             }

 

             pInfoWindow = new SuperGIS.InfoWindow(infoStr, globeLoc, { maxWidth: 250, pixelOffsetX: 100, pixelOffsetY: 0 }); // 建立屬性視窗

             pInfoWindow.open(earth_, document.getElementById("example"));

         }

 

         function CameraChanged(tEvent) {

             // Camera 狀態改變就關掉視窗

             if (pInfoWindow != null) {

                 pInfoWindow.close();

                 pInfoWindow = null;

             }

         }

 

         function MouseMove(tEvent) {

             var pScene = earth_.GetScene();

             var pG = pScene.GetGraphics(2);

               if (nClick == 1)

                   pG.drawText("先點滑鼠右鍵 1 次決定線段起點", 20, 20, "black", "white", "18", "Consolas");

               else

                 pG.drawText("再點滑鼠右鍵 1 次決定線段終點", 20, 20, "black", "white", "18", "Consolas");

         }

       }

 

 

 

 

 

 

 


© 2017 Supergeo Technologies Inc.