滑鼠拖曳平移地圖

<< Click to Display Table of Contents >>

Navigation:  3D API 說明範例 > 功能 > 基本控制項 >

滑鼠拖曳平移地圖

 

 

檢視範例

範例下載

 

 

<說明>

在本範例中,我們將示範如何操作滑鼠拖曳平移地圖,說明如下:

 

 

<範例>

  var earth_ = null;

 

         function documentLoad()

         {

             document.body.style.overflow = "hidden";

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

 

             var pNavi = pEarth.GetCurrentTool(); // 取得目前的 Navigation Tool

             pNavi.ExitTool(); // 關掉所有 Navigation Tool 的事件監聽

             pNavi.WheelEnable = false; // 關閉滾輪

             pNavi.ZoomSpeed = 3; // 設定 Zoom 速度 (預設值 2)

             pNavi.ZoomTimeout = 1; // 設定 Zoom 持續時間 (單位: 秒, 預設值 0.5)

             pNavi.InitTool(pEarth); // 重新啟動 Navigation Tool 的事件監聽

 

             pEarth.addEventListener("mousewheel", mousewheelTest, false); // 自訂滑鼠滾輪滾動時觸發

         }

 

         function mousewheelTest(tEvent) {

             var pScene = earth_.GetScene();

             var pNavi = earth_.GetCurrentTool();

 

             var tPos = pScene.GetCursorPosition(tEvent); // 取得目前游標位置

             var nDelta = tEvent.wheelDelta ? tEvent.wheelDelta : -tEvent.detail; // 取得滾輪資料

 

             var nD = (nDelta > 0 ? 1 : nDelta < 0 ? -1 : 0) * (pNavi.WheelDirection ? 1 : -1); // 決定方向

             // WheelDirection 為 true 時, 向前滾為離開; 向後滾為拉近

 

             pNavi.Zoom(tPos, tEvent.shiftKey, nD); // 呼叫 Navigation Tool 的 Zoom 功能

             // 傳入 Zoom 的中心; 是否按下 ShiftKey (若不希望有作用傳入 0); Zoom 的方向 (1: 離開, -1: 拉近)

         }

       }

 

 

 

 


© 2017 Supergeo Technologies Inc.