void MapWidget::showLocation(Location* location) { if (location==NULL) { std::cout << "MapWidget::showLocation(): no location passed!" << std::endl; return; } std::cout << "MapWidget::showLocation(\"" << location->getName().toLocal8Bit().constData() << "\")" << std::endl; osmscout::ObjectFileRef reference=location->getReferences().front(); DBThread* dbThread=DBThread::GetInstance(); if (reference.GetType()==osmscout::refNode) { osmscout::NodeRef node; if (dbThread->GetNodeByOffset(reference.GetFileOffset(),node)) { center=node->GetCoords(); this->magnification=osmscout::Magnification::magVeryClose; TriggerMapRendering(); } } else if (reference.GetType()==osmscout::refArea) { osmscout::AreaRef area; if (dbThread->GetAreaByOffset(reference.GetFileOffset(),area)) { if (area->GetCenter(center)) { this->magnification=osmscout::Magnification::magVeryClose; TriggerMapRendering(); } } } else if (reference.GetType()==osmscout::refWay) { osmscout::WayRef way; if (dbThread->GetWayByOffset(reference.GetFileOffset(),way)) { if (way->GetCenter(center)) { this->magnification=osmscout::Magnification::magVeryClose; TriggerMapRendering(); } } } else { assert(false); } }
MapWidget::MapWidget(QQuickItem* parent) : QQuickPaintedItem(parent), center(0.0,0.0), angle(0.0), magnification(64), requestNewMap(true) { setOpaquePainting(true); setAcceptedMouseButtons(Qt::LeftButton); DBThread *dbThread=DBThread::GetInstance(); //setFocusPolicy(Qt::StrongFocus); connect(dbThread,SIGNAL(InitialisationFinished(DatabaseLoadedResponse)), this,SLOT(initialisationFinished(DatabaseLoadedResponse))); connect(this,SIGNAL(TriggerMapRenderingSignal()), dbThread,SLOT(TriggerMapRendering())); connect(dbThread,SIGNAL(HandleMapRenderingResult()), this,SLOT(redraw())); connect(dbThread,SIGNAL(Redraw()), this,SLOT(redraw())); }
void MapWidget::zoom(double zoomFactor, double dx, double dy) { DBThread *dbThread=DBThread::GetInstance(); quickZooming = false; quickMoveX = 0; quickMoveY = 0; quickZoomFactor = 1; if(!dbThread->IsOpened()) return; osmscout::MercatorProjection projection; dbThread->GetProjection(projection); if(dx<0) projection.MoveLeft(-1*dx/zoomFactor); else projection.MoveRight(dx/zoomFactor); if(dy<0) projection.MoveUp(-1*dy/zoomFactor); else projection.MoveDown(dy/zoomFactor); center=projection.GetCenter(); osmscout::Magnification maxMag; maxMag.SetLevel(20); if (magnification.GetMagnification()*zoomFactor>maxMag.GetMagnification()) { magnification.SetMagnification(maxMag.GetMagnification()); } else { if (magnification.GetMagnification()*zoomFactor<1) { magnification.SetMagnification(1); } else { magnification.SetMagnification(magnification.GetMagnification()*zoomFactor); } } TriggerMapRendering(); }
void MapWidget::showCoordinates(double lat, double lon) { center=osmscout::GeoCoord(lat,lon); this->magnification=osmscout::Magnification::magVeryClose; TriggerMapRendering(); }
void MapWidget::paint(QPainter *painter) { RenderMapRequest request; QRectF boundingBox=contentsBoundingRect(); request.lat=center.GetLat(); request.lon=center.GetLon(); request.angle=angle; request.magnification=magnification; request.width=boundingBox.width(); request.height=boundingBox.height(); if(quickZooming) //just zoom the already rendered Qimage and repaint { DBThread *dbThread=DBThread::GetInstance(); dbThread->RenderMapQuick(*painter, quickMoveX, quickMoveY, quickZoomFactor, request); } else { DBThread *dbThread=DBThread::GetInstance(); if (!dbThread->RenderMap(*painter,request) && requestNewMap) { TriggerMapRendering(); } requestNewMap=true; } }
void MapWidget::showCoordinates(double lat, double lon) { center=osmscout::GeoCoord(lat,lon); this->magnification=osmscout::Magnification::magVeryClose; DBThread* dbThread = DBThread::GetInstance(); if(!dbThread->IsRendering()) TriggerMapRendering(); }
void MapWidget::rotateRight() { angle=round(angle/DELTA_ANGLE)*DELTA_ANGLE+DELTA_ANGLE; if (angle>=2*M_PI) { angle-=2*M_PI; } TriggerMapRendering(); }
void MapWidget::rotateLeft() { angle=round(angle/DELTA_ANGLE)*DELTA_ANGLE-DELTA_ANGLE; if (angle<0) { angle+=2*M_PI; } TriggerMapRendering(); }
void MapWidget::zoomOut(double zoomFactor) { if (magnification.GetMagnification()/zoomFactor<1) { magnification.SetMagnification(1); } else { magnification.SetMagnification(magnification.GetMagnification()/zoomFactor); } TriggerMapRendering(); }
void MapWidget::down() { DBThread *dbThread=DBThread::GetInstance(); osmscout::MercatorProjection projection; dbThread->GetProjection(projection); projection.MoveDown(height()/3); center=projection.GetCenter(); TriggerMapRendering(); }
void MapWidget::zoomIn(double zoomFactor) { if (magnification.GetMagnification()*zoomFactor>800000) { magnification.SetMagnification(800000); } else { magnification.SetMagnification(magnification.GetMagnification()*zoomFactor); } TriggerMapRendering(); emit zoomLevelChanged(); emit zoomLevelNameChanged(); }
void MapWidget::zoomIn(double zoomFactor) { osmscout::Magnification maxMag; maxMag.SetLevel(20); if (magnification.GetMagnification()*zoomFactor>maxMag.GetMagnification()) { magnification.SetMagnification(maxMag.GetMagnification()); } else { magnification.SetMagnification(magnification.GetMagnification()*zoomFactor); } TriggerMapRendering(); }
void MapWidget::down() { osmscout::MercatorProjection projection; osmscout::GeoBox boundingBox; projection.Set(center.GetLon(), center.GetLat(), magnification, width(),height()); projection.GetDimensions(boundingBox); center.Set(center.GetLat()-boundingBox.GetHeight()*0.3, center.GetLon()); TriggerMapRendering(); }
void MapWidget::right() { quickMoveX = 0; quickMoveY = 0; quickZooming = false; quickZoomFactor = 1; DBThread *dbThread=DBThread::GetInstance(); osmscout::MercatorProjection projection; dbThread->GetProjection(projection); projection.MoveRight(width()/3); center=projection.GetCenter(); TriggerMapRendering(); }
void MapWidget::paint(QPainter *painter) { RenderMapRequest request; DBThread *dbThread=DBThread::GetInstance(); QRectF boundingBox=contentsBoundingRect(); request.lat=center.GetLat(); request.lon=center.GetLon(); request.magnification=magnification; request.width=boundingBox.width(); request.height=boundingBox.height(); if (!dbThread->RenderMap(*painter,request) && requestNewMap) { TriggerMapRendering(); } requestNewMap=true; }
void MapWidget::initialisationFinished(const DatabaseLoadedResponse& response) { size_t zoom=1; double dlat=360; double dlon=180; center=response.boundingBox.GetCenter(); while (dlat>response.boundingBox.GetHeight() && dlon>response.boundingBox.GetWidth()) { zoom=zoom*2; dlat=dlat/2; dlon=dlon/2; } magnification=zoom; TriggerMapRendering(); }
void MapWidget::move(double x, double y) { quickMoveX = 0; quickMoveY = 0; quickZoomFactor = 1; quickZooming = false; DBThread *dbThread=DBThread::GetInstance(); if(!dbThread->IsOpened()) return; osmscout::MercatorProjection projection; dbThread->GetProjection(projection); if(x<0) projection.MoveLeft(-1*x); else projection.MoveRight(x); if(y<0) projection.MoveUp(-1*y); else projection.MoveDown(y); center=projection.GetCenter(); TriggerMapRendering(); }
void MapWidget::initialisationFinished(const DatabaseLoadedResponse& response) { size_t zoom=1; double dlat=360; double dlon=180; std::cout << "Initial bounding box " << response.boundingBox.GetDisplayText() << std::endl; center=response.boundingBox.GetCenter(); while (dlat>response.boundingBox.GetHeight() && dlon>response.boundingBox.GetWidth()) { zoom=zoom*2; dlat=dlat/2; dlon=dlon/2; } magnification=zoom; std::cout << "Magnification: " << magnification.GetMagnification() << "x" << std::endl; TriggerMapRendering(); }
void MapWidget::reloadTmpStyle() { DBThread* dbThread=DBThread::GetInstance(); dbThread->ReloadStyle(TMP_SUFFIX); TriggerMapRendering(); }