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