Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.maryanovsky.map.client.projections
Class AbstractProjection

    java.lang.Object
      com.maryanovsky.map.client.projections.AbstractProjection

All Implemented Interfaces:
  Projection

Direct Known Subclasses:
  MercatorProjection, ScaleProjection

    public abstract class AbstractProjection

extends Object
implements Projection

A useful base class for `Projection` implementations.

It divides the responsibility of handling the projection itself and the zoom magnification to two different objects. The projection at the native zoom is delegated to the subclass using the abstract `fromPixelToLatLngImpl(double, double)` and `fromLatLngToPixelImpl(LatLng)` methods. The zoom magnification, on the other hand, is delegated to a `ZoomStrategy`. An implementation of that interface defines the magnification between each two zooms.

Additionally, this class takes care of implementing the `Projection.getWrapSize(int)` method.

Author:
  Maryanovsky Alexander

Field Summary
`protected boolean` | `longitudeWraps` Whether the map wraps around the X (longitude) axis.
`protected int` | `nativeZoom` The "native" zoom, at which world size is specified.
`protected double` | `worldHeight` The height of the world, in pixels, at the native zoom.
`protected double` | `worldWidth` The width of the world, in pixels, at the native zoom.
`protected ZoomStrategy` | `zoomStrategy` The zoom magnification strategy.

Constructor Summary
`AbstractProjection(ZoomStrategy zoomStrategy, int nativeZoom, SizeView worldSize, boolean longitudeWraps)` Creates a new `AbstractProjection` with the specified arguments.

Method Summary
`Point` | `fromLatLngToPixel(LatLng latLng, int zoom)` Delegates to `fromLatLngToPixelImpl(LatLng)` and then converts the results to the actual zoom before returning.
`protected abstract double[]` | `fromLatLngToPixelImpl(LatLng latLng)` Converts from latitude-longitude to pixel coordinates at the native zoom.
`LatLng` | `fromPixelToLatLng(PointView pixel, int zoom)` Converts the pixel coordinates to the native zoom and then delegates to `fromPixelToLatLngImpl(double, double)`.
`protected abstract LatLng` | `fromPixelToLatLngImpl(double x, double y)` Converts from pixel coordinates to latitude-longitude at the native zoom.
`SizeView` | `getWrapSize(int zoom)` Delegates to `getWrapSizeImpl(int)` and caches the results.
`protected SizeView` | `getWrapSizeImpl(int zoom)` Returns the wrap size at the specified zoom.
`double` | `getZoomMagnification(int startZoom, int endZoom)` Delegates to the `ZoomStrategy` given to us in the constructor.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### nativeZoom

    protected final int nativeZoom

  The "native" zoom, at which world size is specified.

### worldWidth

    protected final double worldWidth

  The width of the world, in pixels, at the native zoom.

### worldHeight

    protected final double worldHeight

  The height of the world, in pixels, at the native zoom.

### longitudeWraps

    protected final boolean longitudeWraps

  Whether the map wraps around the X (longitude) axis.

### zoomStrategy

    protected final ZoomStrategy zoomStrategy

  The zoom magnification strategy.

Constructor Detail

### AbstractProjection

    public AbstractProjection(ZoomStrategy zoomStrategy,
                              int nativeZoom,
                              SizeView worldSize,
                              boolean longitudeWraps)

  Creates a new `AbstractProjection` with the specified arguments.

  Parameters:
    `zoomStrategy` - The strategy that defines zoom magnification for us.
    `nativeZoom` - The "native" zoom. There is no special meaning to this zoom other than that `worldSize` is given at that zoom.
    `worldSize` - The size of the world, in pixels, at the native zoom.
    `longitudeWraps` - Whether the map wraps around the X (longitude) axis.

Method Detail

### fromLatLngToPixel

    public Point fromLatLngToPixel(LatLng latLng,
                                   int zoom)

  Delegates to `fromLatLngToPixelImpl(LatLng)` and then converts the results to the actual zoom before returning.

  Specified by:
    `fromLatLngToPixel` in interface `Projection`

### fromPixelToLatLng

    public LatLng fromPixelToLatLng(PointView pixel,
                                    int zoom)

  Converts the pixel coordinates to the native zoom and then delegates to `fromPixelToLatLngImpl(double, double)`.

  Specified by:
    `fromPixelToLatLng` in interface `Projection`

### fromLatLngToPixelImpl

    protected abstract double[] fromLatLngToPixelImpl(LatLng latLng)

  Converts from latitude-longitude to pixel coordinates at the native zoom. Returns the X and Y coordinates in a 2-element array. The returned values must be in the range `[0, worldWidth or worldHeight]`.

### fromPixelToLatLngImpl

    protected abstract LatLng fromPixelToLatLngImpl(double x,
                                                    double y)

  Converts from pixel coordinates to latitude-longitude at the native zoom. The passed values are guaranteed to be in the range `[0, worldWidth or worldHeight]`.

### getWrapSize

    public SizeView getWrapSize(int zoom)

  Delegates to `getWrapSizeImpl(int)` and caches the results.

  Specified by:
    `getWrapSize` in interface `Projection`

### getWrapSizeImpl

    protected SizeView getWrapSizeImpl(int zoom)

  Returns the wrap size at the specified zoom. This method will be called at most once for each zoom.

### getZoomMagnification

    public double getZoomMagnification(int startZoom,
                                       int endZoom)

  Delegates to the `ZoomStrategy` given to us in the constructor.

  Specified by:
    `getZoomMagnification` in interface `Projection`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD