summaryrefslogtreecommitdiff
path: root/src/plugins/geoservices/osm
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/geoservices/osm')
-rw-r--r--src/plugins/geoservices/osm/osm.pro4
-rw-r--r--src/plugins/geoservices/osm/providers/5.8/cycle8
-rw-r--r--src/plugins/geoservices/osm/providers/5.8/hiking9
-rw-r--r--src/plugins/geoservices/osm/providers/5.8/night-transit9
-rw-r--r--src/plugins/geoservices/osm/providers/5.8/satellite10
-rw-r--r--src/plugins/geoservices/osm/providers/5.8/street9
-rw-r--r--src/plugins/geoservices/osm/providers/5.8/terrain9
-rw-r--r--src/plugins/geoservices/osm/providers/5.8/transit9
-rw-r--r--src/plugins/geoservices/osm/qgeofiletilecacheosm.cpp131
-rw-r--r--src/plugins/geoservices/osm/qgeofiletilecacheosm.h71
-rw-r--r--src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp39
-rw-r--r--src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.h2
12 files changed, 305 insertions, 5 deletions
diff --git a/src/plugins/geoservices/osm/osm.pro b/src/plugins/geoservices/osm/osm.pro
index 56f4cb33..86a62744 100644
--- a/src/plugins/geoservices/osm/osm.pro
+++ b/src/plugins/geoservices/osm/osm.pro
@@ -1,6 +1,6 @@
TARGET = qtgeoservices_osm
-QT += location-private positioning-private network
+QT += location-private positioning-private network concurrent
HEADERS += \
qgeoserviceproviderpluginosm.h \
@@ -15,6 +15,7 @@ HEADERS += \
qplacesearchreplyosm.h \
qplacecategoriesreplyosm.h \
qgeotiledmaposm.h \
+ qgeofiletilecacheosm.h \
qgeotileproviderosm.h
SOURCES += \
@@ -30,6 +31,7 @@ SOURCES += \
qplacesearchreplyosm.cpp \
qplacecategoriesreplyosm.cpp \
qgeotiledmaposm.cpp \
+ qgeofiletilecacheosm.cpp \
qgeotileproviderosm.cpp
diff --git a/src/plugins/geoservices/osm/providers/5.8/cycle b/src/plugins/geoservices/osm/providers/5.8/cycle
new file mode 100644
index 00000000..5e37aab2
--- /dev/null
+++ b/src/plugins/geoservices/osm/providers/5.8/cycle
@@ -0,0 +1,8 @@
+{
+ "UrlTemplate" : "http://a.tile.thunderforest.com/cycle/%z/%x/%y.png",
+ "ImageFormat" : "png",
+ "QImageFormat" : "Indexed8",
+ "ID" : "thf-cycle",
+ "MapCopyRight" : "<a href='http://www.thunderforest.com/'>Thunderforest</a>",
+ "DataCopyRight" : "<a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a> contributors"
+}
diff --git a/src/plugins/geoservices/osm/providers/5.8/hiking b/src/plugins/geoservices/osm/providers/5.8/hiking
new file mode 100644
index 00000000..1bb182e4
--- /dev/null
+++ b/src/plugins/geoservices/osm/providers/5.8/hiking
@@ -0,0 +1,9 @@
+{
+ "UrlTemplate" : "http://b.tiles.wmflabs.org/hikebike/%z/%x/%y.png",
+ "ImageFormat" : "png",
+ "QImageFormat" : "Indexed8",
+ "ID" : "wmf-hike",
+ "MaximumZoomLevel" : 18,
+ "MapCopyRight" : "<a href='https://wikimediafoundation.org/wiki/Terms_of_Use'>WikiMedia Foundation</a>",
+ "DataCopyRight" : "<a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a> contributors"
+}
diff --git a/src/plugins/geoservices/osm/providers/5.8/night-transit b/src/plugins/geoservices/osm/providers/5.8/night-transit
new file mode 100644
index 00000000..988a096a
--- /dev/null
+++ b/src/plugins/geoservices/osm/providers/5.8/night-transit
@@ -0,0 +1,9 @@
+{
+ "UrlTemplate" : "http://a.tile.thunderforest.com/transport-dark/%z/%x/%y.png",
+ "ImageFormat" : "png",
+ "QImageFormat" : "Indexed8",
+ "ID" : "thf-nighttransit",
+ "MaximumZoomLevel" : 19,
+ "MapCopyRight" : "<a href='http://www.thunderforest.com/'>Thunderforest</a>",
+ "DataCopyRight" : "<a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a> contributors"
+}
diff --git a/src/plugins/geoservices/osm/providers/5.8/satellite b/src/plugins/geoservices/osm/providers/5.8/satellite
new file mode 100644
index 00000000..5c48a077
--- /dev/null
+++ b/src/plugins/geoservices/osm/providers/5.8/satellite
@@ -0,0 +1,10 @@
+{
+ "Enabled" : false,
+ "UrlTemplate" : "http://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer/tile/%z/%y/%x",
+ "ImageFormat" : "jpg",
+ "QImageFormat" : "RGB888",
+ "ID" : "usgs-l7",
+ "MaximumZoomLevel" : 8,
+ "MapCopyRight" : "<a href='http://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer'>USGS The National Map: Orthoimagery</a>",
+ "DataCopyRight" : "<a href='http://landsat.gsfc.nasa.gov/?page_id=2339'>USGS/NASA Landsat</a>"
+}
diff --git a/src/plugins/geoservices/osm/providers/5.8/street b/src/plugins/geoservices/osm/providers/5.8/street
new file mode 100644
index 00000000..9819f619
--- /dev/null
+++ b/src/plugins/geoservices/osm/providers/5.8/street
@@ -0,0 +1,9 @@
+{
+ "UrlTemplate" : "https://maps.wikimedia.org/osm-intl/%z/%x/%y@2x.png",
+ "ImageFormat" : "png",
+ "QImageFormat" : "Indexed8",
+ "MaximumZoomLevel" : 18,
+ "ID" : "wmf-intl-2x",
+ "MapCopyRight" : "<a href='https://wikimediafoundation.org/wiki/Terms_of_Use'>WikiMedia Foundation</a>",
+ "DataCopyRight" : "<a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a> contributors"
+}
diff --git a/src/plugins/geoservices/osm/providers/5.8/terrain b/src/plugins/geoservices/osm/providers/5.8/terrain
new file mode 100644
index 00000000..7fc6636c
--- /dev/null
+++ b/src/plugins/geoservices/osm/providers/5.8/terrain
@@ -0,0 +1,9 @@
+{
+ "UrlTemplate" : "http://a.tile.thunderforest.com/landscape/%z/%x/%y.png",
+ "ImageFormat" : "png",
+ "QImageFormat" : "Indexed8",
+ "ID" : "thf-landsc",
+ "MaximumZoomLevel" : 19,
+ "MapCopyRight" : "<a href='http://www.thunderforest.com/'>Thunderforest</a>",
+ "DataCopyRight" : "<a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a> contributors"
+}
diff --git a/src/plugins/geoservices/osm/providers/5.8/transit b/src/plugins/geoservices/osm/providers/5.8/transit
new file mode 100644
index 00000000..ebf87b05
--- /dev/null
+++ b/src/plugins/geoservices/osm/providers/5.8/transit
@@ -0,0 +1,9 @@
+{
+ "UrlTemplate" : "http://a.tile.thunderforest.com/transport/%z/%x/%y.png",
+ "ImageFormat" : "png",
+ "QImageFormat" : "Indexed8",
+ "ID" : "thf-transit",
+ "MaximumZoomLevel" : 19,
+ "MapCopyRight" : "<a href='http://www.thunderforest.com/'>Thunderforest</a>",
+ "DataCopyRight" : "<a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a> contributors"
+}
diff --git a/src/plugins/geoservices/osm/qgeofiletilecacheosm.cpp b/src/plugins/geoservices/osm/qgeofiletilecacheosm.cpp
new file mode 100644
index 00000000..a780faa9
--- /dev/null
+++ b/src/plugins/geoservices/osm/qgeofiletilecacheosm.cpp
@@ -0,0 +1,131 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qgeofiletilecacheosm.h"
+#include <QtLocation/private/qgeotilespec_p.h>
+#include <QDir>
+#include <QDirIterator>
+#include <QPair>
+#include <QDateTime>
+#include <QtConcurrent>
+#include <QThread>
+
+QT_BEGIN_NAMESPACE
+
+QGeoFileTileCacheOsm::QGeoFileTileCacheOsm(const QString &offlineDirectory, const QString &directory, QObject *parent)
+ :QGeoFileTileCache(directory, parent), m_offlineDirectory(offlineDirectory),
+ m_requestCancel(0)
+{
+}
+
+QGeoFileTileCacheOsm::~QGeoFileTileCacheOsm()
+{
+ m_requestCancel = 1;
+ m_future.waitForFinished();
+}
+
+QSharedPointer<QGeoTileTexture> QGeoFileTileCacheOsm::get(const QGeoTileSpec &spec)
+{
+ QSharedPointer<QGeoTileTexture> tt = getFromMemory(spec);
+ if (tt)
+ return tt;
+ if (tt = getFromOfflineStorage(spec))
+ return tt;
+ return getFromDisk(spec);
+}
+
+void QGeoFileTileCacheOsm::init()
+{
+ QGeoFileTileCache::init();
+ if (!m_offlineDirectory.isEmpty())
+ m_future = QtConcurrent::run(this, &QGeoFileTileCacheOsm::initOfflineRegistry);
+}
+
+QSharedPointer<QGeoTileTexture> QGeoFileTileCacheOsm::getFromOfflineStorage(const QGeoTileSpec &spec)
+{
+ QMutexLocker locker(&storageLock);
+ if (m_tilespecToOfflineFilepath.contains(spec)) {
+ QFile file(m_tilespecToOfflineFilepath[spec]);
+ file.open(QIODevice::ReadOnly);
+ QByteArray bytes = file.readAll();
+ file.close();
+ locker.unlock();
+
+ QImage image;
+ if (!image.loadFromData(bytes)) {
+ handleError(spec, QLatin1String("Problem with tile image"));
+ return QSharedPointer<QGeoTileTexture>(0);
+ }
+
+ addToMemoryCache(spec, bytes, QString());
+ QSharedPointer<QGeoTileTexture> tt = addToTextureCache(spec, image);
+ if (tt)
+ return tt;
+ }
+
+ return QSharedPointer<QGeoTileTexture>();
+}
+
+void QGeoFileTileCacheOsm::initOfflineRegistry()
+{
+ // Dealing with duplicates: picking the newest
+ QMap<QString, QPair<QString, QDateTime> > fileDates; // key is filename, value is <filepath, lastmodified>
+ QDirIterator it(m_offlineDirectory, QStringList() << "*.*", QDir::Files, QDirIterator::Subdirectories | QDirIterator::FollowSymlinks );
+ while (it.hasNext()) {
+ const QString &path = it.next();
+ QFileInfo f(path);
+ if (!fileDates.contains(f.fileName()) || fileDates[f.fileName()].second < f.lastModified())
+ fileDates[f.fileName()] = QPair<QString, QDateTime>(f.filePath(), f.lastModified());
+ if (m_requestCancel)
+ return;
+ }
+
+ int count = 0;
+ for (auto i= fileDates.begin(); i != fileDates.end(); ++i) {
+ QGeoTileSpec spec = filenameToTileSpec(i.key());
+ if (spec.zoom() == -1)
+ continue;
+ count++;
+ storageLock.lock();
+ m_tilespecToOfflineFilepath[spec] = i.value().first;
+ storageLock.unlock();
+ if (m_requestCancel)
+ return;
+ }
+ qWarning() << "OSM Offline tiles: "<<count;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/osm/qgeofiletilecacheosm.h b/src/plugins/geoservices/osm/qgeofiletilecacheosm.h
new file mode 100644
index 00000000..f48fad7f
--- /dev/null
+++ b/src/plugins/geoservices/osm/qgeofiletilecacheosm.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QGEOFILETILECACHEOSM_H
+#define QGEOFILETILECACHEOSM_H
+
+#include <QtLocation/private/qgeofiletilecache_p.h>
+#include <QHash>
+#include <QtConcurrent>
+#include <qatomic.h>
+
+QT_BEGIN_NAMESPACE
+
+class QGeoFileTileCacheOsm : public QGeoFileTileCache
+{
+ Q_OBJECT
+public:
+ QGeoFileTileCacheOsm(const QString &offlineDirectory = QString(), const QString &directory = QString(), QObject *parent = 0);
+ ~QGeoFileTileCacheOsm();
+
+ QSharedPointer<QGeoTileTexture> get(const QGeoTileSpec &spec) Q_DECL_OVERRIDE;
+
+protected:
+ void init() Q_DECL_OVERRIDE;
+ QSharedPointer<QGeoTileTexture> getFromOfflineStorage(const QGeoTileSpec &spec);
+
+ void initOfflineRegistry();
+
+ QString m_offlineDirectory;
+ QHash<QGeoTileSpec, QString> m_tilespecToOfflineFilepath;
+ QAtomicInt m_requestCancel;
+ QFuture<void> m_future;
+ QMutex storageLock;
+};
+
+QT_END_NAMESPACE
+
+#endif // QGEOFILETILECACHEOSM_H
diff --git a/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp b/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp
index fba177f4..4f25204a 100644
--- a/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp
+++ b/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp
@@ -40,7 +40,7 @@
#include "qgeotiledmappingmanagerengineosm.h"
#include "qgeotilefetcherosm.h"
#include "qgeotiledmaposm.h"
-#include "qgeotileproviderosm.h"
+#include "qgeofiletilecacheosm.h"
#include <QtLocation/private/qgeocameracapabilities_p.h>
#include <QtLocation/private/qgeomaptype_p.h>
@@ -62,10 +62,10 @@ QGeoTiledMappingManagerEngineOsm::QGeoTiledMappingManagerEngineOsm(const QVarian
setTileSize(QSize(256, 256));
QNetworkAccessManager *nm = new QNetworkAccessManager();
- QString domain = QStringLiteral("http://maps-redirect.qt.io/osm/5.6/");
+ QString domain = QStringLiteral("http://maps-redirect.qt.io/osm/5.8/");
if (parameters.contains(QStringLiteral("osm.mapping.providersrepository.address"))) {
QString customAddress = parameters.value(QStringLiteral("osm.mapping.providersrepository.address")).toString();
- // Allowing some malformed addresses ( containing the suffix "/osm/5.6/"
+ // Allowing some malformed addresses
if (customAddress.indexOf(QStringLiteral(":")) < 0) // defaulting to http:// if no prefix is found
customAddress = QStringLiteral("http://") + customAddress;
if (customAddress[customAddress.length()-1] != QLatin1Char('/'))
@@ -191,9 +191,40 @@ QGeoTiledMappingManagerEngineOsm::QGeoTiledMappingManagerEngineOsm(const QVarian
setTileFetcher(tileFetcher);
- QAbstractGeoTileCache *tileCache = new QGeoFileTileCache(QAbstractGeoTileCache::baseCacheDirectory() + QStringLiteral("osm"));
+ if (parameters.contains(QStringLiteral("osm.mapping.cache.directory"))) {
+ m_cacheDirectory = parameters.value(QStringLiteral("osm.mapping.cache.directory")).toString();
+ } else {
+ // managerName() is not yet set, we have to hardcode the plugin name below
+ m_cacheDirectory = QAbstractGeoTileCache::baseLocationCacheDirectory() + QLatin1String("osm");
+ }
+ if (parameters.contains(QStringLiteral("osm.mapping.offline.directory")))
+ m_offlineDirectory = parameters.value(QStringLiteral("osm.mapping.offline.directory")).toString();
+
+ QAbstractGeoTileCache *tileCache = new QGeoFileTileCacheOsm(m_offlineDirectory, m_cacheDirectory);
+
// 50mb of disk cache by default to minimize n. of accesses to public OSM servers
tileCache->setMaxDiskUsage(50 * 1024 * 1024);
+
+ if (parameters.contains(QStringLiteral("osm.mapping.cache.disk.size"))) {
+ bool ok = false;
+ int cacheSize = parameters.value(QStringLiteral("osm.mapping.cache.disk.size")).toString().toInt(&ok);
+ if (ok)
+ tileCache->setMaxDiskUsage(cacheSize);
+ } else {
+ tileCache->setMaxDiskUsage(100 * 1024 * 1024);
+ }
+ if (parameters.contains(QStringLiteral("osm.mapping.cache.memory.size"))) {
+ bool ok = false;
+ int cacheSize = parameters.value(QStringLiteral("osm.mapping.cache.memory.size")).toString().toInt(&ok);
+ if (ok)
+ tileCache->setMaxMemoryUsage(cacheSize);
+ }
+ if (parameters.contains(QStringLiteral("osm.mapping.cache.texture.size"))) {
+ bool ok = false;
+ int cacheSize = parameters.value(QStringLiteral("osm.mapping.cache.texture.size")).toString().toInt(&ok);
+ if (ok)
+ tileCache->setExtraTextureUsage(cacheSize);
+ }
setTileCache(tileCache);
*error = QGeoServiceProvider::NoError;
diff --git a/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.h b/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.h
index 247e4377..7536e655 100644
--- a/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.h
+++ b/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.h
@@ -73,6 +73,8 @@ protected:
private:
QVector<QGeoTileProviderOsm *> m_providers;
QString m_customCopyright;
+ QString m_cacheDirectory;
+ QString m_offlineDirectory;
};
QT_END_NAMESPACE