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 "coordinates/scenecoordinate.h"
26 #include "mapcommon.h"
31 : m_zoomLevel(UNDEFINED)
32 , m_tileNumber(QPoint(UNDEFINED, UNDEFINED))
34 qDebug() << __PRETTY_FUNCTION__;
36 setPos(UNDEFINED, UNDEFINED);
37 setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
40 SceneCoordinate MapTile::convertTileNumberToSceneCoordinate(int zoomLevel, QPoint tileNumber)
42 qDebug() << __PRETTY_FUNCTION__;
44 int pow = 1 << (OSM_MAX_ZOOM_LEVEL - zoomLevel);
45 int x = tileNumber.x() * OSM_TILE_SIZE_X * pow;
46 int y = tileNumber.y() * OSM_TILE_SIZE_Y * pow;
48 return SceneCoordinate(x, y);
51 int MapTile::lastTileIndex(int zoomLevel)
53 qDebug() << __PRETTY_FUNCTION__;
55 // subtract one because first tile index is zero
56 return tilesPerSide(zoomLevel) - 1;
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 void MapTile::setTileNumber(QPoint tileNumber)
74 qDebug() << __PRETTY_FUNCTION__;
76 m_tileNumber = tileNumber;
80 void MapTile::setPosition()
82 qDebug() << __PRETTY_FUNCTION__;
84 const int MAX_TILE_NUMBER = MapTile::lastTileIndex(m_zoomLevel);
86 // calculate min & max horizontal tile index numbers
87 const int INDEX_0_TILE = 1;
88 const int MIN_TILE_NUMBER_X = -tilesPerSide(m_zoomLevel)
89 * MAP_SCENE_VERTICAL_OVERSIZE_FACTOR;
90 const int MAX_TILE_NUMBER_X = tilesPerSide(m_zoomLevel)
91 * (1 + MAP_SCENE_VERTICAL_OVERSIZE_FACTOR)
94 if ((m_zoomLevel >= OSM_MIN_ZOOM_LEVEL) && (m_zoomLevel <= OSM_MAX_ZOOM_LEVEL)
95 && (m_tileNumber.x() >= MIN_TILE_NUMBER_X) && (m_tileNumber.x() <= MAX_TILE_NUMBER_X)
96 && (m_tileNumber.y() >= 0) && (m_tileNumber.y() <= MAX_TILE_NUMBER)) {
97 setPos(convertTileNumberToSceneCoordinate(m_zoomLevel, m_tileNumber).toPointF());
99 setPos(UNDEFINED, UNDEFINED);
103 void MapTile::setZoomLevel(int tileZoomLevel, int currentViewZoomLevel)
105 qDebug() << __PRETTY_FUNCTION__;
107 m_zoomLevel = tileZoomLevel;
110 setSceneLevel(currentViewZoomLevel);
112 qreal zoomFactor = static_cast<qreal>(1 << (OSM_MAX_ZOOM_LEVEL - m_zoomLevel));
113 setScale(zoomFactor);
116 QPoint MapTile::tileNumber()
118 qDebug() << __PRETTY_FUNCTION__;
123 QString MapTile::tilePath(int zoomLevel, int x, int y)
125 qDebug() << __PRETTY_FUNCTION__;
127 QString tilePathString(QString::number(zoomLevel) + "/");
128 tilePathString.append(QString::number(x) + "/");
129 tilePathString.append(QString::number(y));
131 return tilePathString;
134 int MapTile::tilesPerSide(int zoomLevel)
136 return (1 << zoomLevel);
139 int MapTile::zoomLevel()
141 qDebug() << __PRETTY_FUNCTION__;