Osmdroid API功能介绍5----坐标转换
Osmdroid默认支持的是从屏幕坐标和地图坐标之间的相互转换。
类Projection
提供相互转换的接口,可以通过MapView.getProjection()
获取当前的对象
Projection
类比较复杂。我们先看一下这个类的实现接口
/**
* An interface that resembles the Google Maps API Projection interface and is implemented by the
* osmdroid {@link org.osmdroid.views.Projection} class.
*
* @author Neil Boyd
*
*/
public interface IProjection {
/**
* Converts the given {@link IGeoPoint} to onscreen pixel coordinates, relative to the top-left
* of the {@link org.osmdroid.views.MapView} that provided this Projection.
* 地图的点转换到屏幕的点
* @param in
* The latitude/longitude pair to convert.
* @param out
* A pre-existing object to use for the output; if null, a new Point will be
* allocated and returned.
*/
Point toPixels(IGeoPoint in, Point out);
/**
* Create a new GeoPoint from pixel coordinates relative to the top-left of the MapView that
* provided this PixelConverter.
* 屏幕的点转换到地图点
*/
IGeoPoint fromPixels(int x, int y);
/**
* Converts a distance in meters (along the equator) to one in (horizontal) pixels at the
* current zoomlevel. In the default Mercator projection, the actual number of pixels for a
* given distance will get higher as you move away from the equator.
* 实际的长度转换到像素长度
* @param meters
* the distance in meters
* @return The number of pixels corresponding to the distance, if measured along the equator, at
* the current zoom level. The return value may only be approximate.
*/
float metersToEquatorPixels(float meters);
/**
* Get the coordinates of the most north-easterly visible point of the map.
* 获取当前显示东北角的点
*/
IGeoPoint getNorthEast();
/**
* Get the coordinates of the most south-westerly visible point of the map.
* 获取当前显示的西南角
*/
IGeoPoint getSouthWest();
}
地图有时候需要进行旋转,这个时候这些接口功能就不满足需求了
Projection
类的下面这个就是在屏幕旋转的时候进行计算的接口
/**
* This will revert the current map's scaling and rotation for a point. This can be useful when
* drawing to a fixed location on the screen.
* 获取不旋转时的点
*/
public Point unrotateAndScalePoint(int x, int y, Point reuse) {
return applyMatrixToPoint(x, y, reuse, mUnrotateAndScaleMatrix, mOrientation != 0);
}
/**
* This will apply the current map's scaling and rotation for a point. This can be useful when
* converting MotionEvents to a screen point.
* 不旋转的点转换到旋转的点
*/
public Point rotateAndScalePoint(int x, int y, Point reuse) {
return applyMatrixToPoint(x, y, reuse, mRotateAndScaleMatrix, mOrientation != 0);
}