Google Maps API 2.0解析(9-GProjection GMercatorProjection关于投影坐标系统)

 

// 投影坐标接口,不能实例化,而必须通过继承来使用
   function  GProjection()
  {
  }
  
// 从经纬度转化为像素,a是一个GLatLng,b是缩放等级
  GProjection.prototype.fromLatLngToPixel = function (a,b)
  {
   
throw  GMsg_Implement;
  };
  
// 从像素转化为经纬度,a是GPoint点,b是缩放等级,c如果为true,将不会强制将返回结果限制在-180~180之间
  GProjection.prototype.fromPixelToLatLng = function (a,b,c)
  {
   
throw  GMsg_Implement;
  };
  
// 返回指定的图片序号是否在正常的范围之内,如果经度不在范围内,则转化为范围之内,如果纬度不再范围之内,则返回false
  GProjection.prototype.tileCheckRange = function (a,b,c)
  {
   
return   true
  };
  
// 返回某一缩放等级下地图的横向像素宽度
  GProjection.prototype.getWrapWidth = function (a)
  {
   
throw  GMsg_Implement;
  };
  
// 本对象继承了GProjection接口,代表莫卡托投影坐标,参数a代表缩放等级的个数
   // 缩放等级为0的时候,刚好可以将全球在宽度为128的图片上展示出来
   function  GMercatorProjection(a)
  {
   
var  b = this ;
   b.pixelsPerLonDegree
= [];
   b.pixelsPerLonRadian
= [];
   b.bitmapOrigo
= [];
   b.numTiles
= [];
   
var  c = 256 ;
   
for ( var  d = 0 ;d < a;d ++ )
   {
    
var  e = c / 2 ;
    b.pixelsPerLonDegree.push(c
/ 360 );
    b.pixelsPerLonRadian.push(c
/ ( 2 * GMath_PI));
    b.bitmapOrigo.push(
new  GPoint(e,e));
    b.numTiles.push(c);
    c
*= 2
   }
  }
  GMercatorProjection.prototype
= new  GProjection();  // 指定继承GProjection接口
   // 实现fromLatLngToPixel方法
  GMercatorProjection.prototype.fromLatLngToPixel = function (a,b)
  {
   
var  c = this ;
   
var  d = c.bitmapOrigo[b];
   
var  e = getMathRound(d.x + a.lng() * c.pixelsPerLonDegree[b]);
   
var  f = GetNumberInRange(Math.sin(getRadianByDegree(a.lat())), - 0.9999 , 0.9999 );
   
var  g = getMathRound(d.y + 0.5 * Math.log(( 1 + f) / ( 1 - f)) *- c.pixelsPerLonRadian[b]);
   
return   new  GPoint(e,g)
  };
  
// 实现fromPixelToLatLng方法
  GMercatorProjection.prototype.fromPixelToLatLng = function (a,b,c)
  {
   
var  d = this ;
   
var  e = d.bitmapOrigo[b];
   
var  f = (a.x - e.x) / d.pixelsPerLonDegree[b];
   
var  g = (a.y - e.y) /- d.pixelsPerLonRadian[b];
   
var  h = getDegreeByRadian( 2 * Math.atan(Math.exp(g)) - GMath_PI / 2 );
   
return   new  GLatLng(h,f,c)
  };
  
// 实现tileCheckRange方法
  GMercatorProjection.prototype.tileCheckRange = function (a,b,c)
  {
   
var  d = this .numTiles[b];
   
if (a.y < 0 || a.y * c >= d)
   {
    
return   false
   }
   
if (a.x < 0 || a.x * c >= d)
   {
    
var  e = getMathFloor(d / c);
    a.x
= a.x % e;
    
if (a.x < 0 )
    {
     a.x
+= e
    }
   }
   
return   true
  };
  
// 实现getWrapWidth方法
  GMercatorProjection.prototype.getWrapWidth = function (a)
  {
   
return   this .numTiles[a]
  };

        这次Google将坐标系统和地图类型也进行了分离,这样似乎就更灵活一点了,可以通过实现GProjection开发自己的坐标系统,不过,我觉得在Google现有的图片显示模式下,似乎不大可能太灵活,具体的地方我还没有看到,下面会继续学习。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值