How to create a tiled QuickMapServices layer programmatically?

by mark78   Last Updated May 15, 2019 23:22 PM

I’m writing a stand-alone app using Python and QGIS 2.14.9 (upgrading is not an option). Previous to 2.18, tiled services are not supported directly; you need a plugin like QuickMapServices. I have that installed, and it works within the desktop app.

Now I want to use QuickMapServices from my standalone app. I know how to create a QgsRasterLayer, but how can I create a tiled QuickMapServices layer programmatically?

# Create a normal raster layer
layer = QgsRasterLayer(url_with_params, ‘My Layer’, ‘wms’)

# But how to create a tiled QMS layer?
layer = TiledLayer(?)

I can think of two approaches:

  1. Include the plugin path in my pythonpath, and somehow instantiate a TiledLayer directly. Any sample code would be appreciated.

  2. Create a project in the desktop app which includes a QuickMapServices layer, and load that project in my standalone app. I don't know if that is possible.

Is there a better way?



Related Questions


Updated May 29, 2019 05:22 AM

Updated July 31, 2017 09:22 AM

Updated October 02, 2016 08:09 AM

Updated June 13, 2019 12:22 PM

Updated July 01, 2018 17:22 PM