Skip to content

Commit

Permalink
Added yandex maps
Browse files Browse the repository at this point in the history
  • Loading branch information
agafon0ff committed Oct 27, 2020
1 parent e38bf10 commit 7532de3
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 269 deletions.
44 changes: 39 additions & 5 deletions src/mapglobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,26 @@ QPointF MapGlobal::toCoords(const QPointF &point)
qreal tilesCount = static_cast<qreal>(d->tilesCount);

qreal lon = (point.x() - tileWidth / 2) / (tilesCount * tileWidth) * 360. - 180.;
qreal lat = M_PI - 2. * M_PI * (point.y() - tileWidth / 2) / (tilesCount * tileWidth);
lat = 180. / M_PI * atan(0.5 * (exp(lat) - exp(-lat)));
qreal lat = 0;

if (d->provider == YandexMap || d->provider == YandexSat)
{
double a = 6378137.0;
double c1 = 0.00335655146887969;
double c2 = 0.00000657187271079536;
double c3 = 0.00000001764564338702;
double c4 = 0.00000000005328478445;

double mercY = 20037508.342789 - (point.y() * pow(2, 24 - d->zoomMax)) / 53.5865938;
double g = M_PI / 2 - 2 * atan(1 / exp(mercY / a));
double zz = g + c1 * sin(2 * g) + c2 * sin(4 * g) + c3 * sin(6 * g) + c4 * sin(8 * g);
lat = zz * 180 / M_PI;
}
else
{
lat = M_PI - 2. * M_PI * (point.y() - tileWidth / 2) / (tilesCount * tileWidth);
lat = 180. / M_PI * atan(0.5 * (exp(lat) - exp(-lat)));
}

return QPointF(lon, lat);
}
Expand All @@ -93,10 +111,26 @@ QPointF MapGlobal::toPoint(const QPointF &coords)
qreal tilesCount = static_cast<qreal>(d->tilesCount);

qreal x = (coords.x() + 180.) * (tilesCount * tileWidth) / 360.;
qreal y = (1. - log(tan(coords.y() * M_PI / 180.) + 1. /
cos(coords.y() * M_PI / 180.)) / M_PI) / 2. * (tilesCount * tileWidth);
x += tileWidth / 2;
y += tileWidth / 2;

qreal y = 0;

if (d->provider == YandexMap || d->provider == YandexSat)
{
double rLat = coords.y() * M_PI / 180;
double a = 6378137.0;
double k = 0.0818191908426;

double zz = tan(M_PI / 4 + rLat / 2) / pow((tan(M_PI / 4 + asin(k * sin(rLat)) / 2)), k);
y = static_cast<int>((20037508.342789 - a * log(zz)) * 53.5865938 / pow(2, 24 - d->zoomMax));
}
else
{
y = (1. - log(tan(coords.y() * M_PI / 180.) + 1. /
cos(coords.y() * M_PI / 180.)) / M_PI) / 2. * (tilesCount * tileWidth);

y += tileWidth / 2;
}

return QPoint(x, y);
}
Expand Down
4 changes: 3 additions & 1 deletion src/mapglobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ enum MapProviders
GoogleLand,
BingSat,
BingRoads,
OsmMap
OsmMap,
YandexMap, // Don't work
YandexSat // Don't work
};

class MapGlobal
Expand Down
8 changes: 6 additions & 2 deletions src/maploader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ static const QMap<int, QString> MAP_PROVIDERS = {
{GoogleLand,"http://mt0.google.com/vt/lyrs=p&hl=ru&x=%1&y=%2&z=%3"},
{BingSat, "http://ecn.t0.tiles.virtualearth.net/tiles/a%1.jpeg?g=0"},
{BingRoads, "http://ecn.dynamic.t0.tiles.virtualearth.net/comp/CompositionHandler/%1?mkt=ru-ru&it=G,VE,BX,L,LA&shading=hill"},
{OsmMap, "http://a.tile.openstreetmap.fr/hot/%3/%1/%2.png"}
{OsmMap, "http://a.tile.openstreetmap.fr/hot/%3/%1/%2.png"},
{YandexMap, "http://vec01.maps.yandex.net/tiles?l=map&lang=ru-RU&v=2.26.0&x=%1&y=%2&z=%3"}, // Don't work
{YandexSat, "https://sat01.maps.yandex.net/tiles?l=sat&v=3.379.0&x=%1&y=%2&z=%3"} // Don't work
};

static const QMap<int, QString> MAP_CACHE_PATHS = {
Expand All @@ -28,7 +30,9 @@ static const QMap<int, QString> MAP_CACHE_PATHS = {
{GoogleLand,"/land/z%1/%2/x%3/%4/y%5.jpg"},
{BingSat, "/vesat/z%1/%2/x%3/%4/y%5.jpg"},
{BingRoads, "/bing_roads_ru/z%1/%2/x%3/%4/y%5.png"},
{OsmMap, "/osm/z%1/%2/x%3/%4/y%5.png"}
{OsmMap, "/osm/z%1/%2/x%3/%4/y%5.png"},
{YandexMap, "/yam/z%1/%2/x%3/%4/y%5.png"}, // Don't work
{YandexSat, "/yas/z%1/%2/x%3/%4/y%5.png"} // Don't work
};

struct MapLoader::MapLoaderPrivate
Expand Down
2 changes: 2 additions & 0 deletions src/mapview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ void MapView::mouseReleaseEvent(QMouseEvent *e)
QGraphicsView::mouseReleaseEvent(e);
viewport()->setCursor(Qt::ArrowCursor);

emit clickCoords(d->settings.toCoords(mapToScene(e->pos())));

d->isMove = false;
}

Expand Down
1 change: 1 addition & 0 deletions src/mapview.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class MapView : public QGraphicsView
void zoomChanged(int zoom);
void scaleFactorChanged(qreal factor);
void cursorCoords(const QPointF &point);
void clickCoords(const QPointF &point);

private:

Expand Down
Loading

0 comments on commit 7532de3

Please sign in to comment.