Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 713 → Rev 801

/QMK-Groundstation/trunk/Global/Class_QMapControl/googlemapadapter.cpp
27,8 → 27,9
namespace qmapcontrol
{
GoogleMapAdapter::GoogleMapAdapter()
: TileMapAdapter("mt2.google.com", "/mt?n=404&x=%2&y=%3&zoom=%1", 256, 17, 0)
//: TileMapAdapter("tile.openstreetmap.org", "/%1/%2/%3.png", 256, 0, 17)
: TileMapAdapter("mt1.google.com", "/vt/lyrs=m@120&hl=de&x=%2&y=%3&z=%1&s=", 256, 0, 17)
// : TileMapAdapter("mt1.google.com", "/mt?n=404&x=%2&y=%3&zoom=%1", 256, 17, 0)
// : TileMapAdapter("server.arcgisonline.com", "/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer/tile/%1/%3/%2", 512, 0, 17)
{
}
 
/QMK-Groundstation/trunk/Global/Class_QMapControl/googlesatmapadapter.cpp
24,158 → 24,14
*/
 
#include "googlesatmapadapter.h"
 
#include <math.h>
namespace qmapcontrol
{
GoogleSatMapAdapter::GoogleSatMapAdapter()
: TileMapAdapter("kh.google.com", "/kh?n=404&v=8&t=trtqtt", 256, 0, 19)
: TileMapAdapter("khm1.google.com", "/kh/v=57&hl=de&x=%2&y=%3&z=%1&s=", 256, 0, 20)
{
// 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);
}
}
 
/QMK-Groundstation/trunk/Global/Class_QMapControl/googlesatmapadapter.h
27,6 → 27,7
#define GOOGLESATMAPADAPTER_H
 
#include "tilemapadapter.h"
 
namespace qmapcontrol
{
//! MapAdapter for Google
37,6 → 38,7
class GoogleSatMapAdapter : public TileMapAdapter
{
Q_OBJECT
 
public:
//! constructor
/*!
44,31 → 46,6
*/
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;
};
}
#endif