summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Nienhüser <nienhueser@kde.org>2016-09-11 04:57:22 (GMT)
committerDennis Nienhüser <nienhueser@kde.org>2016-09-11 05:53:40 (GMT)
commitcc98be13cf2a13bd4ed16c8f37569f97cbe46e4d (patch)
treeaef337329d7b7fe036e58c89f7d82d4c65d282a1
parent2fbf41d031b734ee2bb1046aca2e25ed15406450 (diff)
Move lon2tileX, lat2TileY methods to TileId class
-rw-r--r--src/lib/marble/TileId.cpp18
-rw-r--r--src/lib/marble/TileId.h3
-rw-r--r--src/lib/marble/VectorTileModel.cpp24
-rw-r--r--src/lib/marble/VectorTileModel.h3
4 files changed, 26 insertions, 22 deletions
diff --git a/src/lib/marble/TileId.cpp b/src/lib/marble/TileId.cpp
index ed4afbe..d8e7e26 100644
--- a/src/lib/marble/TileId.cpp
+++ b/src/lib/marble/TileId.cpp
@@ -12,6 +12,8 @@
// Own
#include "TileId.h"
+#include "MarbleMath.h"
+
#include <QDebug>
namespace Marble
@@ -85,6 +87,22 @@ TileId TileId::fromCoordinates(const GeoDataCoordinates &coords, int zoomLevel)
return TileId(0, zoomLevel, x, y);
}
+unsigned int TileId::lon2tileX( qreal lon, unsigned int maxTileX )
+{
+ return (unsigned int)floor(0.5 * (lon / M_PI + 1.0) * maxTileX);
+}
+
+unsigned int TileId::lat2tileY( qreal latitude, unsigned int maxTileY )
+{
+ // We need to calculate the tile position from the latitude
+ // projected using the Mercator projection. This requires the inverse Gudermannian
+ // function which is only defined between -85°S and 85°N. Therefore in order to
+ // prevent undefined results we need to restrict our calculation:
+ qreal maxAbsLat = 85.0 * DEG2RAD;
+ qreal lat = (qAbs(latitude) > maxAbsLat) ? latitude/qAbs(latitude) * maxAbsLat : latitude;
+ return (unsigned int)floor(0.5 * (1.0 - gdInv(lat) / M_PI) * maxTileY);
+}
+
}
#ifndef QT_NO_DEBUG_STREAM
diff --git a/src/lib/marble/TileId.h b/src/lib/marble/TileId.h
index 5bf94e4..baab7d3 100644
--- a/src/lib/marble/TileId.h
+++ b/src/lib/marble/TileId.h
@@ -43,6 +43,9 @@ class MARBLE_EXPORT TileId
GeoDataLatLonBox toLatLonBox( const GeoSceneTileDataset *textureLayer ) const;
static TileId fromCoordinates( const GeoDataCoordinates& coords, int zoomLevel );
+ static unsigned int lon2tileX( qreal lon, unsigned int maxTileX );
+ static unsigned int lat2tileY( qreal lat, unsigned int maxTileY );
+
private:
uint m_mapThemeIdHash;
int m_zoomLevel;
diff --git a/src/lib/marble/VectorTileModel.cpp b/src/lib/marble/VectorTileModel.cpp
index 5da2834..4e4c7b4 100644
--- a/src/lib/marble/VectorTileModel.cpp
+++ b/src/lib/marble/VectorTileModel.cpp
@@ -26,7 +26,7 @@
#include <qmath.h>
#include <QThreadPool>
-using namespace Marble;
+namespace Marble {
TileRunner::TileRunner( TileLoader *loader, const GeoSceneVectorTileDataset *texture, const TileId &id ) :
m_loader( loader ),
@@ -124,10 +124,10 @@ void VectorTileModel::setViewport( const GeoDataLatLonBox &latLonBox, int radius
// More info: http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Subtiles
// More info: http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#C.2FC.2B.2B
// Sometimes the formula returns wrong huge values, x and y have to be between 0 and 2^ZoomLevel
- unsigned int westX = qBound<unsigned int>( 0, lon2tileX( latLonBox.west(), maxTileX ), maxTileX);
- unsigned int northY = qBound<unsigned int>( 0, lat2tileY( latLonBox.north(), maxTileY ), maxTileY);
- unsigned int eastX = qBound<unsigned int>( 0, lon2tileX( latLonBox.east(), maxTileX ), maxTileX);
- unsigned int southY = qBound<unsigned int>( 0, lat2tileY( latLonBox.south(), maxTileY ), maxTileY );
+ unsigned int westX = qBound<unsigned int>( 0, TileId::lon2tileX( latLonBox.west(), maxTileX ), maxTileX);
+ unsigned int northY = qBound<unsigned int>( 0, TileId::lat2tileY( latLonBox.north(), maxTileY ), maxTileY);
+ unsigned int eastX = qBound<unsigned int>( 0, TileId::lon2tileX( latLonBox.east(), maxTileX ), maxTileX);
+ unsigned int southY = qBound<unsigned int>( 0, TileId::lat2tileY( latLonBox.south(), maxTileY ), maxTileY );
// Download tiles and send them to VectorTileLayer
// When changing zoom, download everything inside the screen
@@ -235,20 +235,6 @@ void VectorTileModel::cleanupTile(GeoDataObject *object)
}
}
-unsigned int VectorTileModel::lon2tileX( qreal lon, unsigned int maxTileX )
-{
- return (unsigned int)floor(0.5 * (lon / M_PI + 1.0) * maxTileX);
-}
-
-unsigned int VectorTileModel::lat2tileY( qreal latitude, unsigned int maxTileY )
-{
- // We need to calculate the tile position from the latitude
- // projected using the Mercator projection. This requires the inverse Gudermannian
- // function which is only defined between -85°S and 85°N. Therefore in order to
- // prevent undefined results we need to restrict our calculation:
- qreal maxAbsLat = 85.0 * DEG2RAD;
- qreal lat = (qAbs(latitude) > maxAbsLat) ? latitude/qAbs(latitude) * maxAbsLat : latitude;
- return (unsigned int)floor(0.5 * (1.0 - gdInv(lat) / M_PI) * maxTileY);
}
#include "moc_VectorTileModel.cpp"
diff --git a/src/lib/marble/VectorTileModel.h b/src/lib/marble/VectorTileModel.h
index baa6108..4d9e26d 100644
--- a/src/lib/marble/VectorTileModel.h
+++ b/src/lib/marble/VectorTileModel.h
@@ -82,9 +82,6 @@ private:
void removeTilesOutOfView(const GeoDataLatLonBox &boundingBox);
void queryTiles( int tileZoomLevel, unsigned int minX, unsigned int minY, unsigned int maxX, unsigned int maxY );
- static unsigned int lon2tileX( qreal lon, unsigned int maxTileX );
- static unsigned int lat2tileY( qreal lat, unsigned int maxTileY );
-
private:
struct CacheDocument
{