Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
40df5080
Commit
40df5080
authored
Apr 10, 2015
by
Don Gagne
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1439 from dogmaphobic/mapping
Fixed thread race condition.
parents
1e2d7087
8d95ffff
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
111 additions
and
84 deletions
+111
-84
OpenPilotMaps.cc
src/QtLocationPlugin/OpenPilotMaps.cc
+83
-70
OpenPilotMaps.h
src/QtLocationPlugin/OpenPilotMaps.h
+17
-12
qgeotilefetcherqgc.cpp
src/QtLocationPlugin/qgeotilefetcherqgc.cpp
+9
-1
qgeotilefetcherqgc.h
src/QtLocationPlugin/qgeotilefetcherqgc.h
+2
-1
No files found.
src/QtLocationPlugin/OpenPilotMaps.cc
View file @
40df5080
...
...
@@ -37,7 +37,7 @@ This file is part of the QGROUNDCONTROL project
namespace
OpenPilot
{
const
QString
ProviderStrings
::
l
evelsForSigPacSpainMap
[]
=
const
QString
ProviderStrings
::
kL
evelsForSigPacSpainMap
[]
=
{
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"MTNSIGPAC"
,
"MTN2000"
,
"MTN2000"
,
"MTN2000"
,
"MTN2000"
,
"MTN2000"
,
...
...
@@ -45,15 +45,13 @@ const QString ProviderStrings::levelsForSigPacSpainMap[] =
"MTN25"
,
"MTN25"
,
"ORTOFOTOS"
,
"ORTOFOTOS"
,
"ORTOFOTOS"
,
"ORTOFOTOS"
};
const
double
UrlFactory
::
EarthRadiusKm
=
6378.137
;
// WGS-84
ProviderStrings
::
ProviderStrings
()
{
// Google version strings
VersionGoogleMap
=
"m@
113
"
;
VersionGoogleSatellite
=
"s"
;
VersionGoogleLabels
=
"h@2
21
000000"
;
VersionGoogleTerrain
=
"t@132,r@2
49
000000"
;
VersionGoogleMap
=
"m@
296306248
"
;
VersionGoogleSatellite
=
"s
@168
"
;
VersionGoogleLabels
=
"h@2
96
000000"
;
VersionGoogleTerrain
=
"t@132,r@2
96
000000"
;
SecGoogleWord
=
"Galileo"
;
// Google (China) version strings
...
...
@@ -91,18 +89,18 @@ ProviderStrings::ProviderStrings()
BingMapsClientToken
=
""
;
}
UrlFactory
::
UrlFactory
()
:
_isCorrectedGoogleVersions
(
false
)
,
_correctGoogleVersions
(
true
)
,
_timeout
(
5
*
1000
)
UrlFactory
::
UrlFactory
(
QNetworkAccessManager
*
network
)
:
_timeout
(
5
*
1000
)
,
_googleVersionRetrieved
(
false
)
,
_network
(
network
)
,
_googleReply
(
NULL
)
{
Proxy
.
setType
(
QNetworkProxy
::
NoProxy
);
UserAgent
=
"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7"
;
}
UrlFactory
::~
UrlFactory
()
{
if
(
_googleReply
)
_googleReply
->
deleteLater
();
}
QString
UrlFactory
::
_tileXYToQuadKey
(
const
int
&
tileX
,
const
int
&
tileY
,
const
int
&
levelOfDetail
)
const
...
...
@@ -128,38 +126,28 @@ int UrlFactory::_getServerNum(const QPoint &pos, const int &max) const
return
(
pos
.
x
()
+
2
*
pos
.
y
())
%
max
;
}
void
UrlFactory
::
_
tryCorrectGoogleVersions
(
)
void
UrlFactory
::
_
networkReplyError
(
QNetworkReply
::
NetworkError
error
)
{
static
bool
_kVersionRetrieved
=
false
;
if
(
_kVersionRetrieved
)
{
return
;
}
QMutexLocker
locker
(
&
mutex
);
if
(
_correctGoogleVersions
&&
!
_isCorrectedGoogleVersions
)
{
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
);
_isCorrectedGoogleVersions
=
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
;
qWarning
()
<<
"Could not connect to google maps. Error:"
<<
error
;
if
(
_googleReply
)
{
_googleReply
->
deleteLater
();
_googleReply
=
NULL
;
}
tT
.
stop
();
if
((
reply
->
error
()
!=
QNetworkReply
::
NoError
))
{
}
void
UrlFactory
::
_replyDestroyed
()
{
_googleReply
=
NULL
;
}
void
UrlFactory
::
_googleVersionCompleted
()
{
if
(
!
_googleReply
||
(
_googleReply
->
error
()
!=
QNetworkReply
::
NoError
))
{
qDebug
()
<<
"Error collecting Google maps version info"
;
return
;
}
QString
html
=
QString
(
r
eply
->
readAll
());
QString
html
=
QString
(
_googleR
eply
->
readAll
());
QRegExp
reg
(
"
\"
*https://mts0.google.com/vt/lyrs=m@(
\\
d*)"
,
Qt
::
CaseInsensitive
);
if
(
reg
.
indexIn
(
html
)
!=
-
1
)
{
QStringList
gc
=
reg
.
capturedTexts
();
...
...
@@ -188,8 +176,33 @@ void UrlFactory::_tryCorrectGoogleVersions()
VersionGoogleTerrainChina
=
VersionGoogleTerrain
;
VersionGoogleTerrainChina
=
VersionGoogleTerrain
;
}
reply
->
deleteLater
();
_kVersionRetrieved
=
true
;
_googleReply
->
deleteLater
();
_googleReply
=
NULL
;
}
void
UrlFactory
::
_tryCorrectGoogleVersions
()
{
QMutexLocker
locker
(
&
_googleVersionMutex
);
if
(
_googleVersionRetrieved
)
{
return
;
}
_googleVersionRetrieved
=
true
;
if
(
_network
)
{
QNetworkRequest
qheader
;
QNetworkProxy
proxy
=
_network
->
proxy
();
QNetworkProxy
tProxy
;
tProxy
.
setType
(
QNetworkProxy
::
NoProxy
);
_network
->
setProxy
(
tProxy
);
QString
url
=
"https://maps.google.com/maps?output=classic"
;
qheader
.
setUrl
(
QUrl
(
url
));
QByteArray
userAgent
=
"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7"
;
qheader
.
setRawHeader
(
"User-Agent"
,
userAgent
);
_googleReply
=
_network
->
get
(
qheader
);
connect
(
_googleReply
,
SIGNAL
(
finished
()),
this
,
SLOT
(
_googleVersionCompleted
()));
connect
(
_googleReply
,
SIGNAL
(
error
(
QNetworkReply
::
NetworkError
)),
this
,
SLOT
(
_networkReplyError
(
QNetworkReply
::
NetworkError
)));
connect
(
_googleReply
,
SIGNAL
(
destroyed
()),
this
,
SLOT
(
_replyDestroyed
()));
_network
->
setProxy
(
proxy
);
}
}
...
...
@@ -459,7 +472,7 @@ QString UrlFactory::makeImageUrl(const MapType &type, const QPoint& pos, const i
break
;
case
SigPacSpainMap
:
{
return
QString
(
"http://sigpac.mapa.es/kmlserver/raster/%1@3785/%2.%3.%4.img"
).
arg
(
l
evelsForSigPacSpainMap
[
zoom
]).
arg
(
zoom
).
arg
(
pos
.
x
()).
arg
((
2
<<
(
zoom
-
1
))
-
pos
.
y
()
-
1
);
return
QString
(
"http://sigpac.mapa.es/kmlserver/raster/%1@3785/%2.%3.%4.img"
).
arg
(
kL
evelsForSigPacSpainMap
[
zoom
]).
arg
(
zoom
).
arg
(
pos
.
x
()).
arg
((
2
<<
(
zoom
-
1
))
-
pos
.
y
()
-
1
);
}
break
;
case
YandexMapRu
:
...
...
src/QtLocationPlugin/OpenPilotMaps.h
View file @
40df5080
...
...
@@ -35,6 +35,7 @@ This file is part of the QGROUNDCONTROL project
#include <QPoint>
#include <QByteArray>
#include <QNetworkProxy>
#include <QNetworkReply>
#include <QMutex>
namespace
OpenPilot
{
...
...
@@ -88,10 +89,11 @@ enum MapType
YandexMapRu
=
5000
};
class
ProviderStrings
{
class
ProviderStrings
:
public
QObject
{
Q_OBJECT
public:
ProviderStrings
();
static
const
QString
l
evelsForSigPacSpainMap
[];
static
const
QString
kL
evelsForSigPacSpainMap
[];
QString
GoogleMapsAPIKey
;
// Google version strings
QString
VersionGoogleMap
;
...
...
@@ -127,29 +129,32 @@ public:
QString
BingMapsClientToken
;
};
class
UrlFactory
:
public
QObject
,
public
ProviderStrings
{
class
UrlFactory
:
public
ProviderStrings
{
Q_OBJECT
public:
QByteArray
UserAgent
;
QNetworkProxy
Proxy
;
UrlFactory
();
UrlFactory
(
QNetworkAccessManager
*
network
);
~
UrlFactory
();
QString
makeImageUrl
(
const
MapType
&
type
,
const
QPoint
&
pos
,
const
int
&
zoom
,
const
QString
&
language
);
private
slots
:
void
_networkReplyError
(
QNetworkReply
::
NetworkError
error
);
void
_googleVersionCompleted
();
void
_replyDestroyed
();
private:
void
_getSecGoogleWords
(
const
QPoint
&
pos
,
QString
&
sec1
,
QString
&
sec2
);
int
_getServerNum
(
const
QPoint
&
pos
,
const
int
&
max
)
const
;
void
_tryCorrectGoogleVersions
();
QString
_tileXYToQuadKey
(
const
int
&
tileX
,
const
int
&
tileY
,
const
int
&
levelOfDetail
)
const
;
bool
_isCorrectedGoogleVersions
;
bool
_correctGoogleVersions
;
int
_timeout
;
QMutex
mutex
;
static
const
double
EarthRadiusKm
;
bool
_googleVersionRetrieved
;
QNetworkAccessManager
*
_network
;
QNetworkReply
*
_googleReply
;
QMutex
_googleVersionMutex
;
QByteArray
_userAgent
;
};
}
...
...
src/QtLocationPlugin/qgeotilefetcherqgc.cpp
View file @
40df5080
...
...
@@ -56,11 +56,19 @@ QGeoTileFetcherQGC::QGeoTileFetcherQGC(QGeoTiledMappingManagerEngine *parent)
:
QGeoTileFetcher
(
parent
)
,
m_networkManager
(
new
QNetworkAccessManager
(
this
))
,
m_userAgent
(
"Qt Application"
)
,
m_UrlFactory
(
NULL
)
{
QStringList
langs
=
QLocale
::
system
().
uiLanguages
();
if
(
langs
.
length
()
>
0
)
{
m_Language
=
langs
[
0
];
}
m_UrlFactory
=
new
OpenPilot
::
UrlFactory
(
m_networkManager
);
}
QGeoTileFetcherQGC
::~
QGeoTileFetcherQGC
()
{
if
(
m_UrlFactory
)
delete
m_UrlFactory
;
}
void
QGeoTileFetcherQGC
::
setUserAgent
(
const
QByteArray
&
userAgent
)
...
...
@@ -71,7 +79,7 @@ void QGeoTileFetcherQGC::setUserAgent(const QByteArray &userAgent)
QGeoTiledMapReply
*
QGeoTileFetcherQGC
::
getTileImage
(
const
QGeoTileSpec
&
spec
)
{
QNetworkRequest
request
;
QString
url
=
m_UrlFactory
.
makeImageUrl
((
OpenPilot
::
MapType
)
spec
.
mapId
(),
QPoint
(
spec
.
x
(),
spec
.
y
()),
spec
.
zoom
(),
m_Language
);
QString
url
=
m_UrlFactory
->
makeImageUrl
((
OpenPilot
::
MapType
)
spec
.
mapId
(),
QPoint
(
spec
.
x
(),
spec
.
y
()),
spec
.
zoom
(),
m_Language
);
request
.
setUrl
(
QUrl
(
url
));
request
.
setRawHeader
(
"User-Agent"
,
m_userAgent
);
...
...
src/QtLocationPlugin/qgeotilefetcherqgc.h
View file @
40df5080
...
...
@@ -60,6 +60,7 @@ class QGeoTileFetcherQGC : public QGeoTileFetcher
public:
explicit
QGeoTileFetcherQGC
(
QGeoTiledMappingManagerEngine
*
parent
=
0
);
~
QGeoTileFetcherQGC
();
void
setUserAgent
(
const
QByteArray
&
userAgent
);
...
...
@@ -67,7 +68,7 @@ private:
QGeoTiledMapReply
*
getTileImage
(
const
QGeoTileSpec
&
spec
);
QNetworkAccessManager
*
m_networkManager
;
QByteArray
m_userAgent
;
OpenPilot
::
UrlFactory
m_UrlFactory
;
OpenPilot
::
UrlFactory
*
m_UrlFactory
;
QString
m_Language
;
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment