diff --git a/ground/src/experimental/OPMapWidget/internals/core.cpp b/ground/src/experimental/OPMapWidget/internals/core.cpp index 30c26c23a..b4594bbd0 100644 --- a/ground/src/experimental/OPMapWidget/internals/core.cpp +++ b/ground/src/experimental/OPMapWidget/internals/core.cpp @@ -27,611 +27,617 @@ */ #include "core.h" +#ifdef DEBUG_CORE qlonglong internals::Core::debugcounter=0; +#endif using namespace projections; - + namespace internals { -Core::Core():currentPosition(0,0),currentPositionPixel(0,0),LastLocationInBounds(-1,-1),sizeOfMapArea(0,0) - ,minOfTiles(0,0),maxOfTiles(0,0),isDragging(false),started(false),MouseWheelZooming(false),TooltipTextPadding(10,10),zoom(0),loaderLimit(5) -{ - mousewheelzoomtype=MouseWheelZoomType::MousePositionAndCenter; - SetProjection(new MercatorProjection()); - this->setAutoDelete(false); - renderOffset=Point(0,0); - dragPoint=Point(0,0); - CanDragMap=true; -} -void Core::run() -{ - qlonglong debug; - Mdebug.lock(); - debug=++debugcounter; - Mdebug.unlock(); - -#ifdef DEBUG_CORE - qDebug()<<"core:run"<<" ID="< 0) - { - task = tileLoadQueue.dequeue(); - { - last = tileLoadQueue.count() == 0; -#ifdef DEBUG_CORE - qDebug()<<"TileLoadQueue: " << tileLoadQueue.count()<<" Point:"<GetPos().ToString()<<" now has "<Overlays.count()<<" overlays"<<" ID="<RetryLoadTile > 0) - { -#ifdef DEBUG_CORE - qDebug()<<"ProcessLoadTask: " << task.ToString()<< " -> empty tile, retry " << retry<<" ID="<RetryLoadTile); - } - - if(t->Overlays.count() > 0) - { - Matrix.SetTileAt(task.Pos,t); - emit OnNeedInvalidation(); -#ifdef DEBUG_CORE - qDebug()<<"Core::run add tile "<GetPos().ToString()<<" to matrix index "<Overlays.count()<<" ID="<kiberCacheLock.lockForWrite(); - OPMaps::Instance()->TilesInMemory.RemoveMemoryOverload(); - OPMaps::Instance()->kiberCacheLock.unlock(); - - MtileDrawingList.lock(); - { - Matrix.ClearPointsNotIn(tileDrawingList); - } - MtileDrawingList.unlock(); - - - emit OnTileLoadComplete(); - - - emit OnNeedInvalidation(); - - } - } - - - - } - qDebug()<<"loaderLimit release:"+loaderLimit.available()<<" ID="<GetTileMatrixMinXY(value); - maxOfTiles=Projection()->GetTileMatrixMaxXY(value); - currentPositionPixel=Projection()->FromLatLngToPixel(currentPosition,value); - if(started) - { - MtileLoadQueue.lock(); - tileLoadQueue.clear(); - MtileLoadQueue.unlock(); - Matrix.Clear(); - GoToCurrentPositionOnZoom(); - UpdateBounds(); - emit OnMapDrag(); - emit OnMapZoomChanged(); - emit OnNeedInvalidation(); - } - } -} - -void Core::SetCurrentPosition(const PointLatLng &value) -{ - if(!IsDragging()) - { - currentPosition = value; - SetCurrentPositionGPixel(Projection()->FromLatLngToPixel(value, Zoom())); - - if(started) - { - GoToCurrentPosition(); - emit OnCurrentPositionChanged(currentPosition); - } - } - else - { - currentPosition = value; - SetCurrentPositionGPixel(Projection()->FromLatLngToPixel(value, Zoom())); - - if(started) - { - emit OnCurrentPositionChanged(currentPosition); - } - } -} -void Core::SetMapType(const MapType::Types &value) -{ - - if(value != GetMapType()) - { - mapType = value; - - switch(value) - { - - - case MapType::ArcGIS_Map: - case MapType::ArcGIS_Satellite: - case MapType::ArcGIS_ShadedRelief: - case MapType::ArcGIS_Terrain: - { - if(Projection()->Type()!="PlateCarreeProjection") - { - SetProjection(new PlateCarreeProjection()); - } - } - break; - - case MapType::ArcGIS_MapsLT_Map_Hybrid: - case MapType::ArcGIS_MapsLT_Map_Labels: - case MapType::ArcGIS_MapsLT_Map: - case MapType::ArcGIS_MapsLT_OrtoFoto: - { - if(Projection()->Type()!="LKS94Projection") - { - SetProjection(new LKS94Projection()); - } - } - break; - - case MapType::PergoTurkeyMap: - { - if(Projection()->Type()!="PlateCarreeProjectionPergo") - { - SetProjection(new PlateCarreeProjectionPergo()); - } - } - break; - - case MapType::YandexMapRu: - { - if(Projection()->Type()!="MercatorProjectionYandex") - { - SetProjection(new MercatorProjectionYandex()); - } - } - break; - - default: - { - if(Projection()->Type()!="MercatorProjection") - { - SetProjection(new MercatorProjection()); - } - } - break; - } - - minOfTiles = Projection()->GetTileMatrixMinXY(Zoom()); - maxOfTiles = Projection()->GetTileMatrixMaxXY(Zoom()); - SetCurrentPositionGPixel(Projection()->FromLatLngToPixel(CurrentPosition(), Zoom())); - - if(started) - { - CancelAsyncTasks(); - OnMapSizeChanged(Width, Height); - GoToCurrentPosition(); - ReloadMap(); - emit OnMapTypeChanged(value); - - } - } - -} -void Core::StartSystem() -{ - if(!started) - { - started = true; - - ReloadMap(); - GoToCurrentPosition(); - } -} - -void Core::UpdateCenterTileXYLocation() -{ - PointLatLng center = FromLocalToLatLng(Width/2, Height/2); - Point centerPixel = Projection()->FromLatLngToPixel(center, Zoom()); - centerTileXYLocation = Projection()->FromPixelToTileXY(centerPixel); -} - -void Core::OnMapSizeChanged(int const& width, int const& height) -{ - Width = width; - Height = height; - - sizeOfMapArea.SetWidth(1 + (Width/Projection()->TileSize().Width())/2); - sizeOfMapArea.SetHeight(1 + (Height/Projection()->TileSize().Height())/2); - - UpdateCenterTileXYLocation(); - - if(started) - { - UpdateBounds(); - - emit OnCurrentPositionChanged(currentPosition); - } -} -void Core::OnMapClose() -{ - // if(waitOnEmptyTasks != null) - // { - // try - // { - // waitOnEmptyTasks.Set(); - // waitOnEmptyTasks.Close(); - // } - // catch - // { - // } - // } - - CancelAsyncTasks(); -} -GeoCoderStatusCode::Types Core::SetCurrentPositionByKeywords(QString const& keys) -{ - GeoCoderStatusCode::Types status = GeoCoderStatusCode::Unknow; - PointLatLng pos = OPMaps::Instance()->GetLatLngFromGeodecoder(keys, status); - if(pos.IsEmpty() && status == GeoCoderStatusCode::G_GEO_SUCCESS) - { - SetCurrentPosition(pos); - } - - return status; -} -RectLatLng Core::CurrentViewArea() -{ - PointLatLng p = Projection()->FromPixelToLatLng(-renderOffset.X(), -renderOffset.Y(), Zoom()); - double rlng = Projection()->FromPixelToLatLng(-renderOffset.X() + Width, -renderOffset.Y(), Zoom()).Lng(); - double blat = Projection()->FromPixelToLatLng(-renderOffset.X(), -renderOffset.Y() + Height, Zoom()).Lat(); - return RectLatLng::FromLTRB(p.Lng(), p.Lat(), rlng, blat); - -} -PointLatLng Core::FromLocalToLatLng(int const& x, int const& y) -{ - return Projection()->FromPixelToLatLng(Point(x - renderOffset.X(), y - renderOffset.Y()), Zoom()); -} - - -Point Core::FromLatLngToLocal(PointLatLng const& latlng) -{ - Point pLocal = Projection()->FromLatLngToPixel(latlng, Zoom()); - pLocal.Offset(renderOffset); - return pLocal; -} -int Core::GetMaxZoomToFitRect(RectLatLng const& rect) -{ - int zoom = 0; - - for(int i = 1; i <= OPMaps::Instance()->MaxZoom; i++) - { - Point p1 = Projection()->FromLatLngToPixel(rect.LocationTopLeft(), i); - Point p2 = Projection()->FromLatLngToPixel(rect.Bottom(), rect.Right(), i); - - if(((p2.X() - p1.X()) <= Width+10) && (p2.Y() - p1.Y()) <= Height+10) - { - zoom = i; - } - else - { - break; - } - } - - return zoom; -} -void Core::BeginDrag(Point const& pt) -{ - dragPoint.SetX(pt.X() - renderOffset.X()); - dragPoint.SetY(pt.Y() - renderOffset.Y()); - isDragging = true; -} -void Core::EndDrag() -{ - isDragging = false; - emit OnNeedInvalidation(); - -} -void Core::ReloadMap() -{ - if(started) - { -#ifdef DEBUG_CORE - qDebug()<<"------------------"; -#endif //DEBUG_CORE + LoadTask task; MtileLoadQueue.lock(); { - tileLoadQueue.clear(); + if(tileLoadQueue.count() > 0) + { + task = tileLoadQueue.dequeue(); + { + last = tileLoadQueue.count() == 0; +#ifdef DEBUG_CORE + qDebug()<<"TileLoadQueue: " << tileLoadQueue.count()<<" Point:"<GetPos().ToString()<<" now has "<Overlays.count()<<" overlays"<<" ID="<RetryLoadTile > 0) + { +#ifdef DEBUG_CORE + qDebug()<<"ProcessLoadTask: " << task.ToString()<< " -> empty tile, retry " << retry<<" ID="<RetryLoadTile); + } + + if(t->Overlays.count() > 0) + { + Matrix.SetTileAt(task.Pos,t); + emit OnNeedInvalidation(); +#ifdef DEBUG_CORE + qDebug()<<"Core::run add tile "<GetPos().ToString()<<" to matrix index "<Overlays.count()<<" ID="<kiberCacheLock.lockForWrite(); + OPMaps::Instance()->TilesInMemory.RemoveMemoryOverload(); + OPMaps::Instance()->kiberCacheLock.unlock(); + + MtileDrawingList.lock(); + { + Matrix.ClearPointsNotIn(tileDrawingList); + } + MtileDrawingList.unlock(); + + + emit OnTileLoadComplete(); + + + emit OnNeedInvalidation(); + + } + } + + + + } +#ifdef DEBUG_CORE + qDebug()<<"loaderLimit release:"+loaderLimit.available()<<" ID="<GetTileMatrixMinXY(value); + maxOfTiles=Projection()->GetTileMatrixMaxXY(value); + currentPositionPixel=Projection()->FromLatLngToPixel(currentPosition,value); + if(started) + { + MtileLoadQueue.lock(); + tileLoadQueue.clear(); + MtileLoadQueue.unlock(); + Matrix.Clear(); + GoToCurrentPositionOnZoom(); + UpdateBounds(); + emit OnMapDrag(); + emit OnMapZoomChanged(); + emit OnNeedInvalidation(); + } + } + } + + void Core::SetCurrentPosition(const PointLatLng &value) + { + if(!IsDragging()) + { + currentPosition = value; + SetCurrentPositionGPixel(Projection()->FromLatLngToPixel(value, Zoom())); + + if(started) + { + GoToCurrentPosition(); + emit OnCurrentPositionChanged(currentPosition); + } + } + else + { + currentPosition = value; + SetCurrentPositionGPixel(Projection()->FromLatLngToPixel(value, Zoom())); + + if(started) + { + emit OnCurrentPositionChanged(currentPosition); + } + } + } + void Core::SetMapType(const MapType::Types &value) + { + + if(value != GetMapType()) + { + mapType = value; + + switch(value) + { + + + case MapType::ArcGIS_Map: + case MapType::ArcGIS_Satellite: + case MapType::ArcGIS_ShadedRelief: + case MapType::ArcGIS_Terrain: + { + if(Projection()->Type()!="PlateCarreeProjection") + { + SetProjection(new PlateCarreeProjection()); + } + } + break; + + case MapType::ArcGIS_MapsLT_Map_Hybrid: + case MapType::ArcGIS_MapsLT_Map_Labels: + case MapType::ArcGIS_MapsLT_Map: + case MapType::ArcGIS_MapsLT_OrtoFoto: + { + if(Projection()->Type()!="LKS94Projection") + { + SetProjection(new LKS94Projection()); + } + } + break; + + case MapType::PergoTurkeyMap: + { + if(Projection()->Type()!="PlateCarreeProjectionPergo") + { + SetProjection(new PlateCarreeProjectionPergo()); + } + } + break; + + case MapType::YandexMapRu: + { + if(Projection()->Type()!="MercatorProjectionYandex") + { + SetProjection(new MercatorProjectionYandex()); + } + } + break; + + default: + { + if(Projection()->Type()!="MercatorProjection") + { + SetProjection(new MercatorProjection()); + } + } + break; + } + + minOfTiles = Projection()->GetTileMatrixMinXY(Zoom()); + maxOfTiles = Projection()->GetTileMatrixMaxXY(Zoom()); + SetCurrentPositionGPixel(Projection()->FromLatLngToPixel(CurrentPosition(), Zoom())); + + if(started) + { + CancelAsyncTasks(); + OnMapSizeChanged(Width, Height); + GoToCurrentPosition(); + ReloadMap(); + emit OnMapTypeChanged(value); + + } + } + + } + void Core::StartSystem() + { + if(!started) + { + started = true; + + ReloadMap(); + GoToCurrentPosition(); + } + } + + void Core::UpdateCenterTileXYLocation() + { + PointLatLng center = FromLocalToLatLng(Width/2, Height/2); + Point centerPixel = Projection()->FromLatLngToPixel(center, Zoom()); + centerTileXYLocation = Projection()->FromPixelToTileXY(centerPixel); + } + + void Core::OnMapSizeChanged(int const& width, int const& height) + { + Width = width; + Height = height; + + sizeOfMapArea.SetWidth(1 + (Width/Projection()->TileSize().Width())/2); + sizeOfMapArea.SetHeight(1 + (Height/Projection()->TileSize().Height())/2); + + UpdateCenterTileXYLocation(); + + if(started) + { + UpdateBounds(); + + emit OnCurrentPositionChanged(currentPosition); + } + } + void Core::OnMapClose() + { + // if(waitOnEmptyTasks != null) + // { + // try + // { + // waitOnEmptyTasks.Set(); + // waitOnEmptyTasks.Close(); + // } + // catch + // { + // } + // } + + CancelAsyncTasks(); + } + GeoCoderStatusCode::Types Core::SetCurrentPositionByKeywords(QString const& keys) + { + GeoCoderStatusCode::Types status = GeoCoderStatusCode::Unknow; + PointLatLng pos = OPMaps::Instance()->GetLatLngFromGeodecoder(keys, status); + if(pos.IsEmpty() && status == GeoCoderStatusCode::G_GEO_SUCCESS) + { + SetCurrentPosition(pos); + } + + return status; + } + RectLatLng Core::CurrentViewArea() + { + PointLatLng p = Projection()->FromPixelToLatLng(-renderOffset.X(), -renderOffset.Y(), Zoom()); + double rlng = Projection()->FromPixelToLatLng(-renderOffset.X() + Width, -renderOffset.Y(), Zoom()).Lng(); + double blat = Projection()->FromPixelToLatLng(-renderOffset.X(), -renderOffset.Y() + Height, Zoom()).Lat(); + return RectLatLng::FromLTRB(p.Lng(), p.Lat(), rlng, blat); + + } + PointLatLng Core::FromLocalToLatLng(int const& x, int const& y) + { + return Projection()->FromPixelToLatLng(Point(x - renderOffset.X(), y - renderOffset.Y()), Zoom()); + } + + + Point Core::FromLatLngToLocal(PointLatLng const& latlng) + { + Point pLocal = Projection()->FromLatLngToPixel(latlng, Zoom()); + pLocal.Offset(renderOffset); + return pLocal; + } + int Core::GetMaxZoomToFitRect(RectLatLng const& rect) + { + int zoom = 0; + + for(int i = 1; i <= OPMaps::Instance()->MaxZoom; i++) + { + Point p1 = Projection()->FromLatLngToPixel(rect.LocationTopLeft(), i); + Point p2 = Projection()->FromLatLngToPixel(rect.Bottom(), rect.Right(), i); + + if(((p2.X() - p1.X()) <= Width+10) && (p2.Y() - p1.Y()) <= Height+10) + { + zoom = i; + } + else + { + break; + } + } + + return zoom; + } + void Core::BeginDrag(Point const& pt) + { + dragPoint.SetX(pt.X() - renderOffset.X()); + dragPoint.SetY(pt.Y() - renderOffset.Y()); + isDragging = true; + } + void Core::EndDrag() + { + isDragging = false; emit OnNeedInvalidation(); } -} -void Core::GoToCurrentPosition() -{ - // reset stuff - renderOffset = Point::Empty; - centerTileXYLocationLast = Point::Empty; - dragPoint = Point::Empty; - - // goto location - Drag(Point(-(GetcurrentPositionGPixel().X() - Width/2), -(GetcurrentPositionGPixel().Y() - Height/2))); -} -void Core::GoToCurrentPositionOnZoom() -{ - // reset stuff - renderOffset = Point::Empty; - centerTileXYLocationLast = Point::Empty; - dragPoint = Point::Empty; - - // goto location and centering - if(MouseWheelZooming) + void Core::ReloadMap() { - if(mousewheelzoomtype != MouseWheelZoomType::MousePositionWithoutCenter) + if(started) { +#ifdef DEBUG_CORE + qDebug()<<"------------------"; +#endif //DEBUG_CORE + + MtileLoadQueue.lock(); + { + tileLoadQueue.clear(); + } + MtileLoadQueue.unlock(); + Matrix.Clear(); + + emit OnNeedInvalidation(); + + } + } + void Core::GoToCurrentPosition() + { + // reset stuff + renderOffset = Point::Empty; + centerTileXYLocationLast = Point::Empty; + dragPoint = Point::Empty; + + // goto location + Drag(Point(-(GetcurrentPositionGPixel().X() - Width/2), -(GetcurrentPositionGPixel().Y() - Height/2))); + } + void Core::GoToCurrentPositionOnZoom() + { + // reset stuff + renderOffset = Point::Empty; + centerTileXYLocationLast = Point::Empty; + dragPoint = Point::Empty; + + // goto location and centering + if(MouseWheelZooming) + { + if(mousewheelzoomtype != MouseWheelZoomType::MousePositionWithoutCenter) + { + Point pt = Point(-(GetcurrentPositionGPixel().X() - Width/2), -(GetcurrentPositionGPixel().Y() - Height/2)); + renderOffset.SetX(pt.X() - dragPoint.X()); + renderOffset.SetY(pt.Y() - dragPoint.Y()); + } + else // without centering + { + renderOffset.SetX(-GetcurrentPositionGPixel().X() - dragPoint.X()); + renderOffset.SetY(-GetcurrentPositionGPixel().Y() - dragPoint.Y()); + renderOffset.Offset(mouseLastZoom); + } + } + else // use current map center + { + mouseLastZoom = Point::Empty; + Point pt = Point(-(GetcurrentPositionGPixel().X() - Width/2), -(GetcurrentPositionGPixel().Y() - Height/2)); renderOffset.SetX(pt.X() - dragPoint.X()); renderOffset.SetY(pt.Y() - dragPoint.Y()); } - else // without centering - { - renderOffset.SetX(-GetcurrentPositionGPixel().X() - dragPoint.X()); - renderOffset.SetY(-GetcurrentPositionGPixel().Y() - dragPoint.Y()); - renderOffset.Offset(mouseLastZoom); - } - } - else // use current map center - { - mouseLastZoom = Point::Empty; - Point pt = Point(-(GetcurrentPositionGPixel().X() - Width/2), -(GetcurrentPositionGPixel().Y() - Height/2)); + UpdateCenterTileXYLocation(); + } + void Core::DragOffset(Point const& offset) + { + renderOffset.Offset(offset); + + UpdateCenterTileXYLocation(); + + if(centerTileXYLocation != centerTileXYLocationLast) + { + centerTileXYLocationLast = centerTileXYLocation; + UpdateBounds(); + } + + { + LastLocationInBounds = CurrentPosition(); + SetCurrentPosition (FromLocalToLatLng((int) Width/2, (int) Height/2)); + } + + emit OnNeedInvalidation(); + emit OnMapDrag(); + } + void Core::Drag(Point const& pt) + { renderOffset.SetX(pt.X() - dragPoint.X()); renderOffset.SetY(pt.Y() - dragPoint.Y()); - } - UpdateCenterTileXYLocation(); -} -void Core::DragOffset(Point const& offset) -{ - renderOffset.Offset(offset); + UpdateCenterTileXYLocation(); - UpdateCenterTileXYLocation(); - - if(centerTileXYLocation != centerTileXYLocationLast) - { - centerTileXYLocationLast = centerTileXYLocation; - UpdateBounds(); - } - - { - LastLocationInBounds = CurrentPosition(); - SetCurrentPosition (FromLocalToLatLng((int) Width/2, (int) Height/2)); - } - - emit OnNeedInvalidation(); - emit OnMapDrag(); -} -void Core::Drag(Point const& pt) -{ - renderOffset.SetX(pt.X() - dragPoint.X()); - renderOffset.SetY(pt.Y() - dragPoint.Y()); - - UpdateCenterTileXYLocation(); - - if(centerTileXYLocation != centerTileXYLocationLast) - { - centerTileXYLocationLast = centerTileXYLocation; - UpdateBounds(); - } - - if(IsDragging()) - { - LastLocationInBounds = CurrentPosition(); - SetCurrentPosition(FromLocalToLatLng((int) Width/2, (int) Height/2)); - } - - emit OnNeedInvalidation(); - - - emit OnMapDrag(); - -} -void Core::CancelAsyncTasks() -{ - if(started) - { - ProcessLoadTaskCallback.waitForDone(); - MtileLoadQueue.lock(); + if(centerTileXYLocation != centerTileXYLocationLast) { - tileLoadQueue.clear(); + centerTileXYLocationLast = centerTileXYLocation; + UpdateBounds(); } - MtileLoadQueue.unlock(); - // ProcessLoadTaskCallback.waitForDone(); - } -} -void Core::UpdateBounds() -{ - MtileDrawingList.lock(); - { - FindTilesAround(tileDrawingList); -#ifdef DEBUG_CORE - qDebug()<<"OnTileLoadStart: " << tileDrawingList.count() << " tiles to load at zoom " << Zoom() << ", time: " << QDateTime::currentDateTime().date(); -#endif //DEBUG_CORE - - emit OnTileLoadStart(); - - - foreach(Point p,tileDrawingList) + if(IsDragging()) { - LoadTask task = LoadTask(p, Zoom()); + LastLocationInBounds = CurrentPosition(); + SetCurrentPosition(FromLocalToLatLng((int) Width/2, (int) Height/2)); + } + + emit OnNeedInvalidation(); + + + emit OnMapDrag(); + + } + void Core::CancelAsyncTasks() + { + if(started) + { + ProcessLoadTaskCallback.waitForDone(); + MtileLoadQueue.lock(); { - MtileLoadQueue.lock(); - { - if(!tileLoadQueue.contains(task)) - { - tileLoadQueue.enqueue(task); -#ifdef DEBUG_CORE - qDebug()<<"Core::UpdateBounds new Task"< &list) - { - list.clear();; - for(int i = -sizeOfMapArea.Width(); i <= sizeOfMapArea.Width(); i++) - { + void Core::UpdateBounds() + { + MtileDrawingList.lock(); + { + FindTilesAround(tileDrawingList); + +#ifdef DEBUG_CORE + qDebug()<<"OnTileLoadStart: " << tileDrawingList.count() << " tiles to load at zoom " << Zoom() << ", time: " << QDateTime::currentDateTime().date(); +#endif //DEBUG_CORE + + emit OnTileLoadStart(); + + + foreach(Point p,tileDrawingList) + { + LoadTask task = LoadTask(p, Zoom()); + { + MtileLoadQueue.lock(); + { + if(!tileLoadQueue.contains(task)) + { + tileLoadQueue.enqueue(task); +#ifdef DEBUG_CORE + qDebug()<<"Core::UpdateBounds new Task"< &list) + { + list.clear();; + for(int i = -sizeOfMapArea.Width(); i <= sizeOfMapArea.Width(); i++) + { for(int j = -sizeOfMapArea.Height(); j <= sizeOfMapArea.Height(); j++) { - Point p = centerTileXYLocation; - p.SetX(p.X() + i); - p.SetY(p.Y() + j); + Point p = centerTileXYLocation; + p.SetX(p.X() + i); + p.SetY(p.Y() + j); - //if(p.X < minOfTiles.Width) - //{ - // p.X += (maxOfTiles.Width + 1); - //} + //if(p.X < minOfTiles.Width) + //{ + // p.X += (maxOfTiles.Width + 1); + //} - //if(p.X > maxOfTiles.Width) - //{ - // p.X -= (maxOfTiles.Width + 1); - //} + //if(p.X > maxOfTiles.Width) + //{ + // p.X -= (maxOfTiles.Width + 1); + //} - if(p.X() >= minOfTiles.Width() && p.Y() >= minOfTiles.Height() && p.X() <= maxOfTiles.Width() && p.Y() <= maxOfTiles.Height()) - { - if(!list.contains(p)) - { - list.append(p); - } - } + if(p.X() >= minOfTiles.Width() && p.Y() >= minOfTiles.Height() && p.X() <= maxOfTiles.Width() && p.Y() <= maxOfTiles.Height()) + { + if(!list.contains(p)) + { + list.append(p); + } + } } - } + } - } -void Core::UpdateGroundResolution() -{ - double rez = Projection()->GetGroundResolution(Zoom(), CurrentPosition().Lat()); - pxRes100m = (int) (100.0 / rez); // 100 meters - pxRes1000m = (int) (1000.0 / rez); // 1km - pxRes10km = (int) (10000.0 / rez); // 10km - pxRes100km = (int) (100000.0 / rez); // 100km - pxRes1000km = (int) (1000000.0 / rez); // 1000km - pxRes5000km = (int) (5000000.0 / rez); // 5000km -} + } + void Core::UpdateGroundResolution() + { + double rez = Projection()->GetGroundResolution(Zoom(), CurrentPosition().Lat()); + pxRes100m = (int) (100.0 / rez); // 100 meters + pxRes1000m = (int) (1000.0 / rez); // 1km + pxRes10km = (int) (10000.0 / rez); // 10km + pxRes100km = (int) (100000.0 / rez); // 100km + pxRes1000km = (int) (1000000.0 / rez); // 1000km + pxRes5000km = (int) (5000000.0 / rez); // 5000km + } } diff --git a/ground/src/experimental/OPMapWidget/internals/core.h b/ground/src/experimental/OPMapWidget/internals/core.h index 425444f62..e3c7e1f24 100644 --- a/ground/src/experimental/OPMapWidget/internals/core.h +++ b/ground/src/experimental/OPMapWidget/internals/core.h @@ -28,9 +28,7 @@ #ifndef CORE_H #define CORE_H -#define DEBUG_CORE -//#define DEBUG_TILE -//#define DEBUG_TILEMATRIX +#include "debugheader.h" #include "../internals/PointLatlng.h" #include "mousewheelzoomtype.h" @@ -56,11 +54,16 @@ //#include +namespace mapcontrol +{ + class OPMapControl; +} namespace internals { class Core:public QObject,public QRunnable { Q_OBJECT + friend class mapcontrol::OPMapControl; public: Core(); void run(); @@ -179,12 +182,7 @@ public: TileMatrix Matrix; - Rectangle tileRect; - Point mouseDown; - bool CanDragMap; - Point mouseCurrent; - PointLatLng LastLocationInBounds; - Point mouseLastZoom; + signals: void OnCurrentPositionChanged(PointLatLng point); void OnTileLoadComplete(); @@ -197,14 +195,19 @@ signals: private: - static qlonglong debugcounter; + PointLatLng currentPosition; Point currentPositionPixel; Point renderOffset; Point centerTileXYLocation; Point centerTileXYLocationLast; Point dragPoint; - + Rectangle tileRect; + Point mouseDown; + bool CanDragMap; + Point mouseCurrent; + PointLatLng LastLocationInBounds; + Point mouseLastZoom; MouseWheelZoomType::Types mousewheelzoomtype; @@ -233,9 +236,10 @@ private: QMutex Moverlays; QMutex MtileDrawingList; - +#ifdef DEBUG_CORE QMutex Mdebug; - + static qlonglong debugcounter; +#endif Size TooltipTextPadding; MapType::Types mapType; diff --git a/ground/src/experimental/OPMapWidget/internals/debugheader.h b/ground/src/experimental/OPMapWidget/internals/debugheader.h new file mode 100644 index 000000000..8e5bdba43 --- /dev/null +++ b/ground/src/experimental/OPMapWidget/internals/debugheader.h @@ -0,0 +1,8 @@ +#ifndef DEBUGHEADER_H +#define DEBUGHEADER_H + +//#define DEBUG_CORE +//#define DEBUG_TILE +//#define DEBUG_TILEMATRIX + +#endif // DEBUGHEADER_H diff --git a/ground/src/experimental/OPMapWidget/internals/internals.pro b/ground/src/experimental/OPMapWidget/internals/internals.pro index 74693d4bf..21ce6b4b6 100644 --- a/ground/src/experimental/OPMapWidget/internals/internals.pro +++ b/ground/src/experimental/OPMapWidget/internals/internals.pro @@ -9,7 +9,8 @@ HEADERS += core.h \ pureprojection.h \ pointlatlng.h \ rectlatlng.h \ - sizelatlng.h + sizelatlng.h \ + debugheader.h SOURCES += core.cpp \ rectangle.cpp \ tile.cpp \ @@ -19,7 +20,7 @@ SOURCES += core.cpp \ sizelatlng.cpp \ pointlatlng.cpp \ loadtask.cpp \ - MouseWheelZoomType.cpp + mousewheelzoomtype.cpp HEADERS += ./projections/lks94projection.h \ ./projections/mercatorprojection.h \ ./projections/mercatorprojectionyandex.h \ diff --git a/ground/src/experimental/OPMapWidget/internals/tile.h b/ground/src/experimental/OPMapWidget/internals/tile.h index 896ac408c..ffe83cf09 100644 --- a/ground/src/experimental/OPMapWidget/internals/tile.h +++ b/ground/src/experimental/OPMapWidget/internals/tile.h @@ -33,6 +33,7 @@ #include "../core/point.h" #include #include +#include "debugheader.h" using namespace core; namespace internals { diff --git a/ground/src/experimental/OPMapWidget/internals/tilematrix.h b/ground/src/experimental/OPMapWidget/internals/tilematrix.h index 2f5010507..a35d8636e 100644 --- a/ground/src/experimental/OPMapWidget/internals/tilematrix.h +++ b/ground/src/experimental/OPMapWidget/internals/tilematrix.h @@ -32,7 +32,7 @@ #include "tile.h" #include #include "../core/point.h" - +#include "debugheader.h" namespace internals { class TileMatrix {