MapEngine::MapEngine(QObject *parent)
: QObject(parent)
+ , m_autoCenteringEnabled(false)
, m_centerTile(QPoint(UNDEFINED, UNDEFINED))
+ , m_lastManualPosition(QPoint(0, 0))
, m_viewSize(QSize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT))
, m_zoomedIn(false)
, m_zoomLevel(DEFAULT_ZOOM_LEVEL)
+
{
qDebug() << __PRETTY_FUNCTION__;
{
qDebug() << __PRETTY_FUNCTION__;
- setLocation(convertLatLonToSceneCoordinate(latLonCoordinate));
+ QPoint sceneCoordinate = convertLatLonToSceneCoordinate(latLonCoordinate);
+
+ m_lastManualPosition = sceneCoordinate;
+
+ setLocation(sceneCoordinate);
}
void MapEngine::mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image)
{
qDebug() << __PRETTY_FUNCTION__;
+ if (disableAutoCentering(sceneCoordinate))
+ emit mapScrolled();
+
m_sceneCoordinate = sceneCoordinate;
emit locationChanged(m_sceneCoordinate);
if (!m_ownLocation->isVisible())
m_ownLocation->show();
}
+
+bool MapEngine::disableAutoCentering(QPoint sceneCoordinate)
+{
+ if (isAutoCenteringEnabled()) {
+ int zoomFactor = (1 << (MAX_MAP_ZOOM_LEVEL - m_zoomLevel));
+
+ QPoint oldPixelValue = QPoint(m_lastManualPosition.x() / zoomFactor,
+ m_lastManualPosition.y() / zoomFactor);
+
+ QPoint newPixelValue = QPoint(sceneCoordinate.x() / zoomFactor,
+ sceneCoordinate.y() / zoomFactor);
+
+ if ((abs(oldPixelValue.x() - newPixelValue.x()) > AUTO_CENTERING_DISABLE_DISTANCE) ||
+ (abs(oldPixelValue.y() - newPixelValue.y()) > AUTO_CENTERING_DISABLE_DISTANCE))
+ return true;
+ }
+
+ return false;
+}
+
+bool MapEngine::isAutoCenteringEnabled()
+{
+ return m_autoCenteringEnabled;
+}
+
+void MapEngine::setAutoCentering(bool enabled)
+{
+ m_autoCenteringEnabled = enabled;
+}