org.free.garminimg.utils
Class MapTransformer<T>

java.lang.Object
  extended by org.free.garminimg.utils.MapTransformer<T>
All Implemented Interfaces:
java.lang.Cloneable

public class MapTransformer<T>
extends java.lang.Object
implements java.lang.Cloneable

Generic class used to do the conversion between 4 different coordinate systems:

Since this class is heavily used, a lot of care has been taken to avoid performance problems (mainly memory allocation).


Nested Class Summary
static interface MapTransformer.Converter<T2>
          Interface for the class converting from/to the user defined coordinate system and datum to/from WGS84.
 
Constructor Summary
MapTransformer(MapTransformer.Converter<T> converter, int margin)
           
 
Method Summary
 void adjustAutoScaleFromWgs84(double lon, double lat)
          takes a radian WGS84 coordinate and adjust the scale/position to include this coordinate.
 void changeDimensions(int width, int height)
          Use it to change the dimensions of the display area (in screen pixel).
 MapTransformer<T> clone()
           
 T createTempCoord()
           
 boolean equals(java.lang.Object o)
           
 void fixAspectRatio()
          Once several calls to adjustAutoScale have been done, call this to make sure the aspect ratio is correct.
 void garminGeo2Map(int[] longitudes, int[] latitudes, int[] xPoints, int[] yPoints, int nbPoints, java.awt.geom.Point2D.Double tempXY, T tempCoord)
          Convert a set of garmin coordinate into map positions (pixels).
 void geo2map(T coord, java.awt.geom.Point2D.Double result)
          Convert a geographic coordinate into a map position (pixels)
 java.awt.Rectangle getGarminBoundingBox()
           
 int getHeight()
           
 java.awt.geom.Point2D.Double getNorthEastWGS84()
           
 java.awt.geom.Point2D.Double getNorthWestWGS84()
           
 double getPixelsPerMeter()
           
 java.awt.geom.Point2D.Double getSouthEastWGS84()
           
 java.awt.geom.Point2D.Double getSouthWestWGS84()
           
 int getWidth()
           
 int hashCode()
           
 boolean isSetupDone()
           
 T map2geo(int x, int y)
          convert the map position (pixels) into geographic coordinates.
 T map2geoNoScale(double x, double y)
           
 void map2wgs84(int x, int y, java.awt.geom.Point2D.Double result)
          convert the map position (pixels) into WGS84 (radians).
 void moveMapPosition(double deltaX, double deltaY)
          Move the visible area by some delta given in map coordinates (pixels)
 void resetAutoScale()
          Must be called before the first call to adjustAutoScaleFromWgs84.
 void scale(java.awt.geom.Point2D.Double xy, java.awt.geom.Point2D.Double result)
           
 boolean setDimensions(int width, int height)
          Use it to change the dimensions of the display area (in screen pixel) without changing the details (more/less of the map will be shown.
 void setFrom(MapTransformer<T> other)
           
 java.lang.String toString()
           
 void unscale(java.awt.geom.Point2D xy, java.awt.geom.Point2D.Double result)
           
 void wgs84ToMap(double lon, double lat, T temp, java.awt.geom.Point2D.Double result)
          Convert a WGS84 coordinate (radians) into a map position (pixels)
 void wgs84ToMapNoScale(double lon, double lat, T temp, java.awt.geom.Point2D.Double result)
           
 void zoom(double factor)
          If factor>1 zoom in, otherwise zoom out.
 void zoom(double factor, int x, int y)
          If factor>1 zoom in, otherwise zoom out.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MapTransformer

public MapTransformer(MapTransformer.Converter<T> converter,
                      int margin)
Method Detail

setDimensions

public boolean setDimensions(int width,
                             int height)
Use it to change the dimensions of the display area (in screen pixel) without changing the details (more/less of the map will be shown.


changeDimensions

public void changeDimensions(int width,
                             int height)
Use it to change the dimensions of the display area (in screen pixel). That will change the amount of details show, but the same area of the map will be shown.

Beware not to change the aspect ratio!


resetAutoScale

public void resetAutoScale()
Must be called before the first call to adjustAutoScaleFromWgs84.


adjustAutoScaleFromWgs84

public void adjustAutoScaleFromWgs84(double lon,
                                     double lat)
takes a radian WGS84 coordinate and adjust the scale/position to include this coordinate. No called too often, so no need to optimize...


fixAspectRatio

public void fixAspectRatio()
Once several calls to adjustAutoScale have been done, call this to make sure the aspect ratio is correct.


geo2map

public void geo2map(T coord,
                    java.awt.geom.Point2D.Double result)
Convert a geographic coordinate into a map position (pixels)


wgs84ToMap

public void wgs84ToMap(double lon,
                       double lat,
                       T temp,
                       java.awt.geom.Point2D.Double result)
Convert a WGS84 coordinate (radians) into a map position (pixels)


map2geo

public T map2geo(int x,
                 int y)
convert the map position (pixels) into geographic coordinates.


map2wgs84

public void map2wgs84(int x,
                      int y,
                      java.awt.geom.Point2D.Double result)
convert the map position (pixels) into WGS84 (radians). Longitude in x and latitude in y.


getSouthWestWGS84

public java.awt.geom.Point2D.Double getSouthWestWGS84()
Returns:
The WGS84 coordinate (radians) of the lower left corner of the map.

getSouthEastWGS84

public java.awt.geom.Point2D.Double getSouthEastWGS84()
Returns:
The WGS84 coordinate (radians) of the lower left corner of the map.

getNorthEastWGS84

public java.awt.geom.Point2D.Double getNorthEastWGS84()
Returns:
The WGS84 coordinate (radians) of the upper right corner of the map.

getNorthWestWGS84

public java.awt.geom.Point2D.Double getNorthWestWGS84()
Returns:
The WGS84 coordinate (radians) of the upper right corner of the map.

getGarminBoundingBox

public java.awt.Rectangle getGarminBoundingBox()
Returns:
The bounding box in garmin coordinates

garminGeo2Map

public void garminGeo2Map(int[] longitudes,
                          int[] latitudes,
                          int[] xPoints,
                          int[] yPoints,
                          int nbPoints,
                          java.awt.geom.Point2D.Double tempXY,
                          T tempCoord)
Convert a set of garmin coordinate into map positions (pixels).

Parameters:
longitudes - the input longitudes
latitudes - the output latitudes
xPoints - the output X positions
yPoints - the output Y positions
nbPoints - the number of points to concider
tempXY - some temporary variable (avoid to do too many allocations for perf purpose)
tempCoord - some other temporary variable (avoid to do too many allocations for perf purpose)

isSetupDone

public boolean isSetupDone()

moveMapPosition

public void moveMapPosition(double deltaX,
                            double deltaY)
Move the visible area by some delta given in map coordinates (pixels)


zoom

public void zoom(double factor,
                 int x,
                 int y)
If factor>1 zoom in, otherwise zoom out. X and Y specify the new center of the map.


zoom

public void zoom(double factor)
If factor>1 zoom in, otherwise zoom out. The center of the map doesn't move.


map2geoNoScale

public T map2geoNoScale(double x,
                        double y)

scale

public void scale(java.awt.geom.Point2D.Double xy,
                  java.awt.geom.Point2D.Double result)

unscale

public void unscale(java.awt.geom.Point2D xy,
                    java.awt.geom.Point2D.Double result)

wgs84ToMapNoScale

public void wgs84ToMapNoScale(double lon,
                              double lat,
                              T temp,
                              java.awt.geom.Point2D.Double result)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getWidth

public int getWidth()

getHeight

public int getHeight()

createTempCoord

public T createTempCoord()

getPixelsPerMeter

public double getPixelsPerMeter()
Returns:
A rough estimate of how many pixels is one meter.

clone

public MapTransformer<T> clone()
Overrides:
clone in class java.lang.Object

setFrom

public void setFrom(MapTransformer<T> other)

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object


Copyright © 2008. All Rights Reserved.