Merge branch 'crosshair2'
[situare] / src / map / mapengine.cpp
index 5e6998b..098874b 100644 (file)
@@ -374,7 +374,42 @@ void MapEngine::setAutoCentering(bool enabled)
     m_autoCenteringEnabled = enabled;
 }
 
+
 void MapEngine::gpsEnabled(bool enabled)
 {
     m_gpsLocationItem->setEnabled(enabled);
 }
+
+QPointF MapEngine::convertSceneCoordinateToLatLon(int zoomLevel, QPoint sceneCoordinate)
+{   
+    qDebug() << __PRETTY_FUNCTION__;
+
+    double tileFactor = 1 << (MAX_MAP_ZOOM_LEVEL - zoomLevel);
+    double xFactor = (sceneCoordinate.x() / (TILE_SIZE_X*tileFactor));
+    double yFactor = (sceneCoordinate.y() / (TILE_SIZE_Y*tileFactor));
+
+    tileFactor = 1 << zoomLevel;
+    double longitude = xFactor / tileFactor * 360.0 - 180;
+
+    double n = M_PI - 2.0 * M_PI * yFactor / tileFactor;
+    double latitude = 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n)));
+
+    return QPointF(longitude, latitude);
+}
+
+void MapEngine::ownLocation()
+{
+     qDebug() << __PRETTY_FUNCTION__;    
+
+    emit requestToGetViewPortContents();
+    QPointF ownLatitudeLongitudeLocation =
+            convertSceneCoordinateToLatLon(m_zoomLevel, m_viewArea.center());    
+    emit ownLocation(ownLatitudeLongitudeLocation);
+}
+
+void MapEngine::receiveViewSceneRect(QRect viewSceneRect)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_viewArea = viewSceneRect;
+}