Added signals, distance counter, text label to panel and distance text.
[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)
135 {
136     const int MARGIN_HORIZONTAL = 50;
137     const int MARGIN_VERTICAL = 5;
138
139     // calculate the usable size of the view
140     int viewUsableHeight = m_viewSize.height() - 2 * MARGIN_VERTICAL;
141     int viewUsableWidth = m_viewSize.width() - 2 * MARGIN_HORIZONTAL;
142
143     // calculate how many levels must be zoomed out from the closest zoom level to get the rect
144     // fit inside the usable view area
145     int shift = 0;
146     while ((rect.height() > (viewUsableHeight * (1 << shift)))
147            || (rect.width() > (viewUsableWidth * (1 << shift))))
148         shift++;
149
150     scrollToPosition(SceneCoordinate(double(rect.center().x()), double(rect.center().y())));
151
152     int zoomLevel = qBound(OSM_MIN_ZOOM_LEVEL, OSM_MAX_ZOOM_LEVEL - shift, OSM_MAX_ZOOM_LEVEL);
153     setZoomLevel(zoomLevel);
154 }
155
156 GeoCoordinate MapEngine::centerGeoCoordinate()
157 {
158     qDebug() << __PRETTY_FUNCTION__;
159
160     return GeoCoordinate(m_sceneCoordinate);
161 }
162
163 void MapEngine::centerToCoordinates(GeoCoordinate coordinate)
164 {
165     qDebug() << __PRETTY_FUNCTION__;
166
167     scrollToPosition(SceneCoordinate(coordinate));
168 }
169
170 QPoint MapEngine::convertSceneCoordinateToTileNumber(int zoomLevel, SceneCoordinate coordinate)
171 {
172     qDebug() << __PRETTY_FUNCTION__;
173
174     int pow = 1 << (OSM_MAX_ZOOM_LEVEL - zoomLevel);
175     int x = static_cast<int>(coordinate.x() / (OSM_TILE_SIZE_X * pow));
176     int y = static_cast<int>(coordinate.y() / (OSM_TILE_SIZE_Y * pow));
177
178     return QPoint(x, y);
179 }
180
181 QRectF MapEngine::currentViewSceneRect() const
182 {
183     qDebug() << __PRETTY_FUNCTION__;
184
185     const QPoint ONE_PIXEL = QPoint(1, 1);
186
187     QGraphicsView *view = m_mapScene->views().at(0);
188     QPointF sceneTopLeft = view->mapToScene(0, 0);
189     QPoint viewBottomRight = QPoint(view->size().width(), view->size().height()) - ONE_PIXEL;
190     QPointF sceneBottomRight = view->mapToScene(viewBottomRight);
191
192     return QRectF(sceneTopLeft, sceneBottomRight);
193 }
194
195 void MapEngine::disableAutoCenteringIfRequired(SceneCoordinate coordinate)
196 {
197     if (isAutoCenteringEnabled()) {
198         int zoomFactor = (1 << (OSM_MAX_ZOOM_LEVEL - m_zoomLevel));
199
200         SceneCoordinate oldPixelValue(m_lastAutomaticPosition.x() / zoomFactor,
201                                       m_lastAutomaticPosition.y() / zoomFactor);
202
203         SceneCoordinate newPixelValue(coordinate.x() / zoomFactor,
204                                       coordinate.y() / zoomFactor);
205
206         if ((abs(oldPixelValue.x() - newPixelValue.x()) > AUTO_CENTERING_DISABLE_DISTANCE)
207             || (abs(oldPixelValue.y() - newPixelValue.y()) > AUTO_CENTERING_DISABLE_DISTANCE)) {
208
209             emit mapScrolledManually();
210         }
211     }
212 }
213
214 void MapEngine::friendsPositionsUpdated()
215 {
216     qDebug() << __PRETTY_FUNCTION__;
217
218     m_mapScene->spanItems(currentViewSceneRect());
219 }
220
221 void MapEngine::getTiles(SceneCoordinate coordinate)
222 {
223     qDebug() << __PRETTY_FUNCTION__;
224
225     m_viewTilesGrid = calculateTileGrid(coordinate);
226     updateViewTilesSceneRect();
227     m_mapScene->setTilesGrid(m_viewTilesGrid);
228
229     int topLeftX = m_viewTilesGrid.topLeft().x();
230     int topLeftY = m_viewTilesGrid.topLeft().y();
231     int bottomRightX = m_viewTilesGrid.bottomRight().x();
232     int bottomRightY = m_viewTilesGrid.bottomRight().y();
233
234     int tileMaxVal = MapTile::lastTileIndex(m_zoomLevel);
235
236     for (int x = topLeftX; x <= bottomRightX; ++x) {
237         for (int y = topLeftY; y <= bottomRightY; ++y) {
238
239             // map doesn't span in vertical direction, so y index must be inside the limits
240             if (y >= MAP_TILE_MIN_INDEX && y <= tileMaxVal) {
241                 if (!m_mapScene->tileInScene(MapTile::tilePath(m_zoomLevel, x, y)))
242                     emit fetchImage(m_zoomLevel, normalize(x, MAP_TILE_MIN_INDEX, tileMaxVal), y);
243             }
244         }
245     }
246 }
247
248 void MapEngine::gpsPositionUpdate(GeoCoordinate position, qreal accuracy)
249 {
250     qDebug() << __PRETTY_FUNCTION__;
251
252     m_gpsPosition = position;
253
254     // update GPS location item (but only if accuracy is a valid number)
255     if (!isnan(accuracy)) {
256         qreal resolution = MapScene::horizontalResolutionAtLatitude(position.latitude());
257         m_gpsLocationItem->updateItem(SceneCoordinate(position).toPointF(), accuracy, resolution);
258     }
259
260     m_mapScene->spanItems(currentViewSceneRect());
261
262     // do automatic centering (if enabled)
263     if (m_autoCenteringEnabled) {
264         m_lastAutomaticPosition = SceneCoordinate(position);
265         m_scrollStartedByGps = true;
266         scrollToPosition(m_lastAutomaticPosition);
267     }
268
269     updateDirectionIndicator();
270 }
271
272 void MapEngine::init()
273 {
274     qDebug() << __PRETTY_FUNCTION__;
275
276     QSettings settings(DIRECTORY_NAME, FILE_NAME);
277
278     // init can be only done if both values exists in the settings
279     if (settings.contains(MAP_LAST_POSITION) && settings.contains(MAP_LAST_ZOOMLEVEL)) {
280         QVariant zoomLevel = settings.value(MAP_LAST_ZOOMLEVEL);
281         QVariant location = settings.value(MAP_LAST_POSITION);
282
283         // also the init can be only done if we are able to convert variants into target data types
284         if (zoomLevel.canConvert<int>() && location.canConvert<GeoCoordinate>()) {
285             m_zoomLevel = zoomLevel.toInt();
286             m_sceneCoordinate = SceneCoordinate(location.value<GeoCoordinate>());
287         }
288     }
289
290     // emit zoom level and center coordinate so that all parts of the map system gets initialized
291     // NOTE: emit is also done even if we weren't able to read initial valuef from the settings
292     //       so that the default values set in the constructor are used
293     emit zoomLevelChanged(m_zoomLevel);
294     scrollToPosition(m_sceneCoordinate);
295 }
296
297 bool MapEngine::isAutoCenteringEnabled()
298 {
299     return m_autoCenteringEnabled;
300 }
301
302 bool MapEngine::isCenterTileChanged(SceneCoordinate coordinate)
303 {
304     qDebug() << __PRETTY_FUNCTION__;
305
306     QPoint centerTile = convertSceneCoordinateToTileNumber(m_zoomLevel, coordinate);
307     QPoint temp = m_centerTile;
308     m_centerTile = centerTile;
309
310     return (centerTile != temp);
311 }
312
313 void MapEngine::mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image)
314 {
315     qDebug() << __PRETTY_FUNCTION__;
316
317     // add normal tile inside the world
318     QPoint tileNumber(x, y);
319     m_mapScene->addTile(zoomLevel, tileNumber, image, m_zoomLevel);
320
321     // note: add 1 so odd width is rounded up and even is rounded down
322     int tilesGridWidthHalf = (m_viewTilesGrid.width() + 1) / 2;
323
324     // duplicate to east side? (don't need to duplicate over padding)
325     if (tileNumber.x() < (tilesGridWidthHalf - MAP_GRID_PADDING)) {
326         QPoint adjustedTileNumber(tileNumber.x() + MapTile::lastTileIndex(zoomLevel) + 1,
327                                   tileNumber.y());
328         m_mapScene->addTile(zoomLevel, adjustedTileNumber, image, m_zoomLevel);
329     }
330
331     // duplicate to west side? (don't need to duplicate over padding)
332     if (tileNumber.x() > (MapTile::lastTileIndex(zoomLevel)
333                           - tilesGridWidthHalf
334                           + MAP_GRID_PADDING)) {
335         QPoint adjustedTileNumber(tileNumber.x() - MapTile::lastTileIndex(zoomLevel) - 1,
336                                   tileNumber.y());
337         m_mapScene->addTile(zoomLevel, adjustedTileNumber, image, m_zoomLevel);
338     }
339 }
340
341 int MapEngine::normalize(int value, int min, int max)
342 {
343     qDebug() << __PRETTY_FUNCTION__;
344     Q_ASSERT_X(max >= min, "parameters", "max can't be smaller than min");
345
346     while (value < min)
347         value += max - min + 1;
348
349     while (value > max)
350         value -= max - min + 1;
351
352     return value;
353 }
354
355 void MapEngine::receiveOwnLocation(User *user)
356 {
357     qDebug() << __PRETTY_FUNCTION__;
358
359     if(user) {
360         m_ownLocation->setPos(SceneCoordinate(user->coordinates()).toPointF());
361         if (!m_ownLocation->isVisible())
362             m_ownLocation->show();
363     } else {
364         m_ownLocation->hide();
365     }
366
367     m_mapScene->spanItems(currentViewSceneRect());
368 }
369
370 QGraphicsScene* MapEngine::scene()
371 {
372     qDebug() << __PRETTY_FUNCTION__;
373
374     return m_mapScene;
375 }
376
377 void MapEngine::scrollerStateChanged(QAbstractAnimation::State newState)
378 {
379     qDebug() << __PRETTY_FUNCTION__;
380
381     if (m_smoothScrollRunning
382         && newState != QAbstractAnimation::Running) {
383             m_smoothScrollRunning = false;
384
385             // don't disable auto centering if current animation was stopped by new update from GPS
386             if (!m_scrollStartedByGps)
387                 disableAutoCenteringIfRequired(m_sceneCoordinate);
388     }
389
390     m_scrollStartedByGps = false;
391 }
392
393 void MapEngine::scrollToPosition(SceneCoordinate coordinate)
394 {
395     qDebug() << __PRETTY_FUNCTION__;
396
397     m_scroller->stop();
398     m_scroller->setEasingCurve(QEasingCurve::InOutQuart);
399     m_scroller->setDuration(SMOOTH_CENTERING_TIME_MS);
400     m_scroller->setStartValue(m_sceneCoordinate);
401     m_scroller->setEndValue(coordinate);
402     m_smoothScrollRunning = true;
403     m_scroller->start();
404 }
405
406 void MapEngine::setAutoCentering(bool enabled)
407 {
408     qDebug() << __PRETTY_FUNCTION__;
409
410     m_autoCenteringEnabled = enabled;
411
412     if (!m_autoCenteringEnabled && m_gpsLocationItem->isVisible())
413         updateDirectionIndicator();
414 }
415
416 void MapEngine::setCenterPosition(SceneCoordinate coordinate)
417 {
418     qDebug() << __PRETTY_FUNCTION__;
419
420     // jump to opposite side of the world if world horizontal limit is exceeded
421     coordinate.setX(normalize(coordinate.x(), OSM_MAP_MIN_PIXEL_X, OSM_MAP_MAX_PIXEL_X));
422
423     // don't allow vertical scene coordinates go out of the map
424     coordinate.setY(qBound(double(OSM_MAP_MIN_PIXEL_Y),
425                               coordinate.y(),
426                               double(OSM_MAP_MAX_PIXEL_Y)));
427
428     if (!m_smoothScrollRunning)
429         disableAutoCenteringIfRequired(coordinate);
430
431     m_sceneCoordinate = coordinate;
432     emit locationChanged(m_sceneCoordinate);
433
434     if (isCenterTileChanged(coordinate)) {
435         getTiles(coordinate);
436         m_mapScene->removeOutOfViewTiles(m_viewTilesGrid, m_zoomLevel);
437     }
438
439     m_mapScene->spanItems(currentViewSceneRect());
440     emit newMapResolution(viewResolution());
441
442     updateDirectionIndicator();
443 }
444
445 void MapEngine::setGPSEnabled(bool enabled)
446 {
447     qDebug() << __PRETTY_FUNCTION__;
448
449     m_gpsLocationItem->setEnabled(enabled);
450 }
451
452 void MapEngine::setRoute(Route &route)
453 {
454     qDebug() << __PRETTY_FUNCTION__;
455
456     m_route = route;
457
458     qDebug() << __PRETTY_FUNCTION__ << "from:" << m_route.startPointName();
459     qDebug() << __PRETTY_FUNCTION__ << "to:" << m_route.endPointName();
460     qDebug() << __PRETTY_FUNCTION__ << "distance:" << m_route.totalDistance();
461     qDebug() << __PRETTY_FUNCTION__ << "estimated time:" << m_route.totalTime();
462
463     foreach (GeoCoordinate point, m_route.geometryPoints())
464         qDebug() << __PRETTY_FUNCTION__ << "geometry point:" << point;
465
466     foreach (RouteSegment segment, m_route.segments()) {
467         qDebug() << __PRETTY_FUNCTION__ << "segment:" << segment.instruction();
468     }
469
470     // delete old route track (if exists)
471     if (m_mapRouteItem) {
472         m_mapScene->removeItem(m_mapRouteItem);
473         delete m_mapRouteItem;
474     }
475
476     // create new route track
477     m_mapRouteItem = new MapRouteItem(&m_route);
478     m_mapScene->addItem(m_mapRouteItem);
479
480     centerAndZoomTo(m_mapRouteItem->boundingRect().toRect());
481 }
482
483 void MapEngine::setZoomLevel(int newZoomLevel)
484 {
485     qDebug() << __PRETTY_FUNCTION__;
486
487     m_zoomLevel = newZoomLevel;
488     zoomed();
489 }
490
491 void MapEngine::setTilesGridSize(const QSize &viewSize)
492 {
493     qDebug() << __PRETTY_FUNCTION__;
494
495     // there must be scrolling reserve of at least half tile added to tile amount
496     // calculated from view size
497     const qreal SCROLLING_RESERVE = 0.5;
498
499     // converting scene tile to tile number does cause grid centering inaccuracy of one tile
500     const int CENTER_TILE_INACCURACY = 1;
501
502     int gridWidth = ceil(qreal(viewSize.width()) / OSM_TILE_SIZE_X + SCROLLING_RESERVE)
503                     + CENTER_TILE_INACCURACY + (MAP_GRID_PADDING * 2);
504     int gridHeight = ceil(qreal(viewSize.height()) / OSM_TILE_SIZE_Y + SCROLLING_RESERVE)
505                      + CENTER_TILE_INACCURACY + (MAP_GRID_PADDING * 2);
506
507     m_mapFetcher->setDownloadQueueSize(gridWidth * gridHeight);
508
509     m_tilesGridSize.setHeight(gridHeight);
510     m_tilesGridSize.setWidth(gridWidth);
511 }
512
513 void MapEngine::updateDirectionIndicator()
514 {
515     qDebug() << __PRETTY_FUNCTION__;
516
517     qreal distance = m_gpsPosition.distanceTo(m_sceneCoordinate);
518
519     qreal direction = m_sceneCoordinate.azimuthTo(SceneCoordinate(m_gpsPosition));
520
521     // direction indicator triangle should be drawn only if the gps location item is not currently
522     // visible on the view
523     bool drawDirectionIndicatorTriangle = true;
524     if (currentViewSceneRect().contains(m_gpsLocationItem->pos()))
525         drawDirectionIndicatorTriangle = false;
526
527     emit directionIndicatorValuesUpdate(direction, distance, drawDirectionIndicatorTriangle);
528 }
529
530 void MapEngine::updateViewTilesSceneRect()
531 {
532     qDebug() << __PRETTY_FUNCTION__;
533
534     const QPoint ONE_TILE = QPoint(1, 1);
535     const double ONE_PIXEL = 1;
536
537     SceneCoordinate topLeft = MapTile::convertTileNumberToSceneCoordinate(m_zoomLevel,
538                                                                         m_viewTilesGrid.topLeft());
539
540     // one tile - one pixel is added because returned coordinates are pointing to upper left corner
541     // of the last tile.
542     SceneCoordinate bottomRight
543             = MapTile::convertTileNumberToSceneCoordinate(m_zoomLevel,
544                                                           m_viewTilesGrid.bottomRight() + ONE_TILE);
545     bottomRight.setX(bottomRight.x() - ONE_PIXEL);
546     bottomRight.setY(bottomRight.y() - ONE_PIXEL);
547
548     m_mapScene->tilesSceneRectUpdated(QRect(topLeft.toPointF().toPoint(),
549                                             bottomRight.toPointF().toPoint()));
550 }
551
552 void MapEngine::viewResized(const QSize &size)
553 {
554     qDebug() << __PRETTY_FUNCTION__;
555
556     m_viewSize = size;
557     setTilesGridSize(m_viewSize);
558
559     emit locationChanged(m_sceneCoordinate);
560     getTiles(m_sceneCoordinate);
561     m_mapScene->removeOutOfViewTiles(m_viewTilesGrid, m_zoomLevel);
562     m_mapScene->setSceneVerticalOverlap(m_viewSize.height(), m_zoomLevel);
563 }
564
565 qreal MapEngine::viewResolution()
566 {
567     qDebug() << __PRETTY_FUNCTION__;
568
569     qreal scale = (1 << (OSM_MAX_ZOOM_LEVEL - m_zoomLevel));
570
571     return MapScene::horizontalResolutionAtLatitude(centerGeoCoordinate().latitude()) * scale;
572 }
573
574 void MapEngine::viewZoomFinished()
575 {
576     qDebug() << __PRETTY_FUNCTION__;
577
578     updateDirectionIndicator();
579
580     if (m_zoomedIn) {
581         m_zoomedIn = false;
582         m_mapScene->removeOutOfViewTiles(m_viewTilesGrid, m_zoomLevel);
583     }
584
585     if (m_zoomLevel == OSM_MAX_ZOOM_LEVEL)
586         emit maxZoomLevelReached();
587     else if (m_zoomLevel == MAP_VIEW_MIN_ZOOM_LEVEL)
588         emit minZoomLevelReached();
589 }
590
591 void MapEngine::zoomed()
592 {
593     emit zoomLevelChanged(m_zoomLevel);
594     m_mapScene->setTilesDrawingLevels(m_zoomLevel);
595     m_mapScene->setZoomLevel(m_zoomLevel);
596     getTiles(m_sceneCoordinate);
597     m_mapScene->setSceneVerticalOverlap(m_viewSize.height(), m_zoomLevel);
598     m_mapScene->spanItems(currentViewSceneRect());
599     emit newMapResolution(viewResolution());
600 }
601
602 void MapEngine::zoomIn()
603 {
604     qDebug() << __PRETTY_FUNCTION__;
605
606     if (m_zoomLevel < OSM_MAX_ZOOM_LEVEL) {
607         m_zoomLevel++;
608         m_zoomedIn = true;
609         zoomed();
610     }
611 }
612
613 void MapEngine::zoomOut()
614 {
615     qDebug() << __PRETTY_FUNCTION__;
616
617     if (m_zoomLevel > MAP_VIEW_MIN_ZOOM_LEVEL) {
618         m_zoomLevel--;
619         zoomed();
620     }
621 }