/**
******************************************************************************
*
* @file urlfactory.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "urlfactory.h"
#include <QRegExp>
namespace core {
const double UrlFactory::EarthRadiusKm = 6378.137; // WGS-84
UrlFactory::UrlFactory()
{
/// <summary>
/// timeout for map connections
/// </summary>
Proxy.setType(QNetworkProxy::NoProxy);
/// <summary>
/// Gets or sets the value of the User-agent HTTP header.
/// </summary>
UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7";
Timeout = 5 * 1000;
CorrectGoogleVersions = true;
isCorrectedGoogleVersions = false;
UseGeocoderCache = true;
UsePlacemarkCache = true;
}
UrlFactory::~UrlFactory()
{}
QString UrlFactory::TileXYToQuadKey(const int &tileX, const int &tileY, const int &levelOfDetail) const
{
QString quadKey;
for (int i = levelOfDetail; i > 0; i--) {
char digit = '0';
int mask = 1 << (i - 1);
if ((tileX & mask) != 0) {
digit++;
}
if ((tileY & mask) != 0) {
digit++;
digit++;
}
quadKey.append(digit);
}
return quadKey;
}
int UrlFactory::GetServerNum(const Point &pos, const int &max) const
{
return (pos.X() + 2 * pos.Y()) % max;
}
void UrlFactory::setIsCorrectGoogleVersions(bool value)
{
isCorrectedGoogleVersions = value;
}
bool UrlFactory::IsCorrectGoogleVersions()
{
return isCorrectedGoogleVersions;
}
void UrlFactory::TryCorrectGoogleVersions()
{
static bool versionRetrieved = false;
if (versionRetrieved) {
return;
}
QMutexLocker locker(&mutex);
if (CorrectGoogleVersions && !IsCorrectGoogleVersions()) {
QNetworkReply *reply;
QNetworkRequest qheader;
QNetworkAccessManager network;
QEventLoop q;
QTimer tT;
tT.setSingleShot(true);
connect(&network, SIGNAL(finished(QNetworkReply *)),
&q, SLOT(quit()));
connect(&tT, SIGNAL(timeout()), &q, SLOT(quit()));
network.setProxy(Proxy);
#ifdef DEBUG_URLFACTORY
qDebug() << "Correct GoogleVersion";
#endif // DEBUG_URLFACTORY
// setIsCorrectGoogleVersions(true);
QString url = "https://maps.google.com/maps?output=classic";
qheader.setUrl(QUrl(url));
qheader.setRawHeader("User-Agent", UserAgent);
reply = network.get(qheader);
tT.start(Timeout);
q.exec();
if (!tT.isActive()) {
return;
}
tT.stop();
if ((reply->error() != QNetworkReply::NoError)) {
#ifdef DEBUG_URLFACTORY
qDebug() << "Try corrected version withou abort or error:" << reply->errorString();
#endif // DEBUG_URLFACTORY
return;
}
QString html = QString(reply->readAll());
QRegExp reg("\"*https://mts0.google.com/vt/lyrs=m@(\\d*)", Qt::CaseInsensitive);
if (reg.indexIn(html) != -1) {
QStringList gc = reg.capturedTexts();
VersionGoogleMap = QString("m@%1").arg(gc[1]);
VersionGoogleMapChina = VersionGoogleMap;
VersionGoogleMapKorea = VersionGoogleMap;
#ifdef DEBUG_URLFACTORY
qDebug() << "TryCorrectGoogleVersions, VersionGoogleMap: " << VersionGoogleMap;
#endif // DEBUG_URLFACTORY
}
reg = QRegExp("\"*https://mts0.google.com/vt/lyrs=h@(\\d*)", Qt::CaseInsensitive);
if (reg.indexIn(html) != -1) {
QStringList gc = reg.capturedTexts();
VersionGoogleLabels = QString("h@%1").arg(gc[1]);
VersionGoogleLabelsChina = VersionGoogleLabels;
VersionGoogleLabelsKorea = VersionGoogleLabels;
#ifdef DEBUG_URLFACTORY
qDebug() << "TryCorrectGoogleVersions, VersionGoogleLabels: " << VersionGoogleLabels;
#endif // DEBUG_URLFACTORY
}
reg = QRegExp("\"*https://khms0.google.com/kh/v=(\\d*)", Qt::CaseInsensitive);
if (reg.indexIn(html) != -1) {
QStringList gc = reg.capturedTexts();
VersionGoogleSatellite = gc[1];
VersionGoogleSatelliteKorea = VersionGoogleSatellite;
VersionGoogleSatelliteChina = "s@" + VersionGoogleSatellite;
qDebug() << "TryCorrectGoogleVersions, VersionGoogleSatellite: " << VersionGoogleSatellite;
}
reg = QRegExp("\"*https://mts0.google.com/vt/lyrs=t@(\\d*),r@(\\d*)", Qt::CaseInsensitive);
if (reg.indexIn(html) != -1) {
QStringList gc = reg.capturedTexts();
VersionGoogleTerrain = QString("t@%1,r@%2").arg(gc[1]).arg(gc[2]);
VersionGoogleTerrainChina = VersionGoogleTerrain;
VersionGoogleTerrainChina = VersionGoogleTerrain;
#ifdef DEBUG_URLFACTORY
qDebug() << "TryCorrectGoogleVersions, VersionGoogleTerrain: " << VersionGoogleTerrain;
#endif // DEBUG_URLFACTORY
}
reply->deleteLater();
versionRetrieved = true;
}
}
QString UrlFactory::MakeImageUrl(const MapType::Types &type, const Point &pos, const int &zoom, const QString &language)
{
#ifdef DEBUG_URLFACTORY
qDebug() << "Entered MakeImageUrl";
#endif // DEBUG_URLFACTORY
switch (type) {
case MapType::GoogleMap:
{
QString server = "mts";
QString request = "vt";
QString sec1 = ""; // after &x=...
QString sec2 = ""; // after &zoom=...
GetSecGoogleWords(pos, sec1, sec2);
TryCorrectGoogleVersions();
return QString("http://%1%2.google.com/%3/lyrs=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleMap).arg(language).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
}
break;
case MapType::GoogleSatellite:
{
QString server = "khm";
QString request = "kh";
QString sec1 = ""; // after &x=...
QString sec2 = ""; // after &zoom=...
GetSecGoogleWords(pos, sec1, sec2);
TryCorrectGoogleVersions();
return QString("http://%1%2.google.com/%3/v=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleSatellite).arg(language).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
}
break;
case MapType::GoogleLabels:
{
QString server = "mts";
QString request = "vt";
QString sec1 = ""; // after &x=...
QString sec2 = ""; // after &zoom=...
GetSecGoogleWords(pos, sec1, sec2);
TryCorrectGoogleVersions();
return QString("http://%1%2.google.com/%3/lyrs=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleLabels).arg(language).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
没有合适的资源?快使用搜索试试~ 我知道了~
Qt开源地面站库 + 编译好的库
共127个文件
h:54个
cpp:45个
png:12个
需积分: 0 1 下载量 103 浏览量
2024-05-10
15:25:35
上传
评论
收藏 1.41MB RAR 举报
温馨提示
opmapcontrol是一个比较古老的QT开源地面站库,可选择谷歌地图,必应地图, 雅虎地图,GIS等。可直接使用源码,也可以编译生成库进行调用。 本资源包括源码,以及Qt5.15.2 MinGW编译好的库,可直接使用。
资源推荐
资源详情
资源评论
收起资源包目录
Qt开源地面站库 + 编译好的库 (127个子文件)
libopmapwidget.a 754KB
libcore.a 240KB
libinternals.a 176KB
urlfactory.cpp 29KB
core.cpp 21KB
lks94projection.cpp 21KB
opmapwidget.cpp 20KB
mapgraphicitem.cpp 19KB
waypointitem.cpp 18KB
uavitem.cpp 16KB
pureimagecache.cpp 12KB
opmaps.cpp 9KB
pureprojection.cpp 8KB
cache.cpp 6KB
gpsitem.cpp 6KB
mapripper.cpp 5KB
waypointline.cpp 5KB
waypointcircle.cpp 5KB
homeitem.cpp 5KB
tilematrix.cpp 4KB
tilecachequeue.cpp 4KB
mercatorprojectionyandex.cpp 4KB
providerstrings.cpp 3KB
mercatorprojection.cpp 3KB
platecarreeprojectionpergo.cpp 3KB
platecarreeprojection.cpp 3KB
rectangle.cpp 3KB
alllayersoftype.cpp 2KB
kibertilecache.cpp 2KB
languagetype.cpp 2KB
trailitem.cpp 2KB
configuration.cpp 2KB
rawtile.cpp 2KB
cacheitemqueue.cpp 2KB
memorycache.cpp 2KB
point.cpp 2KB
mapripform.cpp 2KB
sizelatlng.cpp 2KB
rectlatlng.cpp 2KB
traillineitem.cpp 2KB
pointlatlng.cpp 2KB
tile.cpp 2KB
pureimage.cpp 1KB
loadtask.cpp 1KB
diagnostics.cpp 1KB
size.cpp 1KB
MouseWheelZoomType.cpp 1KB
placemark.cpp 1KB
opmapwidget.dll 783KB
opmapwidget.h 21KB
opmapwidget.h 21KB
uavitem.h 9KB
core.h 9KB
waypointitem.h 8KB
gpsitem.h 8KB
rectlatlng.h 8KB
mapgraphicitem.h 7KB
geodecoderstatus.h 5KB
configuration.h 5KB
rectangle.h 5KB
pureprojection.h 4KB
maptype.h 4KB
sizelatlng.h 4KB
languagetype.h 3KB
homeitem.h 3KB
urlfactory.h 3KB
pointlatlng.h 3KB
mousewheelzoomtype.h 3KB
opmaps.h 3KB
uavtrailtype.h 3KB
uavmapfollowtype.h 3KB
accessmode.h 3KB
lks94projection.h 3KB
providerstrings.h 3KB
waypointcircle.h 2KB
waypointline.h 2KB
size.h 2KB
point.h 2KB
mercatorprojectionyandex.h 2KB
cacheitemqueue.h 2KB
pureimagecache.h 2KB
platecarreeprojectionpergo.h 2KB
platecarreeprojection.h 2KB
mercatorprojection.h 2KB
mapripper.h 2KB
cache.h 2KB
tile.h 2KB
copyrightstrings.h 2KB
trailitem.h 2KB
traillineitem.h 2KB
rawtile.h 2KB
kibertilecache.h 2KB
loadtask.h 2KB
tilematrix.h 2KB
diagnostics.h 2KB
tilecachequeue.h 2KB
placemark.h 2KB
mapripform.h 2KB
memorycache.h 2KB
pureimage.h 1KB
共 127 条
- 1
- 2
资源评论
taciturn丶
- 粉丝: 220
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Screenshot_2024-05-28-11-40-58-177_com.tencent.mm.jpg
- 基于Dart的Flutter小提琴调音器APP设计源码 - violinhelper
- 基于JavaScript和CSS的随寻订购网页设计源码 - web-order
- 基于MATLAB的声纹识别系统设计源码 - VoiceprintRecognition
- 基于Java的微服务插件集合设计源码 - wsy-plugins
- 基于Vue和微信小程序的监理日志系统设计源码 - supervisionLog
- 基于Java和LCN分布式事务框架的设计源码 - tx-lcn
- 基于Java和JavaScript的茶叶评级管理系统设计源码 - tea
- IMG_5680.JPG
- IMG_0437.jpg
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功