Skip to content

Commit

Permalink
Update TilesXYZ.py
Browse files Browse the repository at this point in the history
Solve issue #30524. Now tiles are drawn correctly if there are layers with scale-dependant styles

(cherry picked from commit 20736b9)
  • Loading branch information
javicasnov authored and nyalldawson committed Nov 21, 2019
1 parent a4c2129 commit 9bfd06a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion python/plugins/processing/algs/qgis/TilesXYZ.py
Expand Up @@ -46,7 +46,8 @@
QgsCoordinateReferenceSystem,
QgsMapRendererCustomPainterJob,
QgsLabelingEngineSettings,
QgsApplication)
QgsApplication,
QgsExpressionContextUtils)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
import threading
from concurrent.futures import ThreadPoolExecutor
Expand Down Expand Up @@ -198,6 +199,11 @@ def renderSingleMetatile(self, metatile):
extent = QgsRectangle(*metatile.extent())
threadSpecificSettings.setExtent(self.wgs_to_dest.transformBoundingBox(extent))
threadSpecificSettings.setOutputSize(size)

#Append MapSettings scope in order to update map variables (e.g @map_scale) with new extent data
exp_context = threadSpecificSettings.expressionContext()
exp_context.appendScope(QgsExpressionContextUtils.mapSettingsScope(threadSpecificSettings))
threadSpecificSettings.setExpressionContext(exp_context)

image = QImage(size, QImage.Format_ARGB32_Premultiplied)
image.fill(self.color)
Expand Down Expand Up @@ -264,6 +270,9 @@ def generate(self, writer, parameters, context, feedback):
labeling_engine_settings = self.settingsDictionary[thread].labelingEngineSettings()
labeling_engine_settings.setFlag(QgsLabelingEngineSettings.UsePartialCandidates, False)
self.settingsDictionary[thread].setLabelingEngineSettings(labeling_engine_settings)

# Transfer context scopes to MapSettings
self.settingsDictionary[thread].setExpressionContext(context.expressionContext())

self.wgs_extent = self.src_to_wgs.transformBoundingBox(extent)
self.wgs_extent = [self.wgs_extent.xMinimum(), self.wgs_extent.yMinimum(), self.wgs_extent.xMaximum(),
Expand Down

0 comments on commit 9bfd06a

Please sign in to comment.