

/*  3DGeospatial Web Mapping Framework, version 1.0
*  (c) 2008 Cloudshadow Consulting LLC
*  Author: Geoffrey Anderson
*  
*
*--------------------------------------------------------------------------*/


function LineString(){}

LineString.prototype.dimension=function(){}
LineString.prototype.coordinateDimension=function(){}
LineString.prototype.spatialDimension=function(){}
LineString.prototype.gemetryType=function(){return "LineString";}
LineString.prototype.SRID=function(){return this.srid;}
LineString.prototype.envelope=function(){}
LineString.prototype.asText=function(){}
LineString.prototype.asBinary=function(){}
LineString.prototype.isEmpty=function(){}
LineString.prototype.isSimple=function(){}
LineString.prototype.is3D=function(){}
LineString.prototype.isMeasured=function(){}
LineString.prototype.boundary=function(){}

LineString.prototype.length=function(){}
LineString.prototype.startPoint=function(){}
LineString.prototype.endPoint=function(){}
LineString.prototype.isClosed=function(){}
LineString.prototype.isRing=function(){}
LineString.prototype.numPoints=function(){}
LineString.prototype.pointN=function(){}

function LinearRing(){}

function Line(){}

function Polygon(){}

Polygon.prototype.dimension=function(){}
Polygon.prototype.coordinateDimension=function(){}
Polygon.prototype.spatialDimension=function(){}
Polygon.prototype.gemetryType=function(){return "Point";}
Polygon.prototype.SRID=function(){return this.srid;}
Polygon.prototype.envelope=function(){}
Polygon.prototype.asText=function(){return "POINT(" + this.X() + " " + this.Y() + ")";}
Polygon.prototype.asBinary=function(){}
Polygon.prototype.isEmpty=function(){}
Polygon.prototype.isSimple=function(){}
Polygon.prototype.is3D=function(){}
Polygon.prototype.isMeasured=function(){}
Polygon.prototype.boundary=function(){}

Polygon.prototype.area=function(){}
Polygon.prototype.centroid=function(){}
Polygon.prototype.pointOnSurface=function(){}
Polygon.prototype.boundary=function(){}
Polygon.prototype.exteriorRing=function(){}
Polygon.prototype.numInteriorRing=function(){}
Polygon.prototype.interiorRingN=function(N){}

function Point(x,y,z,m,srid){
   this.x=x;
   this.y=y;
   this.z=z;
   this.m=m;
   this.srid=srid;
}


Point.prototype.dimension=function(){}
Point.prototype.coordinateDimension=function(){}
Point.prototype.spatialDimension=function(){}
Point.prototype.gemetryType=function(){return "Point";}
Point.prototype.SRID=function(){return this.srid;}
Point.prototype.envelope=function(){}
Point.prototype.asText=function(){return "POINT(" + this.X() + " " + this.Y() + ")";}
Point.prototype.asBinary=function(){}
Point.prototype.isEmpty=function(){}
Point.prototype.isSimple=function(){}
Point.prototype.is3D=function(){}
Point.prototype.isMeasured=function(){}
Point.prototype.boundary=function(){}

Point.prototype.X=function(){return this.x;}
Point.prototype.Y=function(){return this.y;}
Point.prototype.Z=function(){return this.z;}
Point.prototype.M=function(){return this.m;}


function Envelope(xmin,ymin,xmax,ymax,srid){
   this.xmin=xmin;
   this.ymin=ymin;
   this.xmax=xmax;
   this.ymax=ymax;
   this.srid=srid;
}

Envelope.prototype.dimension=function(){}
Envelope.prototype.coordinateDimension=function(){}
Envelope.prototype.spatialDimension=function(){}
Envelope.prototype.gemetryType=function(){return "Envelope";}
Envelope.prototype.SRID=function(){return this.srid;}
Envelope.prototype.envelope=function(){}
Envelope.prototype.asText=function(){}
Envelope.prototype.asBinary=function(){}
Envelope.prototype.isEmpty=function(){}
Envelope.prototype.isSimple=function(){}
Envelope.prototype.is3D=function(){}
Envelope.prototype.isMeasured=function(){}
Envelope.prototype.boundary=function(){}
Envelope.prototype.area=function(){}
Envelope.prototype.centroid=function(){
   center_x=this.xmin + (this.getWidth()/2);
   center_y=this.ymin + (this.getHeight()/2);
   return new Point(center_x,center_y,null,null,this.SRID());
}
Envelope.prototype.pointOnSurface=function(){}
Envelope.prototype.boundary=function(){}
Envelope.prototype.exteriorRing=function(){}
Envelope.prototype.numInteriorRing=function(){}
Envelope.prototype.interiorRingN=function(N){}

Envelope.prototype.getWidth=function(){return this.xmax-this.xmin;}
Envelope.prototype.getHeight=function(){return this.ymax-this.ymin;}
Envelope.prototype.getDim=function(){return {width:this.getWidth(),height:this.getHeight()};}
Envelope.prototype.getRatio=function(){return {w2h:this.getWidth()/this.getHeight(),h2w:this.getHeight()/this.getWidth()};}


function BBox(envelope){

   this.envelope=envelope;
   this.geo_width=this.getWidth();
   this.geo_height=this.getHeight();
}

BBox.prototype.getWidth=function() {return this.envelope.getWidth();}
BBox.prototype.getHeight=function(){return this.envelope.getHeight();}
BBox.prototype.makePropBox=function(width,height){

ratio=this.envelope.getRatio();
if(height==null){
height=width/ratio.w2h;}
else{
width=ratio.w2h*height;}
return {width:width,height:height};
}

BBox.prototype.bbox=function(){return this.envelope.xmin + "," + this.envelope.ymin + "," + this.envelope.xmax + "," + this.envelope.ymax;}

//var env=new Envelope(139982.34375,4094070.25,763218.75,4546718,"26913");
//335580,3570680,345310,3586810
/*
        extent:{
                xmin:139982.34375,
                ymin:4094070.25,
                xmax:763218.75,
                ymax:4546718,
                srid:"26913"
        },
*/



function GMap(envelope){

	this.envelope=envelope;
                                      
	this.bbox=new BBox(this.envelope);
	
     
        
}

GMap.prototype.setContainer=function(obj){
    
    this.container=obj;
    
}

GMap.prototype.getOffsetPosition=function(e){
      var pos=findPos(this.container);
      var top  =e.clientY - pos.left;
      var left =e.clientX - pos.top;
      return {top:top,left:left};
  }

GMap.prototype.page2world=function(screenX,screenY){
	yFlip	=this.viewBox.height-screenY;
	//gRatio  =this.envelope.getRatio();
	wScale=this.envelope.getWidth()/this.viewBox.width;
	hScale=this.envelope.getHeight()/this.viewBox.height;
	xd=screenX * wScale;
	yd=yFlip*hScale;
	realX=this.envelope.xmin+xd;
	realY=this.envelope.ymin+yd;
	return new Point(realX,realY,null,null,this.envelope.srid);

}

GMap.prototype.world2page=function(geoX,geoY){



        imgX=    ((geoX-this.envelope.xmin) / this.envelope.getWidth())  * this.viewBox.width;
        imgY=    ((this.envelope.ymax-geoY) / this.envelope.getHeight()) * this.viewBox.height;
        return {x:imgX,y:imgY};

}

GMap.prototype.zoom=function(gPoint,zFactor){
	
        var imageWIDTH  = this.viewBox.width;
        var imageHEIGHT =  this.viewBox.height;

        var gW = this.envelope.getWidth();
        var gH = this.envelope.getHeight();
        var wScale = gW / imageWIDTH;
        var hScale = gH / imageHEIGHT;


        var newxmin = gPoint.x - wScale*imageWIDTH /(2.0*zFactor);
        var newxmax = newxmin + gW/zFactor;
        
	var newymin = gPoint.y - hScale*imageHEIGHT/(2.0*zFactor);
        var newymax = newymin + gH/zFactor;
	
	newE=new Envelope(newxmin,newymin,newxmax,newymax,this.envelope.srid);
	return newE;

}




GMap.prototype.setViewBox=function(width,height){
	this.viewBox=this.bbox.makePropBox(width,height);
}





function findPos(obj){
    
    var curleft=0;
    var curtop=0;
    
    if(obj.offsetParent){
        
        do{
            	curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
        }
        while(obj=obj.offsetParent);   
    }
    return {left:curleft,top:curtop};
}



