001/*
002 * To change this template, choose Tools | Templates
003 * and open the template in the editor.
004 */
005
006package armyc2.c5isr.web.render;
007import armyc2.c5isr.renderer.utilities.IPointConversion;
008import armyc2.c5isr.graphics2d.Point2D;
009import armyc2.c5isr.graphics2d.Point;
010import android.graphics.PointF;
011/**
012 *
013*
014 */
015public class PointConverter implements IPointConversion
016{
017    private double _controlLat=0;
018    private double _controlLong=0;
019    private double _scale=0;
020    private double _metersPerPixel=0;
021    private boolean _normalize=true;
022    
023    public PointF PixelsToGeo(PointF pixel)
024    {
025        return  null;
026    }
027
028    public PointF GeoToPixels(PointF coord)
029    {
030        return null;
031    }
032    
033    public void set_normalize(boolean value)
034    {
035        _normalize=value;
036    }
037    
038    public PointConverter(double controlLong, double controlLat, double scale)
039    {
040        try
041        {
042            this._controlLat=controlLat;
043            this._controlLong=controlLong;
044            this._scale=scale;
045            _metersPerPixel=GeoPixelConversion.metersPerPixel(scale);
046        }
047        catch(Error e)
048        {
049            throw e;
050        }
051    }
052    /**
053     * add constructor to handle when earth is flipped about it's X axis (South is on top)
054     * @param left
055     * @param right
056     * @param top
057     * @param bottom
058     * @param scale 
059     */
060    public PointConverter(double left, double top, double right, double bottom, double scale)
061    {
062        try
063        {
064            this._controlLat=top;
065            this._controlLong=left;
066            this._scale=scale;
067            _metersPerPixel=GeoPixelConversion.metersPerPixel(scale);
068            if(top<bottom)
069                _metersPerPixel=-_metersPerPixel;
070        }
071        catch(Error e)
072        {
073            throw e;
074        }
075    }
076    public Point2D PixelsToGeo(Point pixel)
077    {
078        Point2D pt2dGeo=null;
079        try
080        {
081            double y=GeoPixelConversion.y2lat(pixel.getY(), _scale, _controlLat, _metersPerPixel);
082            double x=GeoPixelConversion.x2long(pixel.getX(), _scale, _controlLong, y, _metersPerPixel);
083            pt2dGeo=new Point2D.Double(x,y);
084        }
085        catch(Error e)
086        {
087            throw e;
088        }
089        return pt2dGeo;
090    }
091
092    public Point2D PixelsToGeo(Point2D pixel)
093    {
094        Point2D pt2dGeo=null;
095        try
096        {
097            double y=GeoPixelConversion.y2lat(pixel.getY(), _scale, _controlLat, _metersPerPixel);
098            double x=GeoPixelConversion.x2long(pixel.getX(), _scale, _controlLong, y, _metersPerPixel);
099            pt2dGeo=new Point2D.Double(x,y);
100        }
101        catch(Error e)
102        {
103            throw e;
104        }
105        return pt2dGeo;
106    }
107
108    public Point2D GeoToPixels(Point2D coord)
109    {
110        Point2D pt2DPixels=null;
111        try
112        {
113            double y=GeoPixelConversion.lat2y(coord.getY(), _scale, _controlLat, _metersPerPixel);
114            double x=GeoPixelConversion.long2x(coord.getX(), _scale, _controlLong, coord.getY(), _metersPerPixel, _normalize);
115            pt2DPixels=new Point2D.Double(x, y);
116        }
117        catch(Error e)
118        {
119            throw e;
120        }
121        return pt2DPixels;
122    }
123}