Skip to content

Commit

Permalink
[processing] changed alpha to transparent option in tiles_xyz, defaul…
Browse files Browse the repository at this point in the history
…t bg color from canvas
  • Loading branch information
varmar05 authored and wonder-sk committed Jun 7, 2019
1 parent 3a9b32d commit ebab737
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions python/plugins/processing/algs/qgis/TilesXYZ.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
QgsMapSettings,
QgsCoordinateTransform,
QgsCoordinateReferenceSystem,
QgsMapRendererCustomPainterJob)
QgsMapRendererCustomPainterJob,
QgsProject)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm


Expand Down Expand Up @@ -129,7 +130,7 @@ class TilesXYZAlgorithmBase(QgisAlgorithm):
ZOOM_MAX = 'ZOOM_MAX'
DPI = 'DPI'
TILE_FORMAT = 'TILE_FORMAT'
ALPHA = 'ALPHA'
TRANSPARENT = 'TRANSPARENT'
QUALITY = 'QUALITY'

def initAlgorithm(self, config=None):
Expand All @@ -154,13 +155,11 @@ def initAlgorithm(self, config=None):
self.tr('Tile format'),
self.formats,
defaultValue=0))
self.addParameter(QgsProcessingParameterNumber(self.ALPHA,
self.tr('Background transparency (applies to PNG only)'),
minValue=0,
maxValue=255,
defaultValue=0))
self.addParameter(QgsProcessingParameterBoolean(self.TRANSPARENT,
self.tr('Use transparent background (PNG only)'),
defaultValue=True))
self.addParameter(QgsProcessingParameterNumber(self.QUALITY,
self.tr('Quality (applies to JPG only)'),
self.tr('Quality (JPG only)'),
minValue=1,
maxValue=100,
defaultValue=75))
Expand All @@ -179,7 +178,7 @@ def generate(self, writer, parameters, context, feedback):
self.max_zoom = self.parameterAsInt(parameters, self.ZOOM_MAX, context)
dpi = self.parameterAsInt(parameters, self.DPI, context)
self.tile_format = self.formats[self.parameterAsEnum(parameters, self.TILE_FORMAT, context)]
alpha = self.parameterAsInt(parameters, self.ALPHA, context)
transparent = self.parameterAsBool(parameters, self.TRANSPARENT, context)
quality = self.parameterAsInt(parameters, self.QUALITY, context)
try:
tile_width = self.parameterAsInt(parameters, self.TILE_WIDTH, context)
Expand All @@ -200,10 +199,13 @@ def generate(self, writer, parameters, context, feedback):
settings.setDestinationCrs(dest_crs)
settings.setLayers(self.layers)
settings.setOutputDpi(dpi)
if self.tile_format == 'PNG':
color = QColor()
color.setAlpha(alpha)
settings.setBackgroundColor(color)
canvas_red = QgsProject.instance().readNumEntry('Gui', '/CanvasColorRedPart', 255)[0]
canvas_green = QgsProject.instance().readNumEntry('Gui', '/CanvasColorGreenPart', 255)[0]
canvas_blue = QgsProject.instance().readNumEntry('Gui', '/CanvasColorBluePart', 255)[0]
color = QColor(canvas_red, canvas_green, canvas_blue, 255)
if self.tile_format == 'PNG' and transparent:
color.setAlpha(0)
settings.setBackgroundColor(color)

self.wgs_extent = 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 ebab737

Please sign in to comment.