2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Sami Rämö - sami.ramo@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25 #include "mapcommon.h"
26 #include "mapengine.h"
30 : m_tileNumber(QPoint(UNDEFINED, UNDEFINED))
31 , m_zoomLevel(UNDEFINED)
33 qDebug() << __PRETTY_FUNCTION__;
35 setPos(UNDEFINED, UNDEFINED);
36 setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
39 int MapTile::zoomLevel()
41 qDebug() << __PRETTY_FUNCTION__;
46 void MapTile::setZoomLevel(int tileZoomLevel, int currentViewZoomLevel)
48 qDebug() << __PRETTY_FUNCTION__;
50 m_zoomLevel = tileZoomLevel;
53 setSceneLevel(currentViewZoomLevel);
55 qreal zoomFactor = static_cast<qreal>(1 << (OSM_MAX_ZOOM_LEVEL - m_zoomLevel));
59 void MapTile::setSceneLevel(int currentZoomLevel)
61 qDebug() << __PRETTY_FUNCTION__;
63 if (currentZoomLevel < m_zoomLevel) {
64 qreal z = static_cast<qreal>(MAP_SCENE_MIN_NORMAL_LEVEL + currentZoomLevel
65 - (m_zoomLevel - currentZoomLevel)) + 0.5;
69 setZValue(static_cast<qreal>(MAP_SCENE_MIN_NORMAL_LEVEL + m_zoomLevel));
72 QPoint MapTile::tileNumber()
74 qDebug() << __PRETTY_FUNCTION__;
79 void MapTile::setTileNumber(QPoint tileNumber)
81 qDebug() << __PRETTY_FUNCTION__;
83 m_tileNumber = tileNumber;
87 void MapTile::setPosition()
89 qDebug() << __PRETTY_FUNCTION__;
91 const int MAX_TILE_NUMBER = MapEngine::tileMaxIndex(m_zoomLevel);
93 // calculate min & max horizontal tile index numbers
94 const int INDEX_0_TILE = 1;
95 const int MIN_TILE_NUMBER_X = -MapEngine::tilesPerSide(m_zoomLevel)
96 * MAP_SCENE_VERTICAL_OVERSIZE_FACTOR;
97 const int MAX_TILE_NUMBER_X = MapEngine::tilesPerSide(m_zoomLevel)
98 * (1 + MAP_SCENE_VERTICAL_OVERSIZE_FACTOR)
101 if ((m_zoomLevel >= OSM_MIN_ZOOM_LEVEL) && (m_zoomLevel <= OSM_MAX_ZOOM_LEVEL)
102 && (m_tileNumber.x() >= MIN_TILE_NUMBER_X) && (m_tileNumber.x() <= MAX_TILE_NUMBER_X)
103 && (m_tileNumber.y() >= 0) && (m_tileNumber.y() <= MAX_TILE_NUMBER)) {
104 setPos(MapEngine::convertTileNumberToSceneCoordinate(m_zoomLevel, m_tileNumber).toPointF());
106 setPos(UNDEFINED, UNDEFINED);