Osmdroid API功能介绍5----坐标转换

Osmdroid API功能介绍5----坐标转换

http://osmdroid.github.io/osmdroid/

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);
	}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值