K_Reverter的网页开发记录

要么不做,要么就当作艺术品来做!

导航

Google Maps API 2.0解析(5-GPoint GSize GBounds)

 

//GPoint类,该类在1.0之中同时可以代表一个地理位置点,现在,这个功能已经被GLatLng代替了,2.0之中只代表屏幕像素位置
  function GPoint(a,b)
  {
   
this.x=a;
   
this.y=b
  }
  GPoint.ORIGIN
=new GPoint(0,0);
  
//转化成字符串
  GPoint.prototype.toString=function()
  {
   
return"("+this.x+""+this.y+")"
  };
  
//检查两个点是否相等
  GPoint.prototype.equals=function(a)
  {
   
if(!a)return false;
   
return a.x==this.x&&a.y==this.y
  };
  
//GSize类,代表屏幕位置大小
  function GSize(a,b)
  {
   
this.width=a;
   
this.height=b
  }
  GSize.ZERO
=new GSize(0,0);
  
//转化成字符串
  GSize.prototype.toString=function()
  {
   
return"("+this.width+""+this.height+")"
  };
  
//监察两个大小对象是否相等
  GSize.prototype.equals=function(a)
  {
   
if(!a)return false;
   
return a.width==this.width&&a.height==this.height
  };
  
//GBounds对象,代表屏幕的矩形范围,参数是GPoint点列表,将会根据该列表得到一个包含这些点的矩形范围
  function GBounds(a)
  {
   
this.minX=(this.minY=GMath_MaxValue);
   
this.maxX=(this.maxY=-GMath_MaxValue);
   
var b=arguments;
   
if(a&&a.length)
   {
    
for(var c=0;c<a.length;c++)
    {
     
this.extend(a[c])
    }
   }
   
else if(b.length>=4)
   {
    
this.minX=b[0];
    
this.minY=b[1];
    
this.maxX=b[2];
    
this.maxY=b[3]
   }
  }
  
//矩形上最小坐标位置
  GBounds.prototype.min=function()
  {
   
return new GPoint(this.minX,this.minY)
  };
  
//矩形上最大坐标位置
  GBounds.prototype.max=function()
  {
   
return new GPoint(this.maxX,this.maxY)
  };
  
//转化成字符串
  GBounds.prototype.toString=function()
  {
   
return"("+this.min()+""+this.max()+")"
  };
  
//是否包含制定的矩形
  GBounds.prototype.containsBounds=function(a)
  {
   
var b=this;
   
return b.minX<a.minX&&b.maxX>a.maxX&&b.minY<a.minY&&b.maxY>a.maxY
  };
  
//扩展以包含指定的点
  GBounds.prototype.extend=function(a)
  {
   
var b=this;
   b.minX
=GetMathMin(b.minX,a.x);
   b.maxX
=GetMathMax(b.maxX,a.x);
   b.minY
=GetMathMin(b.minY,a.y);
   b.maxY
=GetMathMax(b.maxY,a.y)
  };
  
//获取两个矩形范围的交叉区域
  GBounds.intersection=function(a,b)
  {
   
return new GBounds([new GPoint(GetMathMax(a.minX,b.minX),GetMathMax(a.minY,b.minY)),new GPoint(GetMathMin(a.maxX,b.maxX),GetMathMin(a.maxY,b.maxY))])
  };

        这三个类是提供屏幕坐标描述的对象,以前的API之中也有这几个,可是以前的代码非常简单,并不包含什么方法,而且适用范围包含地理点的坐标,而现在的不适合这么用了

posted on 2006-05-08 23:55  K_Reverter  阅读(1047)  评论(0编辑  收藏  举报