Merge branch 'master' into kinetic
[situare] / src / map / mapengine.cpp
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Sami Rämö - sami.ramo@ixonos.com
6        Jussi Laitinen - jussi.laitinen@ixonos.com
7        Pekka Nissinen - pekka.nissinen@ixonos.com
8        Ville Tiensuu - ville.tiensuu@ixonos.com
9
10    Situare is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License
12    version 2 as published by the Free Software Foundation.
13
14    Situare is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with Situare; if not, write to the Free Software
21    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
22    USA.
23 */
24
25 #include <QtAlgorithms>
26 #include <QDebug>
27 #include <QString>
28 #include <QStringList>
29 #include <QUrl>
30 #include <QHash>
31 #include <QHashIterator>
32 #include <QRect>
33
34 #include "common.h"
35 #include "frienditemshandler.h"
36 #include "gpslocationitem.h"
37 #include "mapcommon.h"
38 #include "mapfetcher.h"
39 #include "mapscene.h"
40 #include "mapscroller.h"
41 #include "maptile.h"
42 #include "network/networkaccessmanager.h"
43 #include "ownlocationitem.h"
44 #include "user/user.h"
45
46 #include "mapengine.h"
47
48 const int SMOOTH_CENTERING_TIME_MS = 1000;
49
50 MapEngine::MapEngine(QObject *parent)
51     : QObject(parent),
52       m_autoCenteringEnabled(false),
53       m_scrollStartedByGps(false),
54       m_smoothScrollRunning(false),
55       m_zoomedIn(false),
56       m_zoomLevel(DEFAULT_ZOOM_LEVEL),
57       m_centerTile(QPoint(UNDEFINED, UNDEFINED)),
58       m_lastAutomaticPosition(QPoint(0, 0)),
59       m_tilesGridSize(QSize(0, 0)),
60       m_viewSize(QSize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT))
61 {
62     qDebug() << __PRETTY_FUNCTION__;
63
64     m_mapScene = new MapScene(this);
65
66     m_mapFetcher = new MapFetcher(NetworkAccessManager::instance(), this);
67     connect(this, SIGNAL(fetchImage(int, int, int)),
68             m_mapFetcher, SLOT(enqueueFetchMapImage(int, int, int)));
69     connect(m_mapFetcher, SIGNAL(mapImageReceived(int, int, int, QPixmap)),
70             this, SLOT(mapImageReceived(int, int, int, QPixmap)));
71     connect(m_mapFetcher, SIGNAL(error(int, int)),
72             this, SIGNAL(error(int, int)));
73
74     m_ownLocation = new OwnLocationItem();
75     m_ownLocation->hide(); // hide until first location info is received
76     m_mapScene->addItem(m_ownLocation);
77
78     m_gpsLocationItem = new GPSLocationItem();
79     m_mapScene->addItem(m_gpsLocationItem);
80
81     m_friendItemsHandler = new FriendItemsHandler(m_mapScene, this);
82     connect(this, SIGNAL(zoomLevelChanged(int)),
83             m_friendItemsHandler, SLOT(refactorFriendItems(int)));
84
85     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
86             m_friendItemsHandler, SLOT(friendListUpdated(QList<User*>&)));
87
88     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
89             this, SLOT(friendsPositionsUpdated()));
90
91     connect(m_friendItemsHandler, SIGNAL(locationItemClicked(QList<QString>)),
92             this, SIGNAL(locationItemClicked(QList<QString>)));
93
94     m_scroller = &MapScroller::getInstance();
95
96     connect(m_scroller, SIGNAL(coordinateUpdated(QPoint)),
97             this, SLOT(setCenterPosition(QPoint)));
98
99     connect(m_scroller, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)),
100             this, SLOT(scrollerStateChanged(QAbstractAnimation::State)));
101 }
102
103 MapEngine::~MapEngine()
104 {
105     qDebug() << __PRETTY_FUNCTION__;
106
107     QSettings settings(DIRECTORY_NAME, FILE_NAME);
108     settings.setValue(MAP_LAST_POSITION,
109                       convertSceneCoordinateToLatLon(m_zoomLevel, m_sceneCoordinate));
110     settings.setValue(MAP_LAST_ZOOMLEVEL, m_zoomLevel);
111 }
112
113 QRect MapEngine::calculateTileGrid(QPoint sceneCoordinate)
114 {
115     qDebug() << __PRETTY_FUNCTION__;
116
117     QPoint tileCoordinate = convertSceneCoordinateToTileNumber(m_zoomLevel, sceneCoordinate);
118
119     QPoint topLeft;
120     topLeft.setX(tileCoordinate.x() - (m_tilesGridSize.width() / 2));
121     topLeft.setY(tileCoordinate.y() - (m_tilesGridSize.height() / 2));
122
123     return QRect(topLeft, m_tilesGridSize);
124 }
125
126 QPointF MapEngine::centerGeoCoordinate()
127 {
128     qDebug() << __PRETTY_FUNCTION__;
129
130     return convertSceneCoordinateToLatLon(m_zoomLevel, m_sceneCoordinate);
131 }
132
133 void MapEngine::centerToCoordinates(QPointF latLonCoordinate)
134 {
135     qDebug() << __PRETTY_FUNCTION__;
136
137     scrollToPosition(convertLatLonToSceneCoordinate(latLonCoordinate));
138 }
139
140 QPoint MapEngine::convertLatLonToSceneCoordinate(QPointF latLonCoordinate)
141 {
142     qDebug() << __PRETTY_FUNCTION__;
143
144     qreal longitude = latLonCoordinate.x();
145     qreal latitude = latLonCoordinate.y();
146
147     if ((longitude > MAX_LONGITUDE) || (longitude < MIN_LONGITUDE))
148         return QPoint(UNDEFINED, UNDEFINED);
149     if ((latitude > MAX_LATITUDE) || (latitude < MIN_LATITUDE))
150         return QPoint(UNDEFINED, UNDEFINED);
151
152     qreal z = static_cast<qreal>(MapEngine::tilesPerSide(MAX_MAP_ZOOM_LEVEL));
153
154     qreal x = static_cast<qreal>((longitude + 180.0) / 360.0);
155     qreal y = static_cast<qreal>((1.0 - log(tan(latitude * M_PI / 180.0) + 1.0
156                                 / cos(latitude * M_PI / 180.0)) / M_PI) / 2.0);
157
158     return QPointF(x * z * TILE_SIZE_X, y * z * TILE_SIZE_Y).toPoint();
159 }
160
161 QPointF MapEngine::convertSceneCoordinateToLatLon(int zoomLevel, QPoint sceneCoordinate)
162 {
163     qDebug() << __PRETTY_FUNCTION__;
164
165     double tileFactor = 1 << (MAX_MAP_ZOOM_LEVEL - zoomLevel);
166     double xFactor = (sceneCoordinate.x() / (TILE_SIZE_X*tileFactor));
167     double yFactor = (sceneCoordinate.y() / (TILE_SIZE_Y*tileFactor));
168
169     tileFactor = 1 << zoomLevel;
170     double longitude = xFactor / tileFactor * 360.0 - 180;
171
172     double n = M_PI - 2.0 * M_PI * yFactor / tileFactor;
173     double latitude = 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n)));
174
175     return QPointF(longitude, latitude);
176 }
177
178 QPoint MapEngine::convertSceneCoordinateToTileNumber(int zoomLevel, QPoint sceneCoordinate)
179 {
180     qDebug() << __PRETTY_FUNCTION__;
181
182     int pow = 1 << (MAX_MAP_ZOOM_LEVEL - zoomLevel);
183     int x = static_cast<int>(sceneCoordinate.x() / (TILE_SIZE_X * pow));
184     int y = static_cast<int>(sceneCoordinate.y() / (TILE_SIZE_Y * pow));
185
186     return QPoint(x, y);
187 }
188
189 QPoint MapEngine::convertTileNumberToSceneCoordinate(int zoomLevel, QPoint tileNumber)
190 {
191     qDebug() << __PRETTY_FUNCTION__;
192
193     int pow = 1 << (MAX_MAP_ZOOM_LEVEL - zoomLevel);
194     int x = tileNumber.x() * TILE_SIZE_X * pow;
195     int y = tileNumber.y() * TILE_SIZE_Y * pow;
196
197     return QPoint(x, y);
198 }
199
200 void MapEngine::disableAutoCenteringIfRequired(QPoint sceneCoordinate)
201 {
202     if (isAutoCenteringEnabled()) {
203         int zoomFactor = (1 << (MAX_MAP_ZOOM_LEVEL - m_zoomLevel));
204
205         QPoint oldPixelValue = QPoint(m_lastAutomaticPosition.x() / zoomFactor,
206                                       m_lastAutomaticPosition.y() / zoomFactor);
207
208         QPoint newPixelValue = QPoint(sceneCoordinate.x() / zoomFactor,
209                                       sceneCoordinate.y() / zoomFactor);
210
211         if ((abs(oldPixelValue.x() - newPixelValue.x()) > AUTO_CENTERING_DISABLE_DISTANCE)
212             || (abs(oldPixelValue.y() - newPixelValue.y()) > AUTO_CENTERING_DISABLE_DISTANCE)) {
213
214             emit mapScrolledManually();
215         }
216     }
217 }
218
219 void MapEngine::friendsPositionsUpdated()
220 {
221     qDebug() << __PRETTY_FUNCTION__;
222
223     m_mapScene->spanItems(m_zoomLevel, m_sceneCoordinate, m_viewSize);
224 }
225
226 void MapEngine::getTiles(QPoint sceneCoordinate)
227 {
228     qDebug() << __PRETTY_FUNCTION__;
229
230     m_viewTilesGrid = calculateTileGrid(sceneCoordinate);
231     updateViewTilesSceneRect();
232     m_mapScene->setTilesGrid(m_viewTilesGrid);
233
234     int topLeftX = m_viewTilesGrid.topLeft().x();
235     int topLeftY = m_viewTilesGrid.topLeft().y();
236     int bottomRightX = m_viewTilesGrid.bottomRight().x();
237     int bottomRightY = m_viewTilesGrid.bottomRight().y();
238
239     int tileMaxVal = tileMaxIndex(m_zoomLevel);
240
241     for (int x = topLeftX; x <= bottomRightX; ++x) {
242         for (int y = topLeftY; y <= bottomRightY; ++y) {
243
244             // map doesn't span in vertical direction, so y index must be inside the limits
245             if (y >= MAP_TILE_MIN_INDEX && y <= tileMaxVal) {
246                 if (!m_mapScene->tileInScene(tilePath(m_zoomLevel, x, y)))
247                     emit fetchImage(m_zoomLevel, normalize(x, MAP_TILE_MIN_INDEX, tileMaxVal), y);
248             }
249         }
250     }
251 }
252
253 void MapEngine::gpsPositionUpdate(QPointF position, qreal accuracy)
254 {
255     qDebug() << __PRETTY_FUNCTION__;
256
257     m_gpsLocationItem->updatePosition(convertLatLonToSceneCoordinate(position), accuracy);
258     m_mapScene->spanItems(m_zoomLevel, m_sceneCoordinate, m_viewSize);
259
260     if (m_autoCenteringEnabled) {
261         m_lastAutomaticPosition = convertLatLonToSceneCoordinate(position);
262         m_scrollStartedByGps = true;
263         scrollToPosition(m_lastAutomaticPosition);
264     }
265 }
266
267 qreal MapEngine::greatCircleDistance(QPointF firstLocation, QPointF secondLocation)
268 {
269     qDebug() << __PRETTY_FUNCTION__;
270
271     const qreal TORAD = (M_PI/180);
272
273     qreal dLat = (secondLocation.y() - firstLocation.y())*TORAD;
274     qreal dLon = (secondLocation.x() - firstLocation.x())*TORAD;
275     qreal a = pow(sin(dLat/2),2) + cos(firstLocation.y()*TORAD) * cos(secondLocation.y()*TORAD)
276               * pow(sin(dLon/2),2);
277     qreal c = 2 * atan2(sqrt(a), sqrt(1-a));
278
279     return (EARTH_RADIUS * c);
280 }
281
282 void MapEngine::init()
283 {
284     qDebug() << __PRETTY_FUNCTION__;
285
286     QPointF startLocation;
287     QSettings settings(DIRECTORY_NAME, FILE_NAME);
288
289     if (settings.value(MAP_LAST_POSITION, ERROR_VALUE_NOT_FOUND_ON_SETTINGS).toString()
290         == ERROR_VALUE_NOT_FOUND_ON_SETTINGS || settings.value(MAP_LAST_ZOOMLEVEL,
291         ERROR_VALUE_NOT_FOUND_ON_SETTINGS).toString() == ERROR_VALUE_NOT_FOUND_ON_SETTINGS) {
292
293         startLocation = QPointF(DEFAULT_LONGITUDE, DEFAULT_LATITUDE);
294         m_zoomLevel = qBound(MIN_VIEW_ZOOM_LEVEL, DEFAULT_START_ZOOM_LEVEL, MAX_MAP_ZOOM_LEVEL);
295     } else {
296         m_zoomLevel = settings.value(MAP_LAST_ZOOMLEVEL, ERROR_VALUE_NOT_FOUND_ON_SETTINGS).toInt();
297         startLocation = settings.value(MAP_LAST_POSITION,
298                                        ERROR_VALUE_NOT_FOUND_ON_SETTINGS).toPointF();
299     }
300
301     emit zoomLevelChanged(m_zoomLevel);
302     centerToCoordinates(QPointF(startLocation.x(), startLocation.y()));
303 }
304
305 bool MapEngine::isAutoCenteringEnabled()
306 {
307     return m_autoCenteringEnabled;
308 }
309
310 bool MapEngine::isCenterTileChanged(QPoint sceneCoordinate)
311 {
312     qDebug() << __PRETTY_FUNCTION__;
313
314     QPoint centerTile = convertSceneCoordinateToTileNumber(m_zoomLevel, sceneCoordinate);
315     QPoint temp = m_centerTile;
316     m_centerTile = centerTile;
317
318     return (centerTile != temp);
319 }
320
321 qreal MapEngine::sceneResolution()
322 {
323     qDebug() << __PRETTY_FUNCTION__;
324
325     const int SHIFT = 200;
326     const int KM_TO_M = 1000;
327     qreal scale = (1 << (MAX_MAP_ZOOM_LEVEL - m_zoomLevel));
328     QPointF centerCoordinate = centerGeoCoordinate();
329     QPoint shiftedSceneCoordinate = QPoint(m_sceneCoordinate.x() + SHIFT*scale
330                                            , m_sceneCoordinate.y());
331     QPointF shiftedCoordinate = convertSceneCoordinateToLatLon(m_zoomLevel, shiftedSceneCoordinate);
332     qreal dist = greatCircleDistance(centerCoordinate, shiftedCoordinate) * KM_TO_M;
333     return (dist / SHIFT);
334 }
335
336 void MapEngine::mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image)
337 {
338     qDebug() << __PRETTY_FUNCTION__;
339
340     // add normal tile inside the world
341     QPoint tileNumber(x, y);
342     m_mapScene->addTile(zoomLevel, tileNumber, image, m_zoomLevel);
343
344     // note: add 1 so odd width is rounded up and even is rounded down
345     int tilesGridWidthHalf = (m_viewTilesGrid.width() + 1) / 2;
346
347     // duplicate to east side? (don't need to duplicate over padding)
348     if (tileNumber.x() < (tilesGridWidthHalf - GRID_PADDING)) {
349         QPoint adjustedTileNumber(tileNumber.x() + tileMaxIndex(zoomLevel) + 1, tileNumber.y());
350         m_mapScene->addTile(zoomLevel, adjustedTileNumber, image, m_zoomLevel);
351     }
352
353     // duplicate to west side? (don't need to duplicate over padding)
354     if (tileNumber.x() > (tileMaxIndex(zoomLevel) - tilesGridWidthHalf + GRID_PADDING)) {
355         QPoint adjustedTileNumber(tileNumber.x() - tileMaxIndex(zoomLevel) - 1, tileNumber.y());
356         m_mapScene->addTile(zoomLevel, adjustedTileNumber, image, m_zoomLevel);
357     }
358 }
359
360 int MapEngine::normalize(int value, int min, int max)
361 {
362     qDebug() << __PRETTY_FUNCTION__;
363     Q_ASSERT_X(max >= min, "parameters", "max can't be smaller than min");
364
365     while (value < min)
366         value += max - min + 1;
367
368     while (value > max)
369         value -= max - min + 1;
370
371     return value;
372 }
373
374 void MapEngine::receiveOwnLocation(User *user)
375 {
376     qDebug() << __PRETTY_FUNCTION__;
377
378     if(user) {
379         QPoint newPosition = convertLatLonToSceneCoordinate(user->coordinates());
380         if (m_ownLocation->pos().toPoint() != newPosition) {
381             m_ownLocation->setPos(newPosition);
382         }
383
384         if (!m_ownLocation->isVisible())
385             m_ownLocation->show();
386     } else {
387         m_ownLocation->hide();
388     }
389
390     m_mapScene->spanItems(m_zoomLevel, m_sceneCoordinate, m_viewSize);
391 }
392
393 QGraphicsScene* MapEngine::scene()
394 {
395     qDebug() << __PRETTY_FUNCTION__;
396
397     return m_mapScene;
398 }
399
400 void MapEngine::scrollerStateChanged(QAbstractAnimation::State newState)
401 {
402     qDebug() << __PRETTY_FUNCTION__;
403
404     if (m_smoothScrollRunning
405         && newState != QAbstractAnimation::Running) {
406             m_smoothScrollRunning = false;
407
408             // don't disable auto centering if current animation was stopped by new update from GPS
409             if (!m_scrollStartedByGps)
410                 disableAutoCenteringIfRequired(m_sceneCoordinate);
411     }
412
413     m_scrollStartedByGps = false;
414 }
415
416 void MapEngine::scrollToPosition(QPoint scenePosition)
417 {
418     qDebug() << __PRETTY_FUNCTION__;
419
420     m_scroller->stop();
421     m_scroller->setEasingCurve(QEasingCurve::InOutQuart);
422     m_scroller->setDuration(SMOOTH_CENTERING_TIME_MS);
423     m_scroller->setStartValue(m_sceneCoordinate);
424     m_scroller->setEndValue(scenePosition);
425     m_smoothScrollRunning = true;
426     m_scroller->start();
427 }
428
429 void MapEngine::setAutoCentering(bool enabled)
430 {
431     qDebug() << __PRETTY_FUNCTION__;
432
433     m_autoCenteringEnabled = enabled;
434 }
435
436 void MapEngine::setCenterPosition(QPoint scenePosition)
437 {
438     qDebug() << __PRETTY_FUNCTION__;
439
440     // jump to opposite side of the world if world horizontal limit is exceeded
441     scenePosition.setX(normalize(scenePosition.x(), MAP_MIN_PIXEL_X, MAP_MAX_PIXEL_X));
442
443     // don't allow vertical scene coordinates go out of the map
444     scenePosition.setY(qBound(MAP_MIN_PIXEL_Y, scenePosition.y(), MAP_MAX_PIXEL_Y));
445
446     if (!m_smoothScrollRunning)
447         disableAutoCenteringIfRequired(scenePosition);
448
449     m_sceneCoordinate = scenePosition;
450     emit locationChanged(m_sceneCoordinate);
451
452     if (isCenterTileChanged(scenePosition)) {
453         getTiles(scenePosition);
454         m_mapScene->removeOutOfViewTiles(m_viewTilesGrid, m_zoomLevel);
455     }
456
457     m_mapScene->spanItems(m_zoomLevel, m_sceneCoordinate, m_viewSize);
458     emit newMapResolution(sceneResolution());
459 }
460
461 void MapEngine::setGPSEnabled(bool enabled)
462 {
463     qDebug() << __PRETTY_FUNCTION__;
464
465     m_gpsLocationItem->setEnabled(enabled);
466 }
467
468 void MapEngine::setZoomLevel(int newZoomLevel)
469 {
470     qDebug() << __PRETTY_FUNCTION__;
471
472     m_zoomLevel = newZoomLevel;
473     zoomed();
474 }
475
476 void MapEngine::setTilesGridSize(const QSize &viewSize)
477 {
478     qDebug() << __PRETTY_FUNCTION__;
479
480     // there must be scrolling reserve of at least half tile added to tile amount
481     // calculated from view size
482     const qreal SCROLLING_RESERVE = 0.5;
483
484     // converting scene tile to tile number does cause grid centering inaccuracy of one tile
485     const int CENTER_TILE_INACCURACY = 1;
486
487     int gridWidth = ceil(qreal(viewSize.width()) / TILE_SIZE_X + SCROLLING_RESERVE)
488                     + CENTER_TILE_INACCURACY + (GRID_PADDING * 2);
489     int gridHeight = ceil(qreal(viewSize.height()) / TILE_SIZE_Y + SCROLLING_RESERVE)
490                      + CENTER_TILE_INACCURACY + (GRID_PADDING * 2);
491
492     m_mapFetcher->setDownloadQueueSize(gridWidth * gridHeight);
493
494     m_tilesGridSize.setHeight(gridHeight);
495     m_tilesGridSize.setWidth(gridWidth);
496 }
497
498 int MapEngine::tileMaxIndex(int zoomLevel)
499 {
500     qDebug() << __PRETTY_FUNCTION__;
501
502     // subtract one because first tile index is zero
503     return tilesPerSide(zoomLevel) - 1;
504 }
505
506 QString MapEngine::tilePath(int zoomLevel, int x, int y)
507 {
508     qDebug() << __PRETTY_FUNCTION__;
509
510     QString tilePathString(QString::number(zoomLevel) + "/");
511     tilePathString.append(QString::number(x) + "/");
512     tilePathString.append(QString::number(y));
513
514     return tilePathString;
515 }
516
517 int MapEngine::tilesPerSide(int zoomLevel)
518 {
519     return (1 << zoomLevel);
520 }
521
522 void MapEngine::updateViewTilesSceneRect()
523 {
524     qDebug() << __PRETTY_FUNCTION__;
525
526     const QPoint ONE_TILE = QPoint(1, 1);
527     const QPoint ONE_PIXEL = QPoint(1, 1);
528
529     QPoint topLeft = convertTileNumberToSceneCoordinate(m_zoomLevel, m_viewTilesGrid.topLeft());
530     // one tile - one pixel is added because returned coordinates are pointing to upper left corner
531     // of the last tile.
532     QPoint bottomRight = convertTileNumberToSceneCoordinate(m_zoomLevel,
533                                                             m_viewTilesGrid.bottomRight()
534                                                              + ONE_TILE) - ONE_PIXEL;
535
536     m_mapScene->tilesSceneRectUpdated(QRect(topLeft, bottomRight));
537 }
538
539 void MapEngine::viewResized(const QSize &size)
540 {
541     qDebug() << __PRETTY_FUNCTION__;
542
543     m_viewSize = size;
544     setTilesGridSize(m_viewSize);
545
546     emit locationChanged(m_sceneCoordinate);
547     getTiles(m_sceneCoordinate);
548     m_mapScene->removeOutOfViewTiles(m_viewTilesGrid, m_zoomLevel);
549     m_mapScene->setSceneVerticalOverlap(m_viewSize.height(), m_zoomLevel);
550 }
551
552 void MapEngine::viewZoomFinished()
553 {
554     qDebug() << __PRETTY_FUNCTION__;
555
556     if (m_zoomedIn) {
557         m_zoomedIn = false;
558         m_mapScene->removeOutOfViewTiles(m_viewTilesGrid, m_zoomLevel);
559     }
560
561     if (m_zoomLevel == MAX_MAP_ZOOM_LEVEL)
562         emit maxZoomLevelReached();
563     else if (m_zoomLevel == MIN_VIEW_ZOOM_LEVEL)
564         emit minZoomLevelReached();
565 }
566
567 void MapEngine::zoomed()
568 {
569     emit zoomLevelChanged(m_zoomLevel);
570     m_mapScene->setTilesDrawingLevels(m_zoomLevel);
571     m_mapScene->setZoomLevel(m_zoomLevel);
572     getTiles(m_sceneCoordinate);
573     m_mapScene->setSceneVerticalOverlap(m_viewSize.height(), m_zoomLevel);
574     m_mapScene->spanItems(m_zoomLevel, m_sceneCoordinate, m_viewSize);
575     emit newMapResolution(sceneResolution());
576 }
577
578 void MapEngine::zoomIn()
579 {
580     qDebug() << __PRETTY_FUNCTION__;
581
582     if (m_zoomLevel < MAX_MAP_ZOOM_LEVEL) {
583         m_zoomLevel++;
584         m_zoomedIn = true;
585         zoomed();
586     }
587 }
588
589 void MapEngine::zoomOut()
590 {
591     qDebug() << __PRETTY_FUNCTION__;
592
593     if (m_zoomLevel > MIN_VIEW_ZOOM_LEVEL) {
594         m_zoomLevel--;
595         zoomed();
596     }
597 }