const int MAX_TILES_PER_SIDE = (1 << MAX_MAP_ZOOM_LEVEL);
const int WORLD_PIXELS_X = MAX_TILES_PER_SIDE * TILE_SIZE_X;
+const int MAP_SCENE_MIN_PIXEL_X = -WORLD_PIXELS_X / 2;
+const int MAP_SCENE_MAX_PIXEL_X = WORLD_PIXELS_X * 2;
/**
* @var DEFAULT_START_ZOOM_LEVEL
const qreal DEFAULT_LONGITUDE = 0.0000; ///< Default longitude value
const qreal DEFAULT_LATITUDE = 0.0000; ///< Default latitude value
-const int GRID_PADDING = 2; ///< Grid padding used in tile grid calculation
+const int GRID_PADDING = 0; ///< Grid padding used in tile grid calculation
const QString OSM_LICENSE = QString::fromUtf8("© OpenStreetMap contributors, CC-BY-SA");
QPoint tileNumber(x, y);
m_mapScene->addTile(zoomLevel, tileNumber, image, m_zoomLevel);
+ // add 1 so odd width is rounded up and even is rounded down
int tilesGridWidthHalf = (m_viewTilesGrid.width() + 1) / 2;
// expand to east side? (don't need to expand over padding)
}
// expand to west side? (don't need to expand over padding)
- if (tileNumber.x() > (tileMaxValue(zoomLevel) - tilesGridWidthHalf + GRID_PADDING)) {
+ if (tileNumber.x() > (tileMaxValue(zoomLevel) - tilesGridWidthHalf + GRID_PADDING - 1)) {
QPoint adjustedTileNumber(tileNumber.x() - tileMaxValue(zoomLevel) - 1, tileNumber.y());
m_mapScene->addTile(zoomLevel, adjustedTileNumber, image, m_zoomLevel);
// qWarning() << __PRETTY_FUNCTION__ << "duplicate tile to west, x:" << x << "->" << adjustedTileNumber.x() << "y:" << adjustedTileNumber.y();
m_tilesGridSize.setHeight(gridHeight);
m_tilesGridSize.setWidth(gridWidth);
-// qWarning() << __PRETTY_FUNCTION__ << "tiles grid:" << m_tilesGridSize.width()
-// << "*" << m_tilesGridSize.height();
+ qWarning() << __PRETTY_FUNCTION__ << "tiles grid:" << m_tilesGridSize.width()
+ << "*" << m_tilesGridSize.height()
+ << "=" << m_tilesGridSize.width() * m_tilesGridSize.height() << "tiles";
}
void MapEngine::setViewLocation(QPointF latLonCoordinate)
/**
* @brief Slot for received map tile images
*
- * Does add MapTile objects to MapScene. Does also remove old tile if tile already exists.
+ * Does receive map tile images from MapFetcher. Calls MapScene::addTile() for creating and adding
+ * the actual MapTile object to the MapScene.
+ *
+ * Tile is added also to outside the world horizontal limits, if required, for spanning the map.
*
* @param zoomLevel Zoom level
* @param x Tile x index
{
qDebug() << __PRETTY_FUNCTION__;
+ const int MAX_UPPER_LEVELS = 4;
+
bool imageFound = false;
QAbstractNetworkCache *cache = m_manager->cache();
parseURL(url, &zoomLevel, &x, &y);
int originalZoomLevel = zoomLevel;
- // try to fetch requested and upper level images until found or all levels tried
+ // try to fetch requested and upper level images until found or MAX_UPPER_LEVELS
+ // limit is reached
do {
QIODevice *cacheImage = cache->data(buildURL(zoomLevel, QPoint(x, y)));
if (cacheImage) {
delete cacheImage;
}
- } while (!imageFound && translateIndexesToUpperLevel(zoomLevel, x, y));
+ } while (!imageFound
+ && (originalZoomLevel - zoomLevel) < MAX_UPPER_LEVELS
+ && translateIndexesToUpperLevel(zoomLevel, x, y));
// check expiration if image was found from requested level
if (imageFound && (originalZoomLevel == zoomLevel)) {
#include "mapscene.h"
-const int WORLD_PIXELS_Y = MAX_TILES_PER_SIDE * TILE_SIZE_Y;
+const int MAP_MIN_PIXEL_Y = 0;
+const int MAP_MAX_PIXEL_Y = MAX_TILES_PER_SIDE * TILE_SIZE_Y - 1;
MapScene::MapScene(QObject *parent)
: QGraphicsScene(parent)
qDebug() << __PRETTY_FUNCTION__;
setBackgroundBrush(Qt::lightGray);
- setSceneRect(-WORLD_PIXELS_X * 2, 0, WORLD_PIXELS_X * 5 - 1, WORLD_PIXELS_Y - 1);
+ setSceneRect(MAP_SCENE_MIN_PIXEL_X, MAP_MIN_PIXEL_Y, MAP_SCENE_MAX_PIXEL_X, MAP_MAX_PIXEL_Y);
}
void MapScene::addTile(int tileZoomLevel, QPoint tileNumber, const QPixmap &image, int viewZoomLevel)
removeTile(tileToRemove);
}
}
+
+ qWarning() << __PRETTY_FUNCTION__ << "tiles in scene:" << items().count();
}
void MapScene::removeStackedTiles(MapTile *newTile)
}
}
}
+// qWarning() << __PRETTY_FUNCTION__ << "tiles in scene:" << items().count();
}
void MapScene::removeTile(MapTile *tile)
int overlap = viewHeight / 2 * (1 << (MAX_MAP_ZOOM_LEVEL - zoomLevel));
QRect rect = sceneRect().toRect();
- rect.setTop(-overlap);
- rect.setBottom(WORLD_PIXELS_Y + overlap - 1);
+ rect.setTop(MAP_MIN_PIXEL_Y - overlap);
+ rect.setBottom(MAP_MAX_PIXEL_Y + overlap);
setSceneRect(rect);
// qWarning() << __PRETTY_FUNCTION__ << "scene rect:" << rect.left() << rect.top() << rect.right() << rect.bottom();
// create rects for left and right side
QRect leftRect = sceneRect().toRect(); // this way we get the horizontal limits of the scene
- leftRect.setTop(0);
- leftRect.setBottom(WORLD_PIXELS_Y);
+ leftRect.setTop(MAP_MIN_PIXEL_Y);
+ leftRect.setBottom(MAP_MAX_PIXEL_Y);
QRect rightRect = leftRect;
// calculate current horizontal area shown on the view
leftRect.setRight(-1 - (WORLD_PIXELS_X - 1 - viewSceneRight));
rightRect.setLeft(WORLD_PIXELS_X + viewSceneLeft);
-// Q_ASSERT_X(leftRect.right() < viewSceneLeft, "spanning rect right value", "move rect is in the view area");
-// Q_ASSERT_X(rightRect.left() > viewSceneRight, "spanning rect left value", "move rect is in the view area");
+ Q_ASSERT_X(leftRect.right() < viewSceneLeft, "spanning rect right value", "move rect is in the view area");
+ Q_ASSERT_X(rightRect.left() > viewSceneRight, "spanning rect left value", "move rect is in the view area");
// move all items which intersects the rects
if (leftRect.left() < leftRect.right())