/**
 * Geometry class
 */
function Geometry() {
    this.bottomLeft; // OpenLayers.Pixel
    this.bottomRight; // OpenLayers.Pixel
    this.center; // OpenLayers.Pixel

    /**
     * Define the geometry using two points (box)
     * @param {OpenLayers.Pixel} Lower Left point
     * @param {OpenLayers.Pixel} Upper Right point
     */
    this.setBounds = function(bottomLeft, topRight) {
        this.bottomLeft = bottomLeft;
        this.topRight = topRight;
    }

    /**
     * Define the geometry using a center point and a jitter value
     * @param {OpenLayers.Pixel} center point
     * @param {Int} Number of pixels to expand the point to make a geometry
     */
    this.setCenter = function(center, jitter) {
        this.center = new OpenLayers.Pixel(center.x, center.y);
        this.bottomLeft = new OpenLayers.Pixel(center.x - jitter, center.y + jitter);
        this.topRight = new OpenLayers.Pixel(center.x + jitter, center.y - jitter);
    }

    /**
     * Return a textual representation of the center point of this geometry object
     */
    this.getCenterGeomText = function(map) {
       // Convert the pixel based coordinates to map coordinates
       var gCenter = map.getLonLatFromViewPortPx(this.center);
      
       // Transform the coordinate from google coordinates (m) to lat/lon
       gCenter.transform(map.getProjectionObject(), map.displayProjection);
   
       return JSON.stringify(gCenter);

//       return "GeomFromText('POINT(" + gCenter.lon + " " + gCenter.lat +")',4326)";
    }
    /**
     * Return a textual representation of this geometry object suitable for use with PostGIS
     * @return {String}
     */
    this.getGeometryText = function(map) {
    
        // Convert the pixel based coordinates to map coordinates
        var gBottomLeft = map.getLonLatFromViewPortPx(this.bottomLeft);
        var gTopRight = map.getLonLatFromViewPortPx(this.topRight);

        // Transform the coordinate from google coordinates (m) to lat/lon
        gBottomLeft.transform(map.getProjectionObject(), map.displayProjection);
        gTopRight.transform(map.getProjectionObject(), map.displayProjection);

        var box = {};
        box.bottomLeft = gBottomLeft;
        box.topRight = gTopRight;
        return JSON.stringify(box);
/*
        return "GeomFromText('POLYGON((" + gBottomLeft.lon + " " + gBottomLeft.lat + ", " +
                                     gBottomLeft.lon + " " + gTopRight.lat + ", " +
                                     gTopRight.lon + " " + gTopRight.lat + ", " +
                                     gTopRight.lon + " " + gBottomLeft.lat + ", " +
                                     gBottomLeft.lon + " " + gBottomLeft.lat +"))',4326)";
*/
    }
}
    
