google earth開發(八)地球旋轉和放大縮寫、以及指定位置打開

(1)打開到中國位置

    function locationToChina()
     {
        var la = ge.createLookAt('');
        la.set(33,105.46, 0, ge.ALTITUDE_RELATIVE_TO_GROUND,
               0, 0, 4000000);   //最後一個參數是放大倍數,可根據頁面大小調整.  第一、二位置是中國中心位置經緯度
        ge.getView().setAbstractView(la);
     }
(2)地球旋轉

      a)定義全局參數

             var speed =  10;  // degrees per second
            var lastMillis = (new Date()).getTime();
      b)設置事件

            ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT);
            google.earth.addEventListener(ge, "frameend", rotateEarth);   //設置事件,地圖畫完事件
            rotateEarth();  //第一次人工啓動下。記住不加這一行,可能不旋轉。

      c)事件處理函數

         function rotateEarth(){
           var now = (new Date()).getTime();
          // dt is the delta-time since last tick, in seconds
          var dt = (now - lastMillis) / 1000.0;
          lastMillis = now;

          var lookAt = ge.getView().copyAsLookAt     (ge.ALTITUDE_RELATIVE_TO_GROUND);
           var nextLong=lookAt.getLongitude() + speed*dt;
           if(nextLong>180)
                 nextLong=nextLong-360;
           lookAt.set(33,nextLong,
                0, ge.ALTITUDE_RELATIVE_TO_GROUND,
                0, 0, 10000000);
             ge.getView().setAbstractView(lookAt);

       }    

 

    d)停止旋轉

         google.earth.removeEventListener(ge,"frameend", rotateEarth);

(3)放大縮小

      和上面函數一樣

       lookAt.set(33,   30,
                      0, ge.ALTITUDE_RELATIVE_TO_GROUND,
                      0, 0, 10000000);   //最後一個參數是放大倍數,  第一、二參數是經緯度

    

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章