From 74e5cfa3ca0f99ba2a049e9fa93d6dff3591d640 Mon Sep 17 00:00:00 2001 From: ephy Date: Mon, 12 Apr 2010 10:22:16 +0000 Subject: [PATCH] OP-65 GCS/qmapcontrol: Fix for google map and google sat map. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@488 ebee16cc-31ac-478f-84a7-5cbb03baadba --- .../libs/qmapcontrol/src/googlemapadapter.cpp | 2 +- .../qmapcontrol/src/googlesatmapadapter.cpp | 279 +++++++++--------- .../qmapcontrol/src/googlesatmapadapter.h | 48 +-- 3 files changed, 163 insertions(+), 166 deletions(-) diff --git a/ground/src/libs/qmapcontrol/src/googlemapadapter.cpp b/ground/src/libs/qmapcontrol/src/googlemapadapter.cpp index 9715e2f50..d18dd8095 100644 --- a/ground/src/libs/qmapcontrol/src/googlemapadapter.cpp +++ b/ground/src/libs/qmapcontrol/src/googlemapadapter.cpp @@ -27,7 +27,7 @@ namespace qmapcontrol { GoogleMapAdapter::GoogleMapAdapter() - : TileMapAdapter("mt2.google.com", "/mt?n=404&x=%2&y=%3&zoom=%1", 256, 17, 0) + : TileMapAdapter("mt0.google.com", "/vt/lyrs=&x=%2&s=&y=%3&z=%1", 256, 0, 17) //: TileMapAdapter("tile.openstreetmap.org", "/%1/%2/%3.png", 256, 0, 17) { } diff --git a/ground/src/libs/qmapcontrol/src/googlesatmapadapter.cpp b/ground/src/libs/qmapcontrol/src/googlesatmapadapter.cpp index b7576ef9e..211c285ac 100644 --- a/ground/src/libs/qmapcontrol/src/googlesatmapadapter.cpp +++ b/ground/src/libs/qmapcontrol/src/googlesatmapadapter.cpp @@ -29,153 +29,150 @@ namespace qmapcontrol { GoogleSatMapAdapter::GoogleSatMapAdapter() - : TileMapAdapter("kh2.google.com", "/kh?n=404&v=8&t=trtqtt", 256, 0, 19) + : TileMapAdapter("khm.google.com", "/kh?v=51&x=%2&s=&y=%3&z=%1", 256, 0, 17) { - // name = "googlesat"; - - numberOfTiles = pow(2, current_zoom+0.0); - coord_per_x_tile = 360. / numberOfTiles; - coord_per_y_tile = 180. / numberOfTiles; } GoogleSatMapAdapter::~GoogleSatMapAdapter() { } - QString GoogleSatMapAdapter::getHost() const - { - int random = qrand() % 4; - return QString("kh%1.google.com").arg(random); - } - - QPoint GoogleSatMapAdapter::coordinateToDisplay(const QPointF& coordinate) const - { - //double x = ((coordinate.x()+180)*(tilesize*numberOfTiles/360)); - //double y = (((coordinate.y()*-1)+90)*(tilesize*numberOfTiles/180)); - - qreal x = (coordinate.x()+180.) * (numberOfTiles*mytilesize)/360.; // coord to pixel! - //double y = -1*(coordinate.y()-90) * (numberOfTiles*tilesize)/180.; // coord to pixel! - qreal y = (getMercatorYCoord(coordinate.y())-M_PI) * -1 * (numberOfTiles*mytilesize)/(2*M_PI); // coord to pixel! - return QPoint(int(x), int(y)); - } - - QPointF GoogleSatMapAdapter::displayToCoordinate(const QPoint& point) const - { - //double lon = ((point.x()/tilesize*numberOfTiles)*360)-180; - //double lat = (((point.y()/tilesize*numberOfTiles)*180)-90)*-1; - - qreal lon = (point.x()*(360./(numberOfTiles*mytilesize)))-180.; - //double lat = -(point.y()*(180./(numberOfTiles*tilesize)))+90; - //qreal lat = getMercatorLatitude(point.y()*-1*(2*M_PI/(numberOfTiles*tilesize)) + M_PI); - qreal lat = lat *180./M_PI; - return QPointF(lon, lat); - } - - qreal GoogleSatMapAdapter::getMercatorLatitude(qreal YCoord) const - { - //http://welcome.warnercnr.colostate.edu/class_info/nr502/lg4/projection_mathematics/converting.html - if (YCoord > M_PI) return 9999.; - if (YCoord < -M_PI) return -9999.; - - qreal t = atan(exp(YCoord)); - qreal res = (2.*(t))-(M_PI/2.); - return res; - } - - qreal GoogleSatMapAdapter::getMercatorYCoord(qreal lati) const - { - qreal lat = lati; - - // conversion degre=>radians - qreal phi = M_PI * lat / 180; - - qreal res; - //double temp = Math.Tan(Math.PI / 4 - phi / 2); - //res = Math.Log(temp); - res = 0.5 * log((1 + sin(phi)) / (1 - sin(phi))); - - return res; - } - - void GoogleSatMapAdapter::zoom_in() - { - current_zoom+=1; - numberOfTiles = pow(2, current_zoom+0.0); - coord_per_x_tile = 360. / numberOfTiles; - coord_per_y_tile = 180. / numberOfTiles; - } - - void GoogleSatMapAdapter::zoom_out() - { - current_zoom-=1; - numberOfTiles = pow(2, current_zoom+0.0); - coord_per_x_tile = 360. / numberOfTiles; - coord_per_y_tile = 180. / numberOfTiles; - } - - bool GoogleSatMapAdapter::isValid(int x, int y, int z) const - { - if ((x>=0 && x < numberOfTiles) && (y>=0 && y < numberOfTiles) && z>=0) - { - return true; - } - return false; - } - QString GoogleSatMapAdapter::query(int i, int j, int z) const - { - return getQ(-180+i*coord_per_x_tile, - 90-(j+1)*coord_per_y_tile, z); - } - - QString GoogleSatMapAdapter::getQ(qreal longitude, qreal latitude, int zoom) const - { - qreal xmin=-180; - qreal xmax=180; - qreal ymin=-90; - qreal ymax=90; - - qreal xmoy=0; - qreal ymoy=0; - QString location="t"; - - //Google uses a latitude divided by 2; - qreal halflat = latitude; - - for (int i = 0; i < zoom; i++) - { - xmoy = (xmax + xmin) / 2; - ymoy = (ymax + ymin) / 2; - if (halflat >= ymoy) //upper part (q or r) - { - ymin = ymoy; - if (longitude < xmoy) - { /*q*/ - location+= "q"; - xmax = xmoy; - } - else - {/*r*/ - location+= "r"; - xmin = xmoy; - } - } - else //lower part (t or s) - { - ymax = ymoy; - if (longitude < xmoy) - { /*t*/ - - location+= "t"; - xmax = xmoy; - } - else - {/*s*/ - location+= "s"; - xmin = xmoy; - } - } - } - return QString("/kh?n=404&v=24&t=%1").arg(location); - } } +// QString GoogleSatMapAdapter::getHost() const +// { +// int random = qrand() % 4; +// return QString("kh%1.google.com").arg(random); +// } +// +// QPoint GoogleSatMapAdapter::coordinateToDisplay(const QPointF& coordinate) const +// { +// //double x = ((coordinate.x()+180)*(tilesize*numberOfTiles/360)); +// //double y = (((coordinate.y()*-1)+90)*(tilesize*numberOfTiles/180)); +// +// qreal x = (coordinate.x()+180.) * (numberOfTiles*mytilesize)/360.; // coord to pixel! +// //double y = -1*(coordinate.y()-90) * (numberOfTiles*tilesize)/180.; // coord to pixel! +// qreal y = (getMercatorYCoord(coordinate.y())-M_PI) * -1 * (numberOfTiles*mytilesize)/(2*M_PI); // coord to pixel! +// return QPoint(int(x), int(y)); +// } +// +// QPointF GoogleSatMapAdapter::displayToCoordinate(const QPoint& point) const +// { +// //double lon = ((point.x()/tilesize*numberOfTiles)*360)-180; +// //double lat = (((point.y()/tilesize*numberOfTiles)*180)-90)*-1; +// +// qreal lon = (point.x()*(360./(numberOfTiles*mytilesize)))-180.; +// //double lat = -(point.y()*(180./(numberOfTiles*tilesize)))+90; +// //qreal lat = getMercatorLatitude(point.y()*-1*(2*M_PI/(numberOfTiles*tilesize)) + M_PI); +// qreal lat = lat *180./M_PI; +// return QPointF(lon, lat); +// } +// +// qreal GoogleSatMapAdapter::getMercatorLatitude(qreal YCoord) const +// { +// //http://welcome.warnercnr.colostate.edu/class_info/nr502/lg4/projection_mathematics/converting.html +// if (YCoord > M_PI) return 9999.; +// if (YCoord < -M_PI) return -9999.; +// +// qreal t = atan(exp(YCoord)); +// qreal res = (2.*(t))-(M_PI/2.); +// return res; +// } +// +// qreal GoogleSatMapAdapter::getMercatorYCoord(qreal lati) const +// { +// qreal lat = lati; +// +// // conversion degre=>radians +// qreal phi = M_PI * lat / 180; +// +// qreal res; +// //double temp = Math.Tan(Math.PI / 4 - phi / 2); +// //res = Math.Log(temp); +// res = 0.5 * log((1 + sin(phi)) / (1 - sin(phi))); +// +// return res; +// } +// +// void GoogleSatMapAdapter::zoom_in() +// { +// current_zoom+=1; +// numberOfTiles = pow(2, current_zoom+0.0); +// coord_per_x_tile = 360. / numberOfTiles; +// coord_per_y_tile = 180. / numberOfTiles; +// } +// +// void GoogleSatMapAdapter::zoom_out() +// { +// current_zoom-=1; +// numberOfTiles = pow(2, current_zoom+0.0); +// coord_per_x_tile = 360. / numberOfTiles; +// coord_per_y_tile = 180. / numberOfTiles; +// } +// +// bool GoogleSatMapAdapter::isValid(int x, int y, int z) const +// { +// if ((x>=0 && x < numberOfTiles) && (y>=0 && y < numberOfTiles) && z>=0) +// { +// return true; +// } +// return false; +// } +// QString GoogleSatMapAdapter::query(int i, int j, int z) const +// { +// return getQ(-180+i*coord_per_x_tile, +// 90-(j+1)*coord_per_y_tile, z); +// } +// +// QString GoogleSatMapAdapter::getQ(qreal longitude, qreal latitude, int zoom) const +// { +// qreal xmin=-180; +// qreal xmax=180; +// qreal ymin=-90; +// qreal ymax=90; +// +// qreal xmoy=0; +// qreal ymoy=0; +// QString location="t"; +// +// //Google uses a latitude divided by 2; +// qreal halflat = latitude; +// +// for (int i = 0; i < zoom; i++) +// { +// xmoy = (xmax + xmin) / 2; +// ymoy = (ymax + ymin) / 2; +// if (halflat >= ymoy) //upper part (q or r) +// { +// ymin = ymoy; +// if (longitude < xmoy) +// { /*q*/ +// location+= "q"; +// xmax = xmoy; +// } +// else +// {/*r*/ +// location+= "r"; +// xmin = xmoy; +// } +// } +// else //lower part (t or s) +// { +// ymax = ymoy; +// if (longitude < xmoy) +// { /*t*/ +// +// location+= "t"; +// xmax = xmoy; +// } +// else +// {/*s*/ +// location+= "s"; +// xmin = xmoy; +// } +// } +// } +// return QString("/kh/v=51&t=%1").arg(location); +// } +//} +// diff --git a/ground/src/libs/qmapcontrol/src/googlesatmapadapter.h b/ground/src/libs/qmapcontrol/src/googlesatmapadapter.h index a74d3e909..5ba35e8ce 100644 --- a/ground/src/libs/qmapcontrol/src/googlesatmapadapter.h +++ b/ground/src/libs/qmapcontrol/src/googlesatmapadapter.h @@ -45,30 +45,30 @@ namespace qmapcontrol GoogleSatMapAdapter(); virtual ~GoogleSatMapAdapter(); - virtual QPoint coordinateToDisplay(const QPointF&) const; - virtual QPointF displayToCoordinate(const QPoint&) const; - - //! returns the host of this MapAdapter - /*! - * @return the host of this MapAdapter - */ - QString getHost () const; - - - protected: - virtual void zoom_in(); - virtual void zoom_out(); - virtual QString query(int x, int y, int z) const; - virtual bool isValid(int x, int y, int z) const; - - private: - virtual QString getQ(qreal longitude, qreal latitude, int zoom) const; - qreal getMercatorLatitude(qreal YCoord) const; - qreal getMercatorYCoord(qreal lati) const; - - qreal coord_per_x_tile; - qreal coord_per_y_tile; - int srvNum; +// virtual QPoint coordinateToDisplay(const QPointF&) const; +// virtual QPointF displayToCoordinate(const QPoint&) const; +// +// //! returns the host of this MapAdapter +// /*! +// * @return the host of this MapAdapter +// */ +// QString getHost () const; +// +// +// protected: +// virtual void zoom_in(); +// virtual void zoom_out(); +// virtual QString query(int x, int y, int z) const; +// virtual bool isValid(int x, int y, int z) const; +// +// private: +// virtual QString getQ(qreal longitude, qreal latitude, int zoom) const; +// qreal getMercatorLatitude(qreal YCoord) const; +// qreal getMercatorYCoord(qreal lati) const; +// +// qreal coord_per_x_tile; +// qreal coord_per_y_tile; +// int srvNum; }; } #endif