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);   //最后一个参数是放大倍数,  第一、二参数是经纬度

    

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