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
d043c24c
Commit
d043c24c
authored
Mar 26, 2014
by
WillRam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Copy of current OpenPilot file. Proxy fixed
Proxy now follows system proxy
parent
49b9228e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
18 deletions
+59
-18
urlfactory.cpp
libs/opmapcontrol/src/core/urlfactory.cpp
+59
-18
No files found.
libs/opmapcontrol/src/core/urlfactory.cpp
View file @
d043c24c
...
...
@@ -37,9 +37,9 @@ namespace core {
/// <summary>
/// timeout for map connections
/// </summary>
QNetworkProxyFactory
::
setUseSystemConfiguration
(
true
);
Proxy
.
setType
(
QNetworkProxy
::
NoProxy
);
/// <summary>
/// Gets or sets the value of the User-agent HTTP header.
/// </summary>
...
...
@@ -54,19 +54,24 @@ namespace core {
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
++
;
}
...
...
@@ -90,9 +95,19 @@ namespace core {
void
UrlFactory
::
TryCorrectGoogleVersions
()
{
static
bool
versionRetrieved
=
false
;
if
(
versionRetrieved
)
{
return
;
}
QMutexLocker
locker
(
&
mutex
);
if
(
CorrectGoogleVersions
&&
!
IsCorrectGoogleVersions
())
{
QNetworkReply
*
reply
;
QNetworkRequest
qheader
;
QNetworkAccessManager
network
;
...
...
@@ -106,8 +121,8 @@ namespace core {
#ifdef DEBUG_URLFACTORY
qDebug
()
<<
"Correct GoogleVersion"
;
#endif //DEBUG_URLFACTORY
setIsCorrectGoogleVersions
(
true
);
QString
url
=
"http://maps.google.com"
;
//
setIsCorrectGoogleVersions(true);
QString
url
=
"http
s
://maps.google.com"
;
qheader
.
setUrl
(
QUrl
(
url
));
qheader
.
setRawHeader
(
"User-Agent"
,
UserAgent
);
...
...
@@ -116,6 +131,7 @@ namespace core {
q
.
exec
();
if
(
!
tT
.
isActive
())
return
;
tT
.
stop
();
if
(
(
reply
->
error
()
!=
QNetworkReply
::
NoError
))
{
...
...
@@ -125,28 +141,30 @@ namespace core {
return
;
}
QString
html
=
QString
(
reply
->
readAll
());
QRegExp
reg
(
"
\"
*http
://mt
0.google.com/vt/lyrs=m@(
\\
d*)"
,
Qt
::
CaseInsensitive
);
QRegExp
reg
(
"
\"
*http
s://mts
0.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
;
#ifdef DEBUG_URLFACTORY
qDebug
()
<<
"TryCorrectGoogleVersions, VersionGoogleMap: "
<<
VersionGoogleMap
;
#endif //DEBUG_URLFACTORY
}
reg
=
QRegExp
(
"
\"
*http://mt
0.google.com/vt/lyrs=h@(
\\
d*)"
,
Qt
::
CaseInsensitive
);
reg
=
QRegExp
(
"
\"
*https://mts
0.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
;
#ifdef DEBUG_URLFACTORY
qDebug
()
<<
"TryCorrectGoogleVersions, VersionGoogleLabels: "
<<
VersionGoogleLabels
;
#endif //DEBUG_URLFACTORY
}
reg
=
QRegExp
(
"
\"
*http
://khm
0.google.com/kh/v=(
\\
d*)"
,
Qt
::
CaseInsensitive
);
reg
=
QRegExp
(
"
\"
*http
s://khms
0.google.com/kh/v=(
\\
d*)"
,
Qt
::
CaseInsensitive
);
if
(
reg
.
indexIn
(
html
)
!=-
1
)
{
QStringList
gc
=
reg
.
capturedTexts
();
...
...
@@ -157,18 +175,20 @@ namespace core {
qDebug
()
<<
"TryCorrectGoogleVersions, VersionGoogleSatellite: "
<<
VersionGoogleSatellite
;
}
reg
=
QRegExp
(
"
\"
*http
://mt
0.google.com/vt/lyrs=t@(
\\
d*),r@(
\\
d*)"
,
Qt
::
CaseInsensitive
);
reg
=
QRegExp
(
"
\"
*http
s://mts
0.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
;
#ifdef DEBUG_URLFACTORY
qDebug
()
<<
"TryCorrectGoogleVersions, VersionGoogleTerrain: "
<<
VersionGoogleTerrain
;
#endif //DEBUG_URLFACTORY
}
reply
->
deleteLater
();
}
}
...
...
@@ -180,50 +200,52 @@ namespace core {
#endif //DEBUG_URLFACTORY
switch
(
type
)
{
case
MapType
:
:
GoogleMap
:
{
QString
server
=
"mt"
;
QString
server
=
"mt
s
"
;
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
);
return
QString
(
"http
s
://%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
server
=
"khm
s
"
;
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
);
return
QString
(
"https://%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
=
"mt"
;
QString
server
=
"mt
s
"
;
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
);
return
QString
(
"http
s
://%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
);
}
break
;
case
MapType
:
:
GoogleTerrain
:
{
QString
server
=
"mt"
;
QString
server
=
"mt
s
"
;
QString
request
=
"vt"
;
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
(
VersionGoogleTerrain
).
arg
(
language
).
arg
(
pos
.
X
()).
arg
(
sec1
).
arg
(
pos
.
Y
()).
arg
(
zoom
).
arg
(
sec2
);
return
QString
(
"http
s
://%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
(
VersionGoogleTerrain
).
arg
(
language
).
arg
(
pos
.
X
()).
arg
(
sec1
).
arg
(
pos
.
Y
()).
arg
(
zoom
).
arg
(
sec2
);
}
break
;
case
MapType
:
:
GoogleMapChina
:
...
...
@@ -286,9 +308,13 @@ namespace core {
QString
sec2
=
""
;
// after &zoom=...
GetSecGoogleWords
(
pos
,
sec1
,
sec2
);
//http://mt3.gmaptiles.co.kr/mt/v=kr1.11&hl=lt&x=109&y=49&z=7&s=
QString
ret
=
QString
(
"http://%1%2.gmaptiles.co.kr/%3/v=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10"
).
arg
(
server
).
arg
(
GetServerNum
(
pos
,
4
)).
arg
(
request
).
arg
(
VersionGoogleMapKorea
).
arg
(
language
).
arg
(
pos
.
X
()).
arg
(
sec1
).
arg
(
pos
.
Y
()).
arg
(
zoom
).
arg
(
sec2
);
QString
ret
=
QString
(
"https://%1%2.gmaptiles.co.kr/%3/v=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10"
).
arg
(
server
).
arg
(
GetServerNum
(
pos
,
4
)).
arg
(
request
).
arg
(
VersionGoogleMapKorea
).
arg
(
language
).
arg
(
pos
.
X
()).
arg
(
sec1
).
arg
(
pos
.
Y
()).
arg
(
zoom
).
arg
(
sec2
);
return
ret
;
}
break
;
...
...
@@ -300,6 +326,7 @@ namespace core {
QString
sec2
=
""
;
// after &zoom=...
GetSecGoogleWords
(
pos
,
sec1
,
sec2
);
// http://khm1.google.co.kr/kh/v=54&x=109&y=49&z=7&s=
return
QString
(
"http://%1%2.google.co.kr/%3/v=%4&x=%5%6&y=%7&z=%8&s=%9"
).
arg
(
server
).
arg
(
GetServerNum
(
pos
,
4
)).
arg
(
request
).
arg
(
VersionGoogleSatelliteKorea
).
arg
(
pos
.
X
()).
arg
(
sec1
).
arg
(
pos
.
Y
()).
arg
(
zoom
).
arg
(
sec2
);
...
...
@@ -313,9 +340,10 @@ namespace core {
QString
sec2
=
""
;
// after &zoom=...
GetSecGoogleWords
(
pos
,
sec1
,
sec2
);
// http://mt1.gmaptiles.co.kr/mt/v=kr1t.11&hl=lt&x=109&y=50&z=7&s=G
return
QString
(
"http://%1%2.gmaptiles.co.kr/%3/v=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10"
).
arg
(
server
).
arg
(
GetServerNum
(
pos
,
4
)).
arg
(
request
).
arg
(
VersionGoogleLabelsKorea
).
arg
(
language
).
arg
(
pos
.
X
()).
arg
(
sec1
).
arg
(
pos
.
Y
()).
arg
(
zoom
).
arg
(
sec2
);
return
QString
(
"http
s
://%1%2.gmaptiles.co.kr/%3/v=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10"
).
arg
(
server
).
arg
(
GetServerNum
(
pos
,
4
)).
arg
(
request
).
arg
(
VersionGoogleLabelsKorea
).
arg
(
language
).
arg
(
pos
.
X
()).
arg
(
sec1
).
arg
(
pos
.
Y
()).
arg
(
zoom
).
arg
(
sec2
);
}
break
;
case
MapType
:
:
YahooMap
:
...
...
@@ -487,12 +515,14 @@ namespace core {
sec2
=
SecGoogleWord
.
left
(
seclen
);
if
(
pos
.
Y
()
>=
10000
&&
pos
.
Y
()
<
100000
)
{
sec1
=
"&s="
;
}
}
QString
UrlFactory
::
MakeGeocoderUrl
(
QString
keywords
)
{
QString
key
=
keywords
.
replace
(
' '
,
'+'
);
return
QString
(
"http://maps.google.com/maps/geo?q=%1&output=csv&key=%2"
).
arg
(
key
).
arg
(
GoogleMapsAPIKey
);
}
QString
UrlFactory
::
MakeReverseGeocoderUrl
(
internals
::
PointLatLng
&
pt
,
const
QString
&
language
)
...
...
@@ -542,7 +572,9 @@ namespace core {
#endif //DEBUG_URLFACTORY
QTime
time
;
time
.
start
();
while
(
(
!
(
reply
->
isFinished
())
||
(
time
.
elapsed
()
>
(
6
*
Timeout
)))
){
QCoreApplication
::
processEvents
(
QEventLoop
::
AllEvents
);}
#ifdef DEBUG_URLFACTORY
qDebug
()
<<
"Finished?"
<<
reply
->
error
()
<<
" abort?"
<<
(
time
.
elapsed
()
>
Timeout
*
6
);
#endif //DEBUG_URLFACTORY
...
...
@@ -563,6 +595,7 @@ namespace core {
// cache geocoding
if
(
useCache
&&
geo
.
startsWith
(
"200"
))
{
Cache
::
Instance
()
->
CacheGeocoder
(
urlEnd
,
geo
);
}
}
...
...
@@ -577,9 +610,11 @@ namespace core {
QStringList
values
=
geo
.
split
(
','
);
if
(
values
.
count
()
==
4
)
{
status
=
(
GeoCoderStatusCode
::
Types
)
QString
(
values
[
0
]).
toInt
();
if
(
status
==
GeoCoderStatusCode
::
G_GEO_SUCCESS
)
{
double
lat
=
QString
(
values
[
2
]).
toDouble
();
double
lng
=
QString
(
values
[
3
]).
toDouble
();
...
...
@@ -602,6 +637,7 @@ namespace core {
{
Placemark
ret
(
""
);
#ifdef DEBUG_URLFACTORY
qDebug
()
<<
"Entered GetPlacemarkFromReverseGeocoderUrl:"
;
#endif //DEBUG_URLFACTORY
...
...
@@ -636,7 +672,9 @@ namespace core {
#endif //DEBUG_URLFACTORY
QTime
time
;
time
.
start
();
while
(
(
!
(
reply
->
isFinished
())
||
(
time
.
elapsed
()
>
(
6
*
Timeout
)))
){
QCoreApplication
::
processEvents
(
QEventLoop
::
AllEvents
);}
#ifdef DEBUG_URLFACTORY
qDebug
()
<<
"Finished?"
<<
reply
->
error
()
<<
" abort?"
<<
(
time
.
elapsed
()
>
Timeout
*
6
);
#endif //DEBUG_URLFACTORY
...
...
@@ -660,6 +698,7 @@ namespace core {
// cache geocoding
if
(
useCache
&&
reverse
.
startsWith
(
"200"
))
{
Cache
::
Instance
()
->
CachePlacemark
(
urlEnd
,
reverse
);
}
}
...
...
@@ -672,6 +711,7 @@ namespace core {
// false: 602,0,0,0
if
(
reverse
.
startsWith
(
"200"
))
{
QString
acc
=
reverse
.
left
(
reverse
.
indexOf
(
'\"'
));
ret
=
Placemark
(
reverse
.
remove
(
reverse
.
indexOf
(
'\"'
)));
ret
.
SetAccuracy
((
int
)
((
(
QString
)
acc
.
split
(
','
)[
1
]).
toInt
())
);
...
...
@@ -690,6 +730,7 @@ namespace core {
double
a
=
pow
(
sin
(
dLatitude
/
2
),
2
)
+
cos
(
dLat1InRad
)
*
cos
(
dLat2InRad
)
*
pow
(
sin
(
dLongitude
/
2
),
2
);
double
c
=
2
*
atan2
(
sqrt
(
a
),
sqrt
(
1
-
a
));
double
dDistance
=
EarthRadiusKm
*
c
;
return
dDistance
;
}
}
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