mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Add XYZ connection to provide default OpenStreetMap tiles
This commit is contained in:
parent
518ffe3f62
commit
273243b4c4
@ -1,4 +1,6 @@
|
||||
INSTALL(FILES srs.db qgis.db symbology-style.xml spatialite.db customization.xml
|
||||
DESTINATION ${QGIS_DATA_DIR}/resources)
|
||||
INSTALL(FILES qgis_global_settings.ini
|
||||
DESTINATION ${QGIS_DATA_DIR})
|
||||
INSTALL(DIRECTORY cpt-city-qgis-min DESTINATION ${QGIS_DATA_DIR}/resources)
|
||||
INSTALL(DIRECTORY themes DESTINATION ${QGIS_DATA_DIR}/resources)
|
||||
|
8
resources/qgis_global_settings.ini
Normal file
8
resources/qgis_global_settings.ini
Normal file
@ -0,0 +1,8 @@
|
||||
[qgis]
|
||||
connections-xyz\OpenStreetMap\authcfg=
|
||||
connections-xyz\OpenStreetMap\password=
|
||||
connections-xyz\OpenStreetMap\referer=
|
||||
connections-xyz\OpenStreetMap\url=http://a.tile.openstreetmap.org/{z}/{x}/{y}.png
|
||||
connections-xyz\OpenStreetMap\username=
|
||||
connections-xyz\OpenStreetMap\zmax=19
|
||||
connections-xyz\OpenStreetMap\zmin=0
|
@ -785,35 +785,6 @@ int main( int argc, char *argv[] )
|
||||
QCoreApplication::setApplicationName( QgsApplication::QGIS_APPLICATION_NAME );
|
||||
QCoreApplication::setAttribute( Qt::AA_DontShowIconsInMenus, false );
|
||||
|
||||
|
||||
// SetUp the QgsSettings Global Settings:
|
||||
// - use the path specified with --globalsettingsfile path,
|
||||
// - use the environment if not found
|
||||
// - use a default location as a fallback
|
||||
if ( globalsettingsfile.isEmpty() )
|
||||
{
|
||||
globalsettingsfile = getenv( "QGIS_GLOBAL_SETTINGS_FILE" );
|
||||
}
|
||||
if ( globalsettingsfile.isEmpty() )
|
||||
{
|
||||
QString default_globalsettingsfile = QgsApplication::pkgDataPath() + "/qgis_global_settings.ini";
|
||||
if ( QFile::exists( default_globalsettingsfile ) )
|
||||
{
|
||||
globalsettingsfile = default_globalsettingsfile;
|
||||
}
|
||||
}
|
||||
if ( !globalsettingsfile.isEmpty() )
|
||||
{
|
||||
if ( ! QgsSettings::setGlobalSettingsPath( globalsettingsfile ) )
|
||||
{
|
||||
QgsMessageLog::logMessage( QString( "Invalid globalsettingsfile path: %1" ).arg( globalsettingsfile ), QStringLiteral( "QGIS" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
QgsMessageLog::logMessage( QString( "Successfully loaded globalsettingsfile path: %1" ).arg( globalsettingsfile ), QStringLiteral( "QGIS" ) );
|
||||
}
|
||||
}
|
||||
|
||||
QgsSettings settings;
|
||||
if ( configLocalStorageLocation.isEmpty() )
|
||||
{
|
||||
@ -848,6 +819,34 @@ int main( int argc, char *argv[] )
|
||||
|
||||
QgsApplication myApp( argc, argv, myUseGuiFlag, profileFolder );
|
||||
|
||||
// SetUp the QgsSettings Global Settings:
|
||||
// - use the path specified with --globalsettingsfile path,
|
||||
// - use the environment if not found
|
||||
// - use a default location as a fallback
|
||||
if ( globalsettingsfile.isEmpty() )
|
||||
{
|
||||
globalsettingsfile = getenv( "QGIS_GLOBAL_SETTINGS_FILE" );
|
||||
}
|
||||
if ( globalsettingsfile.isEmpty() )
|
||||
{
|
||||
QString default_globalsettingsfile = QgsApplication::pkgDataPath() + "/qgis_global_settings.ini";
|
||||
if ( QFile::exists( default_globalsettingsfile ) )
|
||||
{
|
||||
globalsettingsfile = default_globalsettingsfile;
|
||||
}
|
||||
}
|
||||
if ( !globalsettingsfile.isEmpty() )
|
||||
{
|
||||
if ( ! QgsSettings::setGlobalSettingsPath( globalsettingsfile ) )
|
||||
{
|
||||
QgsMessageLog::logMessage( QString( "Invalid globalsettingsfile path: %1" ).arg( globalsettingsfile ), QStringLiteral( "QGIS" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
QgsMessageLog::logMessage( QString( "Successfully loaded globalsettingsfile path: %1" ).arg( globalsettingsfile ), QStringLiteral( "QGIS" ) );
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
// Set hidpi icons; use SVG icons, as PNGs will be relatively too small
|
||||
QCoreApplication::setAttribute( Qt::AA_UseHighDpiPixmaps );
|
||||
|
@ -172,6 +172,7 @@ ADD_PYTHON_TEST(PyQgsVersionCompare test_versioncompare.py)
|
||||
ADD_PYTHON_TEST(PyQgsDBManagerGpkg test_db_manager_gpkg.py)
|
||||
ADD_PYTHON_TEST(PyQgsFileDownloader test_qgsfiledownloader.py)
|
||||
ADD_PYTHON_TEST(PyQgsSettings test_qgssettings.py)
|
||||
ADD_PYTHON_TEST(PyQgsGlobalSettings test_qgis_global_settings.py)
|
||||
ADD_PYTHON_TEST(PyQgsZipUtils test_qgsziputils.py)
|
||||
|
||||
IF (NOT WIN32)
|
||||
|
69
tests/src/python/test_qgis_global_settings.py
Normal file
69
tests/src/python/test_qgis_global_settings.py
Normal file
@ -0,0 +1,69 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
***************************************************************************
|
||||
test_qgis_global_settings.py
|
||||
---------------------
|
||||
Date : January 2017
|
||||
Copyright : (C) 2017, Jorge Gustavo Rocha
|
||||
Email : jgr at geomaster dot pt
|
||||
***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
|
||||
__author__ = 'Jorge Gustavo Rocha'
|
||||
__date__ = 'August 2017'
|
||||
__copyright__ = '(C) 2017, Jorge Gustavo Rocha'
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
from qgis.testing import start_app, unittest
|
||||
from qgis.PyQt.QtCore import qDebug
|
||||
from qgis.core import QgsApplication, QgsRasterLayer, QgsSettings
|
||||
|
||||
start_app()
|
||||
|
||||
def createXYZLayerFromURL(url):
|
||||
typeandurl = "type=xyz&url=" + url
|
||||
osm = QgsRasterLayer(typeandurl, "OpenStreetMap", "wms")
|
||||
return osm
|
||||
|
||||
class TestQgsGlobalSettings(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
"""Run before each test."""
|
||||
qDebug('setUp')
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
"""Run after each test."""
|
||||
qDebug('tearDown')
|
||||
pass
|
||||
|
||||
def test_global_settings_exist(self):
|
||||
qDebug('QgsApplication.pkgDataPath(): {0}'.format(QgsApplication.pkgDataPath()))
|
||||
# Path after deployment: QgsApplication.pkgDataPath() + '/qgis_global_settings.ini'
|
||||
# QgsSettings.setGlobalSettingsPath(QgsApplication.pkgDataPath() + '/resources/qgis_global_settings.ini')
|
||||
QgsSettings.setGlobalSettingsPath(QgsApplication.pkgDataPath() + '/qgis_global_settings.ini')
|
||||
self.settings = QgsSettings('testqgissettings', 'testqgissettings')
|
||||
settings = QgsSettings()
|
||||
qDebug('settings.allKeys(): {0}'.format(settings.allKeys()))
|
||||
defaulturl = settings.value('qgis/connections-xyz/OpenStreetMap/url')
|
||||
|
||||
def testKey():
|
||||
self.assertEqual(defaulturl, 'http://a.tile.openstreetmap.org/{z}/{x}/{y}.png')
|
||||
|
||||
def testLayer():
|
||||
layer = createXYZLayerFromURL(defaulturl)
|
||||
self.assertEqual(layer.name(), 'OpenStreetMap')
|
||||
|
||||
testKey()
|
||||
testLayer()
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
x
Reference in New Issue
Block a user