31 qlonglong internals::Core::debugcounter=0;
34 using namespace projections;
37 Core::Core():started(false),MouseWheelZooming(false),currentPosition(0,0),currentPositionPixel(0,0),LastLocationInBounds(-1,-1),sizeOfMapArea(0,0)
38 ,minOfTiles(0,0),maxOfTiles(0,0),zoom(0),isDragging(false),TooltipTextPadding(10,10),mapType(MapType::None),loaderLimit(5),maxzoom(21),runningThreads(0)
40 mousewheelzoomtype=MouseWheelZoomType::MousePositionAndCenter;
42 this->setAutoDelete(
false);
43 ProcessLoadTaskCallback.setMaxThreadCount(10);
44 renderOffset=Point(0,0);
52 ProcessLoadTaskCallback.waitForDone();
57 MrunningThreads.lock();
59 MrunningThreads.unlock();
65 qDebug()<<
"core:run"<<
" ID="<<
debug;
71 MtileLoadQueue.lock();
73 if(tileLoadQueue.count() > 0)
75 task = tileLoadQueue.dequeue();
78 last = (tileLoadQueue.count() == 0);
80 qDebug()<<
"TileLoadQueue: " << tileLoadQueue.count()<<
" Point:"<<task.
Pos.
ToString()<<
" ID="<<
debug;;
85 MtileLoadQueue.unlock();
88 if(loaderLimit.tryAcquire(1,TLMaps::Instance()->Timeout))
94 qDebug()<<
"loadLimit semaphore aquired "<<loaderLimit.available()<<
" ID="<<debug<<
" TASK="<<task.
Pos.
ToString()<<
" "<<task.
Zoom;
100 qDebug()<<
"task as value, begining get"<<
" ID="<<
debug;;
105 if(m==
nullptr || m->
Overlays.count() == 0)
108 qDebug()<<
"Fill empty TileMatrix: " + task.
ToString()<<
" ID="<<
debug;;
112 QVector<MapType::Types> layers= TLMaps::Instance()->GetAllLayersOfType(
GetMapType());
114 foreach(MapType::Types tl,layers)
120 QByteArray tileImage;
123 if(tl == MapType::PergoTurkeyMap)
125 tileImage = TLMaps::Instance()->GetImageFromServer(tl, Point(task.
Pos.
X(), maxOfTiles.Height() - task.
Pos.
Y()), task.
Zoom);
127 else if(tl == MapType::UserImage)
129 tileImage = TLMaps::Instance()->GetImageFromFile(tl, task.
Pos, task.
Zoom, userImageHorizontalScale, userImageVerticalScale, userImageLocation,
Projection());
134 qDebug()<<
"start getting image"<<
" ID="<<
debug;
136 tileImage = TLMaps::Instance()->GetImageFromServer(tl, task.
Pos, task.
Zoom);
138 qDebug()<<
"Core::run:gotimage size:"<<tileImage.count()<<
" ID="<<
debug;
142 if(tileImage.length()!=0)
148 qDebug()<<
"Core::run append tileImage:"<<tileImage.length()<<
" to tile:"<<t->
GetPos().
ToString()<<
" now has "<<t->
Overlays.count()<<
" overlays"<<
" ID="<<
debug;
156 else if(TLMaps::Instance()->RetryLoadTile > 0)
159 qDebug()<<
"ProcessLoadTask: " << task.
ToString()<<
" -> empty tile, retry " << retry<<
" ID="<<
debug;;
163 while(++retry < TLMaps::Instance()->RetryLoadTile);
194 TLMaps::Instance()->kiberCacheLock.lockForWrite();
195 TLMaps::Instance()->TilesInMemory.RemoveMemoryOverload();
196 TLMaps::Instance()->kiberCacheLock.unlock();
198 MtileDrawingList.lock();
202 MtileDrawingList.unlock();
217 qDebug()<<
"loaderLimit release:"+loaderLimit.available()<<
" ID="<<
debug;
220 loaderLimit.release();
222 MrunningThreads.lock();
224 MrunningThreads.unlock();
228 MrunningThreads.lock();
229 diag=TLMaps::Instance()->GetDiagnostics();
231 MrunningThreads.unlock();
246 MtileLoadQueue.lock();
247 tileLoadQueue.clear();
248 MtileLoadQueue.unlock();
251 MtileToload.unlock();
267 currentPosition = value;
278 currentPosition = value;
290 userImageHorizontalScale=hScale;
294 userImageVerticalScale=vScale;
298 userImageLocation=mapLocation;
312 case MapType::ArcGIS_Map:
313 case MapType::ArcGIS_Satellite:
314 case MapType::ArcGIS_ShadedRelief:
315 case MapType::ArcGIS_Terrain:
317 if(
Projection()->Type()!=
"PlateCarreeProjection")
324 case MapType::ArcGIS_MapsLT_Map_Hybrid:
325 case MapType::ArcGIS_MapsLT_Map_Labels:
326 case MapType::ArcGIS_MapsLT_Map:
327 case MapType::ArcGIS_MapsLT_OrtoFoto:
337 case MapType::PergoTurkeyMap:
339 if(
Projection()->Type()!=
"PlateCarreeProjectionPergo")
347 case MapType::YandexMapRu:
349 if(
Projection()->Type()!=
"MercatorProjectionYandex")
357 case MapType::UserImage:
359 if(
Projection()->Type()!=
"MercatorProjection")
368 if(
Projection()->Type()!=
"MercatorProjection")
379 while( (1 << (numBits-1)) < projection->
TileSize().Width()){
382 unsigned int bitsWithZoom = numBits + (quint8)maxzoom;
384 if (bitsWithZoom >
sizeof(((
core::Point *)
nullptr)->X())*8 - 1){
385 maxzoom =
sizeof(((
core::Point *)
nullptr)->X())*8 - 1 - numBits;
447 return TLMaps::Instance()->GetPlacemarkFromGeocoder(coord,status,LanguageType().toShortString(TLMaps::Instance()->GetLanguage()));
452 return TLMaps::Instance()->GetLatLngFromGeodecoder(address,status,LanguageType().toShortString(TLMaps::Instance()->GetLanguage()));
457 return TLMaps::Instance()->GetElevationFromCoordinate(coord,status);
462 GeoCoderStatusCode::Types status = GeoCoderStatusCode::UNKNOWN_ERROR;
464 if((ret.length() > 0) && (status == GeoCoderStatusCode::OK))
489 pLocal.
Offset(renderOffset);
501 if(((p2.X() - p1.X()) <=
Width+10) && (p2.Y() - p1.Y()) <=
Height+10)
515 dragPoint.
SetX(pt.X() - renderOffset.
X());
516 dragPoint.
SetY(pt.Y() - renderOffset.
Y());
530 qDebug()<<
"------------------";
533 MtileLoadQueue.lock();
535 tileLoadQueue.clear();
537 MtileLoadQueue.unlock();
540 MtileToload.unlock();
550 renderOffset = Point::Empty;
551 centerTileXYLocationLast = Point::Empty;
552 dragPoint = Point::Empty;
560 renderOffset = Point::Empty;
561 centerTileXYLocationLast = Point::Empty;
562 dragPoint = Point::Empty;
565 if(MouseWheelZooming)
567 if(mousewheelzoomtype != MouseWheelZoomType::MousePositionWithoutCenter)
570 renderOffset.
SetX(pt.X() - dragPoint.
X());
571 renderOffset.
SetY(pt.Y() - dragPoint.
Y());
577 renderOffset.
Offset(mouseLastZoom);
582 mouseLastZoom = Point::Empty;
585 renderOffset.
SetX(pt.X() - dragPoint.
X());
586 renderOffset.
SetY(pt.Y() - dragPoint.
Y());
594 renderOffset.
Offset(offset);
598 if(centerTileXYLocation != centerTileXYLocationLast)
600 centerTileXYLocationLast = centerTileXYLocation;
614 renderOffset.
SetX(pt.X() - dragPoint.
X());
615 renderOffset.
SetY(pt.Y() - dragPoint.
Y());
619 if(centerTileXYLocation != centerTileXYLocationLast)
621 centerTileXYLocationLast = centerTileXYLocation;
640 ProcessLoadTaskCallback.waitForDone();
641 MtileLoadQueue.lock();
643 tileLoadQueue.clear();
646 MtileLoadQueue.unlock();
649 MtileToload.unlock();
655 MtileDrawingList.lock();
660 qDebug()<<
"OnTileLoadStart: " <<
tileDrawingList.count() <<
" tiles to load at zoom " <<
Zoom() <<
", time: " << QDateTime::currentDateTime().date();
670 MtileLoadQueue.lock();
672 if(!tileLoadQueue.contains(task))
676 MtileToload.unlock();
677 tileLoadQueue.enqueue(task);
679 qDebug()<<
"Core::UpdateBounds new Task"<<task.
Pos.
ToString();
681 ProcessLoadTaskCallback.start(
this);
684 MtileLoadQueue.unlock();
689 MtileDrawingList.unlock();
695 for(
int i = -sizeOfMapArea.Width();
i <= sizeOfMapArea.Width();
i++)
697 for(
int j = -sizeOfMapArea.Height(); j <= sizeOfMapArea.Height(); j++)
699 Point p = centerTileXYLocation;
713 if(p.X() >= minOfTiles.Width() && p.Y() >= minOfTiles.Height() && p.X() <= maxOfTiles.Width() && p.Y() <= maxOfTiles.Height())
715 if(!list.contains(p))
738 void Core::keepInBounds()
740 if(renderOffset.
X()>0)
741 renderOffset.
SetX(0);
742 if(renderOffset.
Y()>0)
743 renderOffset.
SetY(0);
748 if(maxDragY>renderOffset.
Y())
749 renderOffset.
SetY(maxDragY);
750 if(maxDragX>renderOffset.
X())
751 renderOffset.
SetX(maxDragX);