data 2018 7 12 by WJB
#include
#define MapLenght(level) 256*pow(2,(level))
#define WEBMERCATOR_256_MAP_LONG 20037508.342789
#define PI 3.141592653589793
#define WEBERCATOR_256_RESOLUTION(x) ((WEBMERCATOR_256_MAP_LONG * 2)/(256 * (2<<((x)-1))))
struct Point2D
{
double x_;
double y_;
Point2D(double _x,double _y)
{
x_ = _x;
y_ = _y;
}
Point2D()
{
x_ = 0;
y_ = 0;
}
};
Point2D qgs2map(const Point2D & qgs, int zoomLevel)
{
Point2D mapPoint;
double resolution = WEBERCATOR_256_RESOLUTION(zoomLevel);
double x = (double)(-WEBMERCATOR_256_MAP_LONG + (qgs.x_*resolution));
double y = (double)(WEBMERCATOR_256_MAP_LONG - (qgs.y_*resolution));
mapPoint.x_=x;
mapPoint.y_=y;
return mapPoint;
}
// Moded by WJB 2018 07 12
//,地图坐标与地理坐标之间的转换函数.…
Point2D map211(const Point2D & map)
{
Point2D geoPoint;
double x = (double)(map.x_ / WEBMERCATOR_256_MAP_LONG * 180);
double y = (double)(map.y_ / WEBMERCATOR_256_MAP_LONG * 180);
y = (180 / PI)*(2 * atan(exp(y*PI / 180)) - PI / 2);
geoPoint.x_ = x;
geoPoint.y_ = y;
return geoPoint;
}
Point2D map2qgs(const Point2D & map, int zoomLevel)
{
//Moded bY WJB 2018 07 12
// 地图坐标与场景像素坐标之间的转换函数
Point2D pixPoint;
double resolution = WEBERCATOR_256_RESOLUTION(zoomLevel);
double x = (double)((WEBMERCATOR_256_MAP_LONG + map.x_) / resolution);
double y = (double)((WEBMERCATOR_256_MAP_LONG - map.y_) / resolution);
pixPoint.x_ = x;
pixPoint.y_ = y;
return pixPoint;
}
Point2D ll2map(const Point2D & geo)
{
//Moded by WJB 2018 07 12
//地理坐标与地图坐标之间的转换函数
Point2D mapPoint;
double x = (double)(geo.x_ *WEBMERCATOR_256_MAP_LONG / 180);
double y = (double)(log(tan(((90 + geo.y_)*PI / 360))) / (PI / 180));
y = y*WEBMERCATOR_256_MAP_LONG / 180;
mapPoint.x_ = x;
mapPoint.y_ = y;
return mapPoint;
}