mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-19 09:54:15 +01:00
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
This commit is contained in:
parent
30f8da6e82
commit
74e5cfa3ca
@ -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)
|
||||
{
|
||||
}
|
||||
|
@ -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);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user