5
5
6
6
GeoFileTileCache::GeoFileTileCache (const QList<QGeoMapType>& mapTypes,
7
7
int scaleFactor,
8
+ bool enableLogging,
8
9
const QString& directory,
9
10
QObject* parent)
10
11
: QGeoFileTileCache(directory, parent)
12
+ , m_enableLogging(enableLogging)
11
13
, m_hasCacheDirectory(!directory.isEmpty())
12
14
, m_mapTypes(mapTypes)
13
15
{
@@ -58,72 +60,90 @@ QGeoTileSpec GeoFileTileCache::filenameToTileSpec(const QString& filename) const
58
60
// @See QGeoFileTileCacheMapBox for more information for this function
59
61
// General scheme is: plugin_name - map_type - zoom - x - y - @scale.png
60
62
// For now the cached tiles names look like this:
61
- // basemap_pix4d_100-mapbox.streets-satellite- [email protected] or
62
- // basemap_pix4d_100-mapbox.satellite [email protected]
63
+ // basemap_pix4d_100-ck8zzfxb30vwp1jo04yktjtbg- [email protected] or
64
+ // basemap_pix4d_100-ck8zz9gpq0vty1ip30bji3b5a [email protected]
63
65
// basemap_pix4d_100 = plugin name
64
- // mapbox.streets-satellite / mapbox.satellite = map type
66
+ // ck8zzfxb30vwp1jo04yktjtbg = streets-satellite type map
67
+ // ck8zz9gpq0vty1ip30bji3b5a = street type map
65
68
// 13 = zoom
66
69
// 4401-2685 = x, y
67
70
68
71
if (!m_hasCacheDirectory)
69
72
{
73
+ if (m_enableLogging)
74
+ {
75
+ qWarning () << " GeoFileTileCache: No cache directory." ;
76
+ }
70
77
return QGeoTileSpec ();
71
78
}
72
79
73
80
const QStringList parts = filename.split (' .' );
74
- if (parts.length () != 3 ) // 3 because the map name has always a dot in it.
81
+ if (parts.length () != 2 ) // 2 because the map name has always a dot in it.
75
82
{
83
+ if (m_enableLogging)
84
+ {
85
+ qWarning () << " GeoFileTileCache: This file doesn't have a file extension." ;
86
+ }
76
87
return QGeoTileSpec ();
77
88
}
78
89
79
- // name = mapbox_pix4d_100-mapbox.streets-satellite -13-4401-2685-@2x (no extension)
80
- const QString name = parts.at (0 ) + " . " + parts. at ( 1 ) ;
90
+ // name = mapbox_pix4d_100-ck8zzfxb30vwp1jo04yktjtbg -13-4401-2685-@2x (no extension)
91
+ const QString name = parts.at (0 );
81
92
const QStringList fields = name.split (' -' );
82
93
83
94
// must be at least 6 different fields
84
95
if (fields.length () < 6 )
85
96
{
97
+ if (m_enableLogging)
98
+ {
99
+ qWarning () << " GeoFileTileCache: The file name without extension doesn't have 6 different fields." ;
100
+ }
86
101
return QGeoTileSpec ();
87
102
}
88
103
89
104
const int length = fields.length ();
90
105
const int scaleIdx = fields.last ().indexOf (" @" );
91
106
if (scaleIdx < 0 || fields.last ().size () <= (scaleIdx + 2 ))
92
107
{
108
+ if (m_enableLogging)
109
+ {
110
+ qWarning () << " GeoFileTileCache: Scale is not last data in name." ;
111
+ }
93
112
return QGeoTileSpec ();
94
113
}
95
114
96
115
int scaleFactor = fields.last ()[scaleIdx + 1 ].digitValue ();
97
116
if (scaleFactor != m_scaleFactor)
98
117
{
118
+ if (m_enableLogging)
119
+ {
120
+ qWarning () << " GeoFileTileCache: The last fields doesn't have scale factor." ;
121
+ }
99
122
return QGeoTileSpec ();
100
123
}
101
124
102
125
QList<int > numbers;
103
- int startIndex = 2 ;
104
-
105
- // try to combine the fields from [1] and [2]. In case the map type
106
- // contains a '-' in it (e.g. mapbox.streets-satellite vs mapbox.satellite)
107
- QString pluginName = fields.at (1 );
108
- if (m_mapNameToId.find (pluginName + " -" + fields.at (2 )) != m_mapNameToId.end ())
109
- {
110
- pluginName += " -" + fields.at (2 );
111
- startIndex = 3 ;
112
- }
113
-
114
- for (int i = startIndex; i < length - 1 ; ++i) // skipping -@_X
126
+ for (int i = 2 ; i < length - 1 ; ++i) // skipping -@_X
115
127
{
116
128
bool ok = false ;
117
129
const int value = fields.at (i).toInt (&ok);
118
130
if (!ok)
119
131
{
132
+ if (m_enableLogging)
133
+ {
134
+ qWarning () << " GeoFileTileCache: The value of zoom/x/y must be integer." ;
135
+ }
120
136
return QGeoTileSpec ();
121
137
}
122
138
numbers.append (value);
123
139
}
124
140
125
141
if (numbers.length () < 3 )
126
142
{
143
+ if (m_enableLogging)
144
+ {
145
+ qWarning () << " GeoFileTileCache: The cache file must have zoom/x/y value." ;
146
+ }
127
147
return QGeoTileSpec ();
128
148
}
129
149
@@ -134,5 +154,5 @@ QGeoTileSpec GeoFileTileCache::filenameToTileSpec(const QString& filename) const
134
154
}
135
155
136
156
return QGeoTileSpec (
137
- fields.at (0 ), m_mapNameToId[pluginName ], numbers.at (0 ), numbers.at (1 ), numbers.at (2 ), numbers.at (3 ));
138
- }
157
+ fields.at (0 ), m_mapNameToId[fields. at ( 1 ) ], numbers.at (0 ), numbers.at (1 ), numbers.at (2 ), numbers.at (3 ));
158
+ }
0 commit comments