/// <summary> /// 经纬度坐标转像素坐标 /// </summary> /// <returns></returns> public static PointDouble LatLngToPixel(PointLatLng pLatLng, int zoom) { PointDouble pPix = new PointDouble(); if (pLatLng != null) { var lat = MapHelper.Clip(pLatLng.LatY, MinLatY, MaxLatY); var lng = MapHelper.Clip(pLatLng.LngX, MinLngX, MaxLngX); double x = (lng + 180) / 360; double sinLatitude = Math.Sin(lat * Math.PI / 180); double y = 0.5 - Math.Log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI); BSize <long> s = MapHelper.GetTileMatrixSizePixel(zoom, TileSize); double mapSizeX = s.Width; double mapSizeY = s.Height; //pPix.X = MapHelper.Clip(x * mapSizeX + 0.5, 0, mapSizeX - 1); //pPix.Y = MapHelper.Clip(y * mapSizeY + 0.5, 0, mapSizeY - 1); pPix.X = MapHelper.Clip(x * mapSizeX, 0, mapSizeX - 1); pPix.Y = MapHelper.Clip(y * mapSizeY, 0, mapSizeY - 1); } return(pPix); }
/// <summary> /// 像素坐标转经纬度坐标 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="zoom"></param> /// <returns></returns> public static PointLatLng PixelToLatLng(PointDouble pPix, int zoom) { PointLatLng ret = new PointLatLng(); if (pPix != null) { BSize <long> s = MapHelper.GetTileMatrixSizePixel(zoom, TileSize); double mapSizeX = s.Width; double mapSizeY = s.Height; double xx = (MapHelper.Clip(pPix.X, 0, mapSizeX - 1) / mapSizeX) - 0.5; double yy = 0.5 - (MapHelper.Clip(pPix.Y, 0, mapSizeY - 1) / mapSizeY); ret.LatY = 90 - 360 * Math.Atan(Math.Exp(-yy * 2 * Math.PI)) / Math.PI; ret.LngX = 360 * xx; } return(ret); }
public static Size ToSize(this BSize <long> s) { return(new Size((int)s.Width, (int)s.Height)); }
/// <summary> /// 获取指定层级瓦片数量 /// </summary> /// <param name="zoom"></param> /// <returns></returns> public long GetTileItemCount(int zoom) { BSize <long> s = GetTileMatrixSizeXY(zoom); return(s.Width * s.Height); }