bool downloadOSM(QWidget* aParent, const QString& aWeb, const QString& aUser, const QString& aPassword, const CoordBox& aBox , Document* theDocument, Layer* theLayer) { if (checkForConflicts(theDocument)) { QMessageBox::warning(aParent,QApplication::translate("Downloader","Unresolved conflicts"), QApplication::translate("Downloader","Please resolve existing conflicts first")); return false; } Downloader Rcv(aUser, aPassword); QString URL = Rcv.getURLToMap(); if ((fabs(aBox.bottomLeft().x()) < 180.0 && fabs(aBox.topRight().x()) > 180.0) || (fabs(aBox.bottomLeft().x()) > 180.0 && fabs(aBox.topRight().x()) < 180.0)) { /* Check for +-180 meridian, and split query in two if necessary */ int sign = (aBox.bottomLeft().x() > 0) ? 1 : -1; CoordBox q1 = aBox, q2 = aBox; if (aBox.bottomLeft().x() > 0) { q1.setRight(180*sign); q2.setLeft(-180*sign); q2.setRight(q2.right()-360); } else { q1.setLeft(180*sign); q2.setRight(-180*sign); q2.setLeft(q2.left()+360); } return downloadOSM(aParent, aWeb, aUser, aPassword, q1, theDocument, theLayer) && downloadOSM(aParent, aWeb, aUser, aPassword, q2, theDocument, theLayer); } else { /* Normal code path */ URL = URL.arg(aBox.bottomLeft().x(), 0, 'f').arg(aBox.bottomLeft().y(), 0, 'f').arg(aBox.topRight().x(), 0, 'f').arg(aBox.topRight().y(), 0, 'f'); QUrl theUrl(aWeb+URL); return downloadOSM(aParent, theUrl, aUser, aPassword, theDocument, theLayer); } }
QString WmscMapAdapter::getQuery(int i, int j, int /* z */) const { // WMS-C Y origin is lower left // j = getTilesNS(current_zoom)-1 - j; qreal tileWidth = getBoundingbox().width() / getTilesWE(current_zoom); qreal tileHeight = getBoundingbox().height() / getTilesNS(current_zoom); QPointF ul = QPointF(i*tileWidth+getBoundingbox().topLeft().x(), getBoundingbox().bottomLeft().y()-j*tileHeight); QPointF br = QPointF((i+1)*tileWidth+getBoundingbox().topLeft().x(), getBoundingbox().bottomLeft().y()- (j+1)*tileHeight); QUrl theUrl(theServer.WmsPath); #ifdef QT5 QUrlQuery theQuery; #define theQuery theQuery #else #define theQuery theUrl #endif if (!theQuery.hasQueryItem("VERSION")) theQuery.addQueryItem("VERSION", "1.1.1"); if (!theQuery.hasQueryItem("SERVICE")) theQuery.addQueryItem("SERVICE", "WMS"); theQuery.addQueryItem("REQUEST", "GetMap"); if (!theQuery.hasQueryItem("TRANSPARENT")) theQuery.addQueryItem("TRANSPARENT", "TRUE"); if (!theQuery.hasQueryItem("LAYERS")) theQuery.addQueryItem("LAYERS", theServer.WmsLayers); if (!theQuery.hasQueryItem("SRS")) theQuery.addQueryItem("SRS", theServer.WmsProjections); if (!theQuery.hasQueryItem("STYLES")) theQuery.addQueryItem("STYLES", theServer.WmsStyles); if (!theQuery.hasQueryItem("FORMAT")) theQuery.addQueryItem("FORMAT", theServer.WmsImgFormat); theQuery.addQueryItem("WIDTH", QString::number(getTileSizeW())); theQuery.addQueryItem("HEIGHT", QString::number(getTileSizeH())); theQuery.addQueryItem("BBOX", QString() .append(loc.toString(ul.x(),'f',6)).append(",") .append(loc.toString(br.y(),'f',6)).append(",") .append(loc.toString(br.x(),'f',6)).append(",") .append(loc.toString(ul.y(),'f',6)) ); if (theServer.WmsIsTiled == 1) theQuery.addQueryItem("tiled", "true"); #ifdef QT5 theUrl.setQuery(theQuery); #endif #undef theQuery return theUrl.toString(QUrl::RemoveScheme | QUrl::RemoveAuthority); }
bool downloadTracksFromOSM(QWidget* Main, const QString& aWeb, const QString& aUser, const QString& aPassword, const CoordBox& aBox , Document* theDocument) { Downloader theDownloader(aUser, aPassword); QList<TrackLayer*> theTracklayers; //TrackMapLayer* trackLayer = new TrackMapLayer(QApplication::translate("Downloader","Downloaded tracks")); //theDocument->add(trackLayer); IProgressWindow* aProgressWindow = dynamic_cast<IProgressWindow*>(Main); if (!aProgressWindow) return false; QProgressDialog* dlg = aProgressWindow->getProgressDialog(); dlg->setWindowTitle(QApplication::translate("Downloader","Parsing...")); QProgressBar* Bar = aProgressWindow->getProgressBar(); Bar->setTextVisible(false); Bar->setMaximum(11); QLabel* Lbl = aProgressWindow->getProgressLabel(); Lbl->setText(QApplication::translate("Downloader","Parsing XML")); if (dlg) dlg->show(); theDownloader.setAnimator(dlg,Lbl,Bar,true); for (int Page=0; ;++Page) { Lbl->setText(QApplication::translate("Downloader","Downloading trackpoints %1-%2").arg(Page*5000+1).arg(Page*5000+5000)); QString URL = theDownloader.getURLToTrackPoints(); URL = URL.arg(aBox.bottomLeft().x()). arg(aBox.bottomLeft().y()). arg(aBox.topRight().x()). arg(aBox.topRight().y()). arg(Page); QUrl theUrl(aWeb+URL); if (!theDownloader.go(theUrl)) return false; if (theDownloader.resultCode() != 200) return false; int Before = theTracklayers.size(); QByteArray Ar(theDownloader.content()); bool OK = importGPX(Main, Ar, theDocument, theTracklayers, true); if (!OK) return false; if (Before == theTracklayers.size()) break; theTracklayers[theTracklayers.size()-1]->setName(QApplication::translate("Downloader", "Downloaded track - nodes %1-%2").arg(Page*5000+1).arg(Page*5000+5000)); } return true; }
bool downloadOSM(QWidget* aParent, const QString& aWeb, const QString& aUser, const QString& aPassword, const CoordBox& aBox , Document* theDocument, Layer* theLayer) { if (checkForConflicts(theDocument)) { QMessageBox::warning(aParent,QApplication::translate("Downloader","Unresolved conflicts"), QApplication::translate("Downloader","Please resolve existing conflicts first")); return false; } Downloader Rcv(aUser, aPassword); QString URL = Rcv.getURLToMap(); URL = URL.arg(aBox.bottomLeft().x(), 0, 'f').arg(aBox.bottomLeft().y(), 0, 'f').arg(aBox.topRight().x(), 0, 'f').arg(aBox.topRight().y(), 0, 'f'); QUrl theUrl(aWeb+URL); return downloadOSM(aParent, theUrl, aUser, aPassword, theDocument, theLayer); }
bool DirtyListExecutor::sendRequest(const QString& Method, const QString& URL, const QString& Data, QString& Rcv) { if (inError()) return false; QMessageBox::StandardButton theChoice = QMessageBox::Retry; while (theChoice == QMessageBox::Retry) { QUrl theUrl(Web+URL); if (!theDownloader->request(Method,theUrl,Data)) { qDebug() << QString("Upload error: request (%1); Server message is '%2'").arg(theDownloader->resultCode()).arg(theDownloader->resultText()); if (theDownloader->resultCode() == 401) { QMessageBox::warning(Progress,tr("Error uploading request"), tr("Please check your username and password in the Preferences menu")); theChoice = QMessageBox::Abort; } else { QString msg = tr("There was an error uploading this request (%1)\nServer message is '%2'").arg(theDownloader->resultCode()).arg(theDownloader->resultText()); if (!theDownloader->errorText().isEmpty()) msg += tr("\nAPI message is '%1'").arg(theDownloader->errorText()); theChoice = QMessageBox::warning(Progress,tr("Error uploading request"), msg, QMessageBox::Abort | QMessageBox::Retry | QMessageBox::Ignore); continue; } } QByteArray Content = theDownloader->content(); int x = theDownloader->resultCode(); if (x==200) { Rcv = QString::fromUtf8(Content.data()); break; } else { qDebug() << QString("Upload error: request (%1); Server message is '%2'").arg(theDownloader->resultCode()).arg(theDownloader->resultText()); theChoice = QMessageBox::warning(Progress,tr("Error uploading request"), tr("There was an error uploading this request (%1)\nServer message is '%2'").arg(x).arg(theDownloader->resultText()), QMessageBox::Abort | QMessageBox::Retry | QMessageBox::Ignore); continue; } } if (theChoice == QMessageBox::Abort) { errorAbort = true; return false; } return true; }
bool downloadFeatures(MainWindow* Main, const QList<IFeature::FId>& idList , Document* theDocument, Layer* theLayer) { if (!theLayer) { if (!theDocument->getLastDownloadLayer()) { theLayer = new DrawingLayer(QApplication::translate("Downloader","%1 download").arg(QDateTime::currentDateTime().toString(Qt::ISODate))); theDocument->add(theLayer); } else theLayer = (Layer*)theDocument->getLastDownloadLayer(); } QString osmWebsite, osmUser, osmPwd; osmWebsite = M_PREFS->getOsmApiUrl(); osmUser = M_PREFS->getOsmUser(); osmPwd = M_PREFS->getOsmPassword(); if (Main) Main->view()->setUpdatesEnabled(false); bool OK = true; Downloader Rcv(osmUser, osmPwd); for (int i=0; i<idList.size(); ++i) { QString URL = Rcv.getURLToFetchFull(idList[i]); QUrl theUrl(osmWebsite+URL); downloadOSM(Main, theUrl, osmUser, osmPwd, theDocument, theLayer); } if (Main) Main->view()->setUpdatesEnabled(true); if (OK) { if (Main) Main->invalidateView(); } else { if (theLayer != theDocument->getLastDownloadLayer()) { theDocument->remove(theLayer); delete theLayer; } } return OK; }