geometalab / Vector-Tiles-Reader-QGIS-Plugin_2016

QGIS Python plugin which reads Mapbox vector tiles from a local MBTiles file (Note: Abandoned repo; goto repo Vector-Tiles-Reader-QGIS-Plugin)
http://giswiki.hsr.ch/Vector_Tiles_Reader_QGIS_Plugin
GNU General Public License v2.0
18 stars 3 forks source link

first time loading an MBtile and adding 1st layer #30

Open Maroben opened 8 years ago

Maroben commented 8 years ago

When the plugin opens an MBTile and adds the 1st layer after a fresh start of QGIS (nothing is loaded in the mercator crs), the scale and coordinates are somehow invalid. Current workaround is, to load some kind of base map before, for example OSM.

Set the center from the mbtiles' metadata as the mapcanvas extent in Qgis.

sfkeller commented 8 years ago

Can't you check, if scale, crs and extent is available?

Then try this:

self.canvas = QgsMapCanvas() self.canvas.setExtent(layer.extent()) zoomRectangle = QgsRectangle(pos[0]-offset, pos[1]-offset,pos[0]+offset,pos[1]+offset) self.canvas.setExtent(zoomRectangle) self.canvas.refresh()

or render = QgsMapRenderer()
rect = QgsRectangle(render.fullExtent()) render.setExtent(rect)
render.setDestinationCrs()

or qgis.utils.iface.mapCanvas().zoomScale(1000)

See http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/