-
- All Implemented Interfaces:
-
org.osmdroid.api.IProjection
public class Projection implements IProjection
A Projection serves to translate between the coordinate system of x/y on-screen pixel coordinates and that of latitude/longitude points on the surface of the earth. You obtain a Projection from MapView.getProjection(). You should not hold on to this object for more than one draw, since the projection of the map could change. Uses the web mercator projection Note: This class will "wrap" all pixel and lat/long values that overflow their bounds (rather than clamping to their bounds).
-
-
Field Summary
Fields Modifier and Type Field Description public final static doublemProjectedMapSize
-
Constructor Summary
Constructors Constructor Description Projection(double pZoomLevel, Rect pScreenRect, GeoPoint pCenter, long pScrollX, long pScrollY, float pOrientation, boolean pHorizontalWrapEnabled, boolean pVerticalWrapEnabled, TileSystem pTileSystem, int pMapCenterOffsetX, int pMapCenterOffsetY)Projection(double pZoomLevel, int pWidth, int pHeight, GeoPoint pCenter, float pOrientation, boolean pHorizontalWrapEnabled, boolean pVerticalWrapEnabled, int pMapCenterOffsetX, int pMapCenterOffsetY)
-
Method Summary
Modifier and Type Method Description ProjectiongetOffspring(double pZoomLevel, Rect pScreenRect)doublegetZoomLevel()BoundingBoxgetBoundingBox()RectgetScreenRect()RectgetIntrinsicScreenRect()IGeoPointfromPixels(int x, int y)Create a new GeoPoint from pixel coordinates relative to the top-left of the MapView thatprovided this PixelConverter. IGeoPointfromPixels(int pPixelX, int pPixelY, GeoPoint pReuse)note: if setHorizontalMapRepetitionEnabled or setVerticalMapRepetitionEnabled is false, then thiscan return values that beyond the max extents of the world. IGeoPointfromPixels(int pPixelX, int pPixelY, GeoPoint pReuse, boolean forceWrap)* note: if setHorizontalMapRepetitionEnabled or setVerticalMapRepetitionEnabled is false, then thiscan return values that beyond the max extents of the world. PointtoPixels(IGeoPoint in, Point reuse)Converts the given IGeoPoint to onscreen pixel coordinates, relative to the top-leftof the org.osmdroid.views.MapView that provided this Projection. PointtoPixels(IGeoPoint in, Point reuse, boolean forceWrap)longgetLongPixelXFromLongitude(double pLongitude, boolean forceWrap)longgetLongPixelXFromLongitude(double pLongitude)longgetLongPixelYFromLatitude(double pLatitude, boolean forceWrap)longgetLongPixelYFromLatitude(double pLatitude)PointLtoProjectedPixels(GeoPoint geoPoint, PointL reuse)A wrapper for toProjectedPixels PointLtoProjectedPixels(long latituteE6, long longitudeE6, PointL reuse)Performs only the first computationally heavy part of the projection. PointLtoProjectedPixels(double latitude, double longitude, PointL reuse)Performs only the first computationally heavy part of the projection. PointLtoProjectedPixels(double latitude, double longitude, boolean pWrapEnabled, PointL reuse)PointtoPixelsFromProjected(PointL in, Point reuse)Performs the second computationally light part of the projection. PointtoPixelsFromMercator(long pMercatorX, long pMercatorY, Point reuse)PointLtoMercatorPixels(int pPixelX, int pPixelY, PointL reuse)floatmetersToEquatorPixels(float meters)Converts a distance in meters (along the equator) to one in (horizontal) pixels at thecurrent zoomlevel. floatmetersToPixels(float meters)Converts a distance in meters to one in (horizontal) pixels at the current zoomlevel and atthe current latitude at the center of the screen. floatmetersToPixels(float meters, double latitude, double zoomLevel)IGeoPointgetNorthEast()Get the coordinates of the most north-easterly visible point of the map. IGeoPointgetSouthWest()Get the coordinates of the most south-westerly visible point of the map. MatrixgetInvertedScaleRotateCanvasMatrix()This will provide a Matrix that will revert the current map's scaling and rotation. PointunrotateAndScalePoint(int x, int y, Point reuse)This will revert the current map's scaling and rotation for a point. PointrotateAndScalePoint(int x, int y, Point reuse)This will apply the current map's scaling and rotation for a point. voiddetach()RectgetPixelFromTile(int pTileX, int pTileY, Rect pReuse)longgetMercatorFromTile(int pTile)MatrixgetScaleRotateCanvasMatrix()This will provide a Matrix that will revert the current map's scaling and rotation. doublegetProjectedPowerDifference()PointgetPixelsFromProjected(PointL in, double powerDifference, Point reuse)PointLgetLongPixelsFromProjected(PointL in, double powerDifference, boolean pCloser, PointL reuse)intgetTileFromMercator(long pMercator)RectLgetMercatorViewPort(RectL pReuse)intgetScreenCenterX()intgetScreenCenterY()longgetMercatorXFromPixel(int pPixelX)longgetMercatorYFromPixel(int pPixelY)longgetCleanMercator(long pMercator, boolean wrapEnabled)GeoPointgetCurrentCenter()longgetOffsetX()longgetOffsetY()voidsave(Canvas pCanvas, boolean pMapRotation, boolean pForce)voidrestore(Canvas pCanvas, boolean pForce)voidadjustOffsets(IGeoPoint pGeoPoint, PointF pPixel)Adjust the offsets so that this geo point projects into that pixel voidadjustOffsets(BoundingBox pBoundingBox)Adjust the offsets so thateither this bounding box is bigger than the screen and contains itor it is smaller and it is centered static longgetScrollableOffset(long pPixelMin, long pPixelMax, double pWorldSize, int pScreenSize, int pExtraSize)booleanisHorizontalWrapEnabled()booleanisVerticalWrapEnabled()floatgetOrientation()intgetWidth()intgetHeight()doublegetWorldMapSize()-
-
Constructor Detail
-
Projection
Projection(double pZoomLevel, Rect pScreenRect, GeoPoint pCenter, long pScrollX, long pScrollY, float pOrientation, boolean pHorizontalWrapEnabled, boolean pVerticalWrapEnabled, TileSystem pTileSystem, int pMapCenterOffsetX, int pMapCenterOffsetY)
-
Projection
Projection(double pZoomLevel, int pWidth, int pHeight, GeoPoint pCenter, float pOrientation, boolean pHorizontalWrapEnabled, boolean pVerticalWrapEnabled, int pMapCenterOffsetX, int pMapCenterOffsetY)
-
-
Method Detail
-
getOffspring
Projection getOffspring(double pZoomLevel, Rect pScreenRect)
-
getZoomLevel
double getZoomLevel()
-
getBoundingBox
BoundingBox getBoundingBox()
-
getScreenRect
Rect getScreenRect()
-
getIntrinsicScreenRect
Rect getIntrinsicScreenRect()
-
fromPixels
IGeoPoint fromPixels(int x, int y)
Create a new GeoPoint from pixel coordinates relative to the top-left of the MapView thatprovided this PixelConverter.
-
fromPixels
IGeoPoint fromPixels(int pPixelX, int pPixelY, GeoPoint pReuse)
note: if setHorizontalMapRepetitionEnabled or setVerticalMapRepetitionEnabled is false, then thiscan return values that beyond the max extents of the world. This may or may not bedesired. https://github.com/osmdroid/osmdroid/pull/722for more information and the discussion associated with this.
-
fromPixels
IGeoPoint fromPixels(int pPixelX, int pPixelY, GeoPoint pReuse, boolean forceWrap)
* note: if setHorizontalMapRepetitionEnabled or setVerticalMapRepetitionEnabled is false, then thiscan return values that beyond the max extents of the world. This may or may not bedesired. https://github.com/osmdroid/osmdroid/pull/722for more information and the discussion associated with this.
-
toPixels
Point toPixels(IGeoPoint in, Point reuse)
Converts the given IGeoPoint to onscreen pixel coordinates, relative to the top-leftof the org.osmdroid.views.MapView that provided this Projection.
- Parameters:
in- The latitude/longitude pair to convert.
-
getLongPixelXFromLongitude
long getLongPixelXFromLongitude(double pLongitude, boolean forceWrap)
-
getLongPixelXFromLongitude
long getLongPixelXFromLongitude(double pLongitude)
-
getLongPixelYFromLatitude
long getLongPixelYFromLatitude(double pLatitude, boolean forceWrap)
-
getLongPixelYFromLatitude
long getLongPixelYFromLatitude(double pLatitude)
-
toProjectedPixels
PointL toProjectedPixels(GeoPoint geoPoint, PointL reuse)
A wrapper for toProjectedPixels
-
toProjectedPixels
@Deprecated() PointL toProjectedPixels(long latituteE6, long longitudeE6, PointL reuse)
Performs only the first computationally heavy part of the projection. Call getLongPixelsFromProjected to get the final position.
- Parameters:
latituteE6- the latitute of the pointlongitudeE6- the longitude of the pointreuse- just pass null if you do not have a PointL to be 'recycled'.
-
toProjectedPixels
PointL toProjectedPixels(double latitude, double longitude, PointL reuse)
Performs only the first computationally heavy part of the projection. Call getLongPixelsFromProjected to get the final position.
- Parameters:
latitude- the latitute of the pointlongitude- the longitude of the pointreuse- just pass null if you do not have a PointL to be 'recycled'.
-
toProjectedPixels
PointL toProjectedPixels(double latitude, double longitude, boolean pWrapEnabled, PointL reuse)
-
toPixelsFromProjected
@Deprecated() Point toPixelsFromProjected(PointL in, Point reuse)
Performs the second computationally light part of the projection.
- Parameters:
in- the PointL calculated by the toProjectedPixelsreuse- just pass null if you do not have a Point to be 'recycled'.
-
toPixelsFromMercator
@Deprecated() Point toPixelsFromMercator(long pMercatorX, long pMercatorY, Point reuse)
-
toMercatorPixels
PointL toMercatorPixels(int pPixelX, int pPixelY, PointL reuse)
-
metersToEquatorPixels
float metersToEquatorPixels(float meters)
Converts a distance in meters (along the equator) to one in (horizontal) pixels at thecurrent zoomlevel. In the default Mercator projection, the actual number of pixels for agiven distance will get higher as you move away from the equator.
- Parameters:
meters- the distance in meters
-
metersToPixels
float metersToPixels(float meters)
Converts a distance in meters to one in (horizontal) pixels at the current zoomlevel and atthe current latitude at the center of the screen.
- Parameters:
meters- the distance in meters
-
metersToPixels
float metersToPixels(float meters, double latitude, double zoomLevel)
-
getNorthEast
IGeoPoint getNorthEast()
Get the coordinates of the most north-easterly visible point of the map.
-
getSouthWest
IGeoPoint getSouthWest()
Get the coordinates of the most south-westerly visible point of the map.
-
getInvertedScaleRotateCanvasMatrix
Matrix getInvertedScaleRotateCanvasMatrix()
This will provide a Matrix that will revert the current map's scaling and rotation. This canbe useful when drawing to a fixed location on the screen.
-
unrotateAndScalePoint
Point unrotateAndScalePoint(int x, int y, Point reuse)
This will revert the current map's scaling and rotation for a point. This can be useful whendrawing to a fixed location on the screen.
-
rotateAndScalePoint
Point rotateAndScalePoint(int x, int y, Point reuse)
This will apply the current map's scaling and rotation for a point. This can be useful whenconverting MotionEvents to a screen point.
-
detach
void detach()
-
getPixelFromTile
Rect getPixelFromTile(int pTileX, int pTileY, Rect pReuse)
-
getMercatorFromTile
long getMercatorFromTile(int pTile)
-
getScaleRotateCanvasMatrix
Matrix getScaleRotateCanvasMatrix()
This will provide a Matrix that will revert the current map's scaling and rotation. This canbe useful when drawing to a fixed location on the screen.
-
getProjectedPowerDifference
double getProjectedPowerDifference()
-
getPixelsFromProjected
@Deprecated() Point getPixelsFromProjected(PointL in, double powerDifference, Point reuse)
-
getLongPixelsFromProjected
PointL getLongPixelsFromProjected(PointL in, double powerDifference, boolean pCloser, PointL reuse)
- Parameters:
in- Input point: a geo point projected to the map with the largest zoom level (aka "projected" map)powerDifference- Factor between the large "projected" map and the wanted projection zoom levelpCloser- "Should we move the resulting point - modulo the map size - so that it'sas close to the screen limits as possible?
-
getTileFromMercator
int getTileFromMercator(long pMercator)
-
getMercatorViewPort
RectL getMercatorViewPort(RectL pReuse)
-
getScreenCenterX
int getScreenCenterX()
-
getScreenCenterY
int getScreenCenterY()
-
getMercatorXFromPixel
long getMercatorXFromPixel(int pPixelX)
-
getMercatorYFromPixel
long getMercatorYFromPixel(int pPixelY)
-
getCleanMercator
long getCleanMercator(long pMercator, boolean wrapEnabled)
-
getCurrentCenter
GeoPoint getCurrentCenter()
-
getOffsetX
long getOffsetX()
-
getOffsetY
long getOffsetY()
-
adjustOffsets
void adjustOffsets(IGeoPoint pGeoPoint, PointF pPixel)
Adjust the offsets so that this geo point projects into that pixel
-
adjustOffsets
@Deprecated() void adjustOffsets(BoundingBox pBoundingBox)
Adjust the offsets so thateither this bounding box is bigger than the screen and contains itor it is smaller and it is centered
-
getScrollableOffset
static long getScrollableOffset(long pPixelMin, long pPixelMax, double pWorldSize, int pScreenSize, int pExtraSize)
- Parameters:
pPixelMin- Pixel position of the limit (left)pPixelMax- Pixel position of the limit (right)pWorldSize- World map size - for modulo adjustmentspScreenSize- Screen sizepExtraSize- Extra size to consider at each side of the screen
-
isHorizontalWrapEnabled
boolean isHorizontalWrapEnabled()
-
isVerticalWrapEnabled
boolean isVerticalWrapEnabled()
-
getOrientation
float getOrientation()
-
getWidth
int getWidth()
-
getHeight
int getHeight()
-
getWorldMapSize
double getWorldMapSize()
-
-
-
-