-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathQGVLayerGoogle.cpp
More file actions
110 lines (98 loc) · 3.41 KB
/
Copy pathQGVLayerGoogle.cpp
File metadata and controls
110 lines (98 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/***************************************************************************
* QGeoView is a Qt / C ++ widget for visualizing geographic data.
* Copyright (C) 2018-2025 Andrey Yaroshenko.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License
* along with this program; if not, see https://www.gnu.org/licenses.
****************************************************************************/
#include "QGVLayerGoogle.h"
#include <QtMath>
namespace {
// clang-format off
const QMap<QGV::TilesType, QStringList> URLTemplates = {
{QGV::TilesType::Satellite, {
"https://mts0.google.com/vt/lyrs=s@186112443&hl=${lcl}&x=${x}&y=${y}&z=${z}&s=Galile",
"https://mts1.google.com/vt/lyrs=s@186112443&hl=${lcl}&x=${x}&y=${y}&z=${z}&s=Galile",
"https://mts2.google.com/vt/lyrs=s@186112443&hl=${lcl}&x=${x}&y=${y}&z=${z}&s=Galile",
}
},
{QGV::TilesType::Schema, {
"http://mt1.google.com/vt/lyrs=m@110&hl=${lcl}&x=${x}&y=${y}&z=${z}",
"http://mt2.google.com/vt/lyrs=m@110&hl=${lcl}&x=${x}&y=${y}&z=${z}",
"http://mt3.google.com/vt/lyrs=m@110&hl=${lcl}&x=${x}&y=${y}&z=${z}",
}
},
{QGV::TilesType::Hybrid, {
"http://mt1.google.com/vt/lyrs=s,m@110&hl=${lcl}&x=${x}&y=${y}&z=${z}",
"http://mt2.google.com/vt/lyrs=s,m@110&hl=${lcl}&x=${x}&y=${y}&z=${z}",
"http://mt3.google.com/vt/lyrs=s,m@110&hl=${lcl}&x=${x}&y=${y}&z=${z}",
}
},
};
// clang-format on
}
QGVLayerGoogle::QGVLayerGoogle(QGV::TilesType type, QLocale locale, int serverNumber)
: mType(type)
, mLocale(locale)
, mServerNumber(serverNumber)
{
createName();
setDescription("Copyrights ©Google");
}
void QGVLayerGoogle::setType(QGV::TilesType type)
{
mType = type;
createName();
}
void QGVLayerGoogle::setLocale(const QLocale& locale)
{
mLocale = locale;
createName();
}
QGV::TilesType QGVLayerGoogle::getType() const
{
return mType;
}
QLocale QGVLayerGoogle::getLocale() const
{
return mLocale;
}
void QGVLayerGoogle::createName()
{
// clang-format off
const QMap<QGV::TilesType, QString> adapter = {
{ QGV::TilesType::Satellite, "QGV::Satellite" },
{ QGV::TilesType::Schema, "QGV::Schema" },
{ QGV::TilesType::Hybrid, "QGV::Hybrid" },
};
// clang-format on
setName("Google Maps (" + adapter[mType] + " " + mLocale.name() + ")");
}
int QGVLayerGoogle::minZoomlevel() const
{
return 0;
}
int QGVLayerGoogle::maxZoomlevel() const
{
return 21;
}
QString QGVLayerGoogle::tilePosToUrl(const QGV::GeoTilePos& tilePos) const
{
const QStringList& list = URLTemplates[mType];
QString url = list.value(mServerNumber).toLower();
url.replace("${lcl}", mLocale.name());
url.replace("${z}", QString::number(tilePos.zoom()));
url.replace("${x}", QString::number(tilePos.pos().x()));
url.replace("${y}", QString::number(tilePos.pos().y()));
return url;
}