77a87f6400d761b40a07cadb65c4f0cae2f037d2
[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        Henri Lampela - henri.lampela@ixonos.com
10
11    Situare is free software; you can redistribute it and/or
12    modify it under the terms of the GNU General Public License
13    version 2 as published by the Free Software Foundation.
14
15    Situare is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with Situare; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
23    USA.
24 */
25
26 #include <QtAlgorithms>
27 #include <QDebug>
28 #include <QGraphicsView>
29 #include <QString>
30 #include <QStringList>
31 #include <QUrl>
32 #include <QHash>
33 #include <QHashIterator>
34 #include <QRect>
35
36 #include "common.h"
37 #include "coordinates/geocoordinate.h"
38 #include "frienditemshandler.h"
39 #include "gpslocationitem.h"
40 #include "mapcommon.h"
41 #include "mapfetcher.h"
42 #include "maprouteitem.h"
43 #include "mapscene.h"
44 #include "mapscroller.h"
45 #include "maptile.h"
46 #include "network/networkaccessmanager.h"
47 #include "ownlocationitem.h"
48 #include "user/user.h"
49
50 #include "mapengine.h"
51
52 const int SMOOTH_CENTERING_TIME_MS = 1000;
53
54 MapEngine::MapEngine(QObject *parent)
55     : QObject(parent),
56       m_autoCenteringEnabled(false),
57       m_scrollStartedByGps(false),
58       m_smoothScrollRunning(false),
59       m_zoomedIn(false),
60       m_zoomLevel(MAP_DEFAULT_ZOOM_LEVEL),
61       m_centerTile(QPoint(UNDEFINED, UNDEFINED)),
62       m_sceneCoordinate(SceneCoordinate(GeoCoordinate(MAP_DEFAULT_LATITUDE, MAP_DEFAULT_LONGITUDE))),
63       m_tilesGridSize(QSize(0, 0)),
64       m_viewSize(QSize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT)),
65       m_mapRouteItem(0)
66 {
67     qDebug() << __PRETTY_FUNCTION__;
68
69     m_mapScene = new MapScene(this);
70
71     m_mapFetcher = new MapFetcher(new NetworkAccessManager(this), this);
72     connect(this, SIGNAL(fetchImage(int, int, int)),
73             m_mapFetcher, SLOT(enqueueFetchMapImage(int, int, int)));
74     connect(m_mapFetcher, SIGNAL(mapImageReceived(int, int, int, QPixmap)),
75             this, SLOT(mapImageReceived(int, int, int, QPixmap)));
76     connect(m_mapFetcher, SIGNAL(error(int, int)),
77             this, SIGNAL(error(int, int)));
78
79     m_ownLocation = new OwnLocationItem();
80     m_ownLocation->hide(); // hide until first location info is received
81     m_mapScene->addItem(m_ownLocation);
82
83     m_gpsLocationItem = new GPSLocationItem();
84     m_mapScene->addItem(m_gpsLocationItem);
85
86     m_friendItemsHandler = new FriendItemsHandler(m_mapScene, this);
87     connect(this, SIGNAL(zoomLevelChanged(int)),
88             m_friendItemsHandler, SLOT(refactorFriendItems(int)));
89
90     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
91             m_friendItemsHandler, SLOT(friendListUpdated(QList<User*>&)));
92
93     connect(this, SIGNAL(friendImageReady(User*)),
94             m_friendItemsHandler, SLOT(friendImageReady(User*)));
95
96     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
97             this, SLOT(friendsPositionsUpdated()));
98
99     connect(m_friendItemsHandler, SIGNAL(locationItemClicked(QList<QString>)),
100             this, SIGNAL(locationItemClicked(QList<QString>)));
101
102     m_scroller = &MapScroller::getInstance();
103
104     connect(m_scroller, SIGNAL(coordinateUpdated(SceneCoordinate)),
105             this, SLOT(setCenterPosition(SceneCoordinate)));
106
107     connect(m_scroller, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)),
108             this, SLOT(scrollerStateChanged(QAbstractAnimation::State)));
109 }
110
111 MapEngine::~MapEngine()
112 {
113     qDebug() << __PRETTY_FUNCTION__;
114
115     QSettings settings(DIRECTORY_NAME, FILE_NAME);
116
117     settings.setValue(MAP_LAST_POSITION, QVariant::fromValue(centerGeoCoordinate()));
118     settings.setValue(MAP_LAST_ZOOMLEVEL, m_zoomLevel);
119 }
120
121 QRect MapEngine::calculateTileGrid(SceneCoordinate coordinate)
122 {
123     qDebug() << __PRETTY_FUNCTION__;
124
125     QPoint tileCoordinate = convertSceneCoordinateToTileNumber(m_zoomLevel, coordinate);
126
127     QPoint topLeft;
128     topLeft.setX(tileCoordinate.x() - (m_tilesGridSize.width() / 2));
129     topLeft.setY(tileCoordinate.y() - (m_tilesGridSize.height() / 2));
130
131     return QRect(topLeft, m_tilesGridSize);
132 }
133
134 void MapEngine::centerAndZoomTo(QRect rect, bool useMargins)
135 {
136     qDebug() << __PRETTY_FUNCTION__;
137
138     int marginHorizontal = 0;
139     int marginVertical = 0;
140
141     if (useMargins) {
142         marginHorizontal = 5;
143         marginVertical = 5;
144     }
145
146     // calculate the usable size of the view
147     int viewUsableHeight = m_viewSize.height() - 2 * marginVertical;
148     int viewUsableWidth = m_viewSize.width() - 2 * marginHorizontal;
149
150     // calculate how many levels must be zoomed out from the closest zoom level to get the rect
151     // fit inside the usable view area
152     int shift = 0;
153     while ((rect.height() > (viewUsableHeight * (1 << shift)))
154            || (rect.width() > (viewUsableWidth * (1 << shift)))) {
155
156         shift++;
157     }
158
159
160     scrollToPosition(SceneCoordinate(double(rect.center().x()), double(rect.center().y())));
161
162     int zoomLevel = qBound(OSM_MIN_ZOOM_LEVEL, OSM_MAX_ZOOM_LEVEL - shift, OSM_MAX_ZOOM_LEVEL);
163     setZoomLevel(zoomLevel);
164 }
165
166 GeoCoordinate MapEngine::centerGeoCoordinate()
167 {
168     qDebug() << __PRETTY_FUNCTION__;
169
170     return GeoCoordinate(m_sceneCoordinate);
171 }
172
173 void MapEngine::centerToCoordinates(GeoCoordinate coordinate)
174 {
175     qDebug() << __PRETTY_FUNCTION__;
176
177     scrollToPosition(SceneCoordinate(coordinate));
178 }
179
180 void MapEngine::clearRoute()
181 {
182     qDebug() << __PRETTY_FUNCTION__;
183
184     if (m_mapRouteItem) {
185         m_mapScene->removeItem(m_mapRouteItem);
186         delete m_mapRouteItem;
187         m_mapRouteItem = 0;
188     }
189 }
190
191 QPoint MapEngine::convertSceneCoordinateToTileNumber(int zoomLevel, SceneCoordinate coordinate)
192 {
193     qDebug() << __PRETTY_FUNCTION__;
194
195     int pow = 1 << (OSM_MAX_ZOOM_LEVEL - zoomLevel);
196     int x = static_cast<int>(coordinate.x() / (OSM_TILE_SIZE_X * pow));
197     int y = static_cast<int>(coordinate.y() / (OSM_TILE_SIZE_Y * pow));
198
199     return QPoint(x, y);
200 }
201
202 QRectF MapEngine::currentViewSceneRect() const
203 {
204     qDebug() << __PRETTY_FUNCTION__;
205
206     const QPoint ONE_PIXEL = QPoint(1, 1);
207
208     QGraphicsView *view = m_mapScene->views().first();
209     QPointF sceneTopLeft = view->mapToScene(0, 0);
210     QPoint viewBottomRight = QPoint(view->size().width(), view->size().height()) - ONE_PIXEL;
211     QPointF sceneBottomRight = view->mapToScene(viewBottomRight);
212
213     return QRectF(sceneTopLeft, sceneBottomRight);
214 }
215
216 void MapEngine::disableAutoCenteringIfRequired(SceneCoordinate coordinate)
217 {
218     if (isAutoCenteringEnabled()) {
219         int zoomFactor = (1 << (OSM_MAX_ZOOM_LEVEL - m_zoomLevel));
220
221         SceneCoordinate oldPixelValue(m_lastAutomaticPosition.x() / zoomFactor,
222                                       m_lastAutomaticPosition.y() / zoomFactor);
223
224         SceneCoordinate newPixelValue(coordinate.x() / zoomFactor,
225                                       coordinate.y() / zoomFactor);
226
227         if ((abs(oldPixelValue.x() - newPixelValue.x()) > AUTO_CENTERING_DISABLE_DISTANCE)
228             || (abs(oldPixelValue.y() - newPixelValue.y()) > AUTO_CENTERING_DISABLE_DISTANCE)) {
229
230             emit mapScrolledManually();
231         }
232     }
233 }
234
235 void MapEngine::friendsPositionsUpdated()
236 {
237     qDebug() << __PRETTY_FUNCTION__;
238
239     m_mapScene->spanItems(currentViewSceneRect());
240 }
241
242 void MapEngine::getTiles(SceneCoordinate coordinate)
243 {
244     qDebug() << __PRETTY_FUNCTION__;
245
246     m_viewTilesGrid = calculateTileGrid(coordinate);
247     updateViewTilesSceneRect();
248     m_mapScene->setTilesGrid(m_viewTilesGrid);
249
250     int topLeftX = m_viewTilesGrid.topLeft().x();
251     int topLeftY = m_viewTilesGrid.topLeft().y();
252     int bottomRightX = m_viewTilesGrid.bottomRight().x();
253     int bottomRightY = m_viewTilesGrid.bottomRight().y();
254
255     int tileMaxVal = MapTile::lastTileIndex(m_zoomLevel);
256
257     for (int x = topLeftX; x <= bottomRightX; ++x) {
258         for (int y = topLeftY; y <= bottomRightY; ++y) {
259
260             // map doesn't span in vertical direction, so y index must be inside the limits
261             if (y >= MAP_TILE_MIN_INDEX && y <= tileMaxVal) {
262                 if (!m_mapScene->tileInScene(MapTile::tilePath(m_zoomLevel, x, y)))
263                     emit fetchImage(m_zoomLevel, normalize(x, MAP_TILE_MIN_INDEX, tileMaxVal), y);
264             }
265         }
266     }
267 }
268
269 void MapEngine::gpsPositionUpdate(GeoCoordinate position, qreal accuracy)
270 {
271     qDebug() << __PRETTY_FUNCTION__;
272
273     m_gpsPosition = position;
274
275     // update GPS location item (but only if accuracy is a valid number)
276     if (!isnan(accuracy)) {
277         qreal resolution = MapScene::horizontalResolutionAtLatitude(position.latitude());
278         m_gpsLocationItem->updateItem(SceneCoordinate(position).toPointF(), accuracy, resolution);
279     }
280
281     m_mapScene->spanItems(currentViewSceneRect());
282
283     // do automatic centering (if enabled)
284     if (m_autoCenteringEnabled) {
285         m_lastAutomaticPosition = SceneCoordinate(position);
286         m_scrollStartedByGps = true;
287         scrollToPosition(m_lastAutomaticPosition);
288     }
289
290     updateDirectionIndicator();
291 }
292
293 void MapEngine::init()
294 {
295     qDebug() << __PRETTY_FUNCTION__;
296
297     QSettings settings(DIRECTORY_NAME, FILE_NAME);
298
299     // init can be only done if both values exists in the settings
300     if (settings.contains(MAP_LAST_POSITION) && settings.contains(MAP_LAST_ZOOMLEVEL)) {
301         QVariant zoomLevel = settings.value(MAP_LAST_ZOOMLEVEL);
302         QVariant location = settings.value(MAP_LAST_POSITION);
303
304         // also the init can be only done if we are able to convert variants into target data types
305         if (zoomLevel.canConvert<int>() && location.canConvert<GeoCoordinate>()) {
306             m_zoomLevel = zoomLevel.toInt();
307             m_sceneCoordinate = SceneCoordinate(location.value<GeoCoordinate>());
308         }
309     }
310
311     // emit zoom level and center coordinate so that all parts of the map system gets initialized
312     // NOTE: emit is also done even if we weren't able to read initial valuef from the settings
313     //       so that the default values set in the constructor are used
314     emit zoomLevelChanged(m_zoomLevel);
315     scrollToPosition(m_sceneCoordinate);
316 }
317
318 bool MapEngine::isAutoCenteringEnabled()
319 {
320     return m_autoCenteringEnabled;
321 }
322
323 bool MapEngine::isCenterTileChanged(SceneCoordinate coordinate)
324 {
325     qDebug() << __PRETTY_FUNCTION__;
326
327     QPoint centerTile = convertSceneCoordinateToTileNumber(m_zoomLevel, coordinate);
328     QPoint temp = m_centerTile;
329     m_centerTile = centerTile;
330
331     return (centerTile != temp);
332 }
333
334 void MapEngine::mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image)
335 {
336     qDebug() << __PRETTY_FUNCTION__;
337
338     // add normal tile inside the world
339     QPoint tileNumber(x, y);
340     m_mapScene->addTile(zoomLevel, tileNumber, image, m_zoomLevel);
341
342     // note: add 1 so odd width is rounded up and even is rounded down
343     int tilesGridWidthHalf = (m_viewTilesGrid.width() + 1) / 2;
344
345     // duplicate to east side? (don't need to duplicate over padding)
346     if (tileNumber.x() < (tilesGridWidthHalf - MAP_GRID_PADDING)) {
347         QPoint adjustedTileNumber(tileNumber.x() + MapTile::lastTileIndex(zoomLevel) + 1,
348                                   tileNumber.y());
349         m_mapScene->addTile(zoomLevel, adjustedTileNumber, image, m_zoomLevel);
350     }
351
352     // duplicate to west side? (don't need to duplicate over padding)
353     if (tileNumber.x() > (MapTile::lastTileIndex(zoomLevel)
354                           - tilesGridWidthHalf
355                           + MAP_GRID_PADDING)) {
356         QPoint adjustedTileNumber(tileNumber.x() - MapTile::lastTileIndex(zoomLevel) - 1,
357                                   tileNumber.y());
358         m_mapScene->addTile(zoomLevel, adjustedTileNumber, image, m_zoomLevel);
359     }
360 }
361
362 int MapEngine::normalize(int value, int min, int max)
363 {
364     qDebug() << __PRETTY_FUNCTION__;
365     Q_ASSERT_X(max >= min, "parameters", "max can't be smaller than min");
366
367     while (value < min)
368         value += max - min + 1;
369
370     while (value > max)
371         value -= max - min + 1;
372
373     return value;
374 }
375
376 void MapEngine::receiveOwnLocation(User *user)
377 {
378     qDebug() << __PRETTY_FUNCTION__;
379
380     if(user) {
381         m_ownLocation->setPos(SceneCoordinate(user->coordinates()).toPointF());
382         if (!m_ownLocation->isVisible())
383             m_ownLocation->show();
384     } else {
385         m_ownLocation->hide();
386     }
387
388     m_mapScene->spanItems(currentViewSceneRect());
389 }
390
391 QGraphicsScene* MapEngine::scene()
392 {
393     qDebug() << __PRETTY_FUNCTION__;
394
395     return m_mapScene;
396 }
397
398 void MapEngine::scrollerStateChanged(QAbstractAnimation::State newState)
399 {
400     qDebug() << __PRETTY_FUNCTION__;
401
402     if (m_smoothScrollRunning
403         && newState != QAbstractAnimation::Running) {
404             m_smoothScrollRunning = false;
405
406             // don't disable auto centering if current animation was stopped by new update from GPS
407             if (!m_scrollStartedByGps)
408                 disableAutoCenteringIfRequired(m_sceneCoordinate);
409     }
410
411     m_scrollStartedByGps = false;
412 }
413
414 void MapEngine::scrollToPosition(SceneCoordinate coordinate)
415 {
416     qDebug() << __PRETTY_FUNCTION__;
417
418     m_scroller->stop();
419     m_scroller->setEasingCurve(QEasingCurve::InOutQuart);
420     m_scroller->setDuration(SMOOTH_CENTERING_TIME_MS);
421     m_scroller->setStartValue(m_sceneCoordinate);
422     m_scroller->setEndValue(coordinate);
423     m_smoothScrollRunning = true;
424     m_scroller->start();
425 }
426
427 void MapEngine::setAutoCentering(bool enabled)
428 {
429     qDebug() << __PRETTY_FUNCTION__;
430
431     m_autoCenteringEnabled = enabled;
432
433     if (!m_autoCenteringEnabled && m_gpsLocationItem->isVisible())
434         updateDirectionIndicator();
435 }
436
437 void MapEngine::setCenterPosition(SceneCoordinate coordinate)
438 {
439     qDebug() << __PRETTY_FUNCTION__;
440
441     // jump to opposite side of the world if world horizontal limit is exceeded
442     coordinate.setX(normalize(coordinate.x(), OSM_MAP_MIN_PIXEL_X, OSM_MAP_MAX_PIXEL_X));
443
444     // don't allow vertical scene coordinates go out of the map
445     coordinate.setY(qBound(double(OSM_MAP_MIN_PIXEL_Y),
446                               coordinate.y(),
447                               double(OSM_MAP_MAX_PIXEL_Y)));
448
449     if (!m_smoothScrollRunning)
450         disableAutoCenteringIfRequired(coordinate);
451
452     m_sceneCoordinate = coordinate;
453     emit locationChanged(m_sceneCoordinate);
454
455     if (isCenterTileChanged(coordinate)) {
456         getTiles(coordinate);
457         m_mapScene->removeOutOfViewTiles(m_viewTilesGrid, m_zoomLevel);
458     }
459
460     m_mapScene->spanItems(currentViewSceneRect());
461     emit newMapResolution(viewResolution());
462
463     updateDirectionIndicator();
464 }
465
466 void MapEngine::setGPSEnabled(bool enabled)
467 {
468     qDebug() << __PRETTY_FUNCTION__;
469
470     m_gpsLocationItem->setEnabled(enabled);
471 }
472
473 void MapEngine::setRoute(Route &route)
474 {
475     qDebug() << __PRETTY_FUNCTION__;
476
477     clearRoute();
478
479     m_mapRouteItem = new MapRouteItem(&route);
480     m_mapScene->addItem(m_mapRouteItem);
481
482     centerAndZoomTo(m_mapRouteItem->boundingRect().toRect());
483 }
484
485 void MapEngine::setZoomLevel(int newZoomLevel)
486 {
487     qDebug() << __PRETTY_FUNCTION__;
488
489     m_zoomLevel = newZoomLevel;
490     zoomed();
491 }
492
493 void MapEngine::setTilesGridSize(const QSize &viewSize)
494 {
495     qDebug() << __PRETTY_FUNCTION__;
496
497     // there must be scrolling reserve of at least half tile added to tile amount
498     // calculated from view size
499     const qreal SCROLLING_RESERVE = 0.5;
500
501     // converting scene tile to tile number does cause grid centering inaccuracy of one tile
502     const int CENTER_TILE_INACCURACY = 1;
503
504     int gridWidth = ceil(qreal(viewSize.width()) / OSM_TILE_SIZE_X + SCROLLING_RESERVE)
505                     + CENTER_TILE_INACCURACY + (MAP_GRID_PADDING * 2);
506     int gridHeight = ceil(qreal(viewSize.height()) / OSM_TILE_SIZE_Y + SCROLLING_RESERVE)
507                      + CENTER_TILE_INACCURACY + (MAP_GRID_PADDING * 2);
508
509     m_mapFetcher->setDownloadQueueSize(gridWidth * gridHeight);
510
511     m_tilesGridSize.setHeight(gridHeight);
512     m_tilesGridSize.setWidth(gridWidth);
513 }
514
515 void MapEngine::showMapArea(const GeoCoordinate &swBound, const GeoCoordinate &neBound)
516 {
517     qDebug() << __PRETTY_FUNCTION__;
518
519     QRect area;
520     area.setTopRight(SceneCoordinate(neBound).toPointF().toPoint());
521     area.setBottomLeft(SceneCoordinate(swBound).toPointF().toPoint());
522
523     centerAndZoomTo(area, false);
524 }
525
526 void MapEngine::updateDirectionIndicator()
527 {
528     qDebug() << __PRETTY_FUNCTION__;
529
530     qreal distance = m_gpsPosition.distanceTo(m_sceneCoordinate);
531
532     qreal direction = m_sceneCoordinate.azimuthTo(SceneCoordinate(m_gpsPosition));
533
534     // direction indicator triangle should be drawn only if the gps location item is not currently
535     // visible on the view
536     bool drawDirectionIndicatorTriangle = true;
537     if (currentViewSceneRect().contains(m_gpsLocationItem->pos()))
538         drawDirectionIndicatorTriangle = false;
539
540     emit directionIndicatorValuesUpdate(direction, distance, drawDirectionIndicatorTriangle);
541 }
542
543 void MapEngine::updateViewTilesSceneRect()
544 {
545     qDebug() << __PRETTY_FUNCTION__;
546
547     const QPoint ONE_TILE = QPoint(1, 1);
548     const double ONE_PIXEL = 1;
549
550     SceneCoordinate topLeft = MapTile::convertTileNumberToSceneCoordinate(m_zoomLevel,
551                                                                         m_viewTilesGrid.topLeft());
552
553     // one tile - one pixel is added because returned coordinates are pointing to upper left corner
554     // of the last tile.
555     SceneCoordinate bottomRight
556             = MapTile::convertTileNumberToSceneCoordinate(m_zoomLevel,
557                                                           m_viewTilesGrid.bottomRight() + ONE_TILE);
558     bottomRight.setX(bottomRight.x() - ONE_PIXEL);
559     bottomRight.setY(bottomRight.y() - ONE_PIXEL);
560
561     m_mapScene->tilesSceneRectUpdated(QRect(topLeft.toPointF().toPoint(),
562                                             bottomRight.toPointF().toPoint()));
563 }
564
565 void MapEngine::viewResized(const QSize &size)
566 {
567     qDebug() << __PRETTY_FUNCTION__;
568
569     m_viewSize = size;
570     setTilesGridSize(m_viewSize);
571
572     emit locationChanged(m_sceneCoordinate);
573     getTiles(m_sceneCoordinate);
574     m_mapScene->removeOutOfViewTiles(m_viewTilesGrid, m_zoomLevel);
575     m_mapScene->setSceneVerticalOverlap(m_viewSize.height(), m_zoomLevel);
576 }
577
578 qreal MapEngine::viewResolution()
579 {
580     qDebug() << __PRETTY_FUNCTION__;
581
582     qreal scale = (1 << (OSM_MAX_ZOOM_LEVEL - m_zoomLevel));
583
584     return MapScene::horizontalResolutionAtLatitude(centerGeoCoordinate().latitude()) * scale;
585 }
586
587 void MapEngine::viewZoomFinished()
588 {
589     qDebug() << __PRETTY_FUNCTION__;
590
591     updateDirectionIndicator();
592
593     if (m_zoomedIn) {
594         m_zoomedIn = false;
595         m_mapScene->removeOutOfViewTiles(m_viewTilesGrid, m_zoomLevel);
596     }
597
598     if (m_zoomLevel == OSM_MAX_ZOOM_LEVEL)
599         emit maxZoomLevelReached();
600     else if (m_zoomLevel == MAP_VIEW_MIN_ZOOM_LEVEL)
601         emit minZoomLevelReached();
602 }
603
604 void MapEngine::zoomed()
605 {
606     emit zoomLevelChanged(m_zoomLevel);
607     m_mapScene->setTilesDrawingLevels(m_zoomLevel);
608     m_mapScene->setZoomLevel(m_zoomLevel);
609     getTiles(m_sceneCoordinate);
610     m_mapScene->setSceneVerticalOverlap(m_viewSize.height(), m_zoomLevel);
611     m_mapScene->spanItems(currentViewSceneRect());
612     emit newMapResolution(viewResolution());
613 }
614
615 void MapEngine::zoomIn()
616 {
617     qDebug() << __PRETTY_FUNCTION__;
618
619     if (m_zoomLevel < OSM_MAX_ZOOM_LEVEL) {
620         m_zoomLevel++;
621         m_zoomedIn = true;
622         zoomed();
623     }
624 }
625
626 void MapEngine::zoomOut()
627 {
628     qDebug() << __PRETTY_FUNCTION__;
629
630     if (m_zoomLevel > MAP_VIEW_MIN_ZOOM_LEVEL) {
631         m_zoomLevel--;
632         zoomed();
633     }
634 }