Skip to content

Commit

Permalink
Add possibility to use all wms url parameters for the baseLayers in t…
Browse files Browse the repository at this point in the history
…he restriction_on_landownership
  • Loading branch information
marionb committed Jan 9, 2020
1 parent cb2039a commit 7cea1df
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
3 changes: 3 additions & 0 deletions docker/config.yaml.mako
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ vars:
# Specify any additional URL parameters that the print shall use for WMS calls
wms_url_params:
TRANSPARENT: 'true'
# Set this to true fi all parameters specified in the original URL (from the DB) should be reused in the map
# request for the restriction_on_landownership baseLayers.
wms_url_params_from_DB: false
% endif

# The "app_schema" property contains only one sub property "name". This is directly related to the database
Expand Down
45 changes: 28 additions & 17 deletions pyramid_oereb/contrib/print_proxy/mapfish_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,25 +170,33 @@ def archive_pdf_file(pdf_archive_path, binary_content, extract_as_dict):
return path_and_filename

@staticmethod
def get_wms_url_params():
def get_wms_url_params(params = None):
"""
Returns the list of additionally configured wms_url_params.
:return: The configured wms_url_params.
:rtype: list
:rtype: dict
"""
result = {}
wms_url_params = Config.get('print', {}).get('wms_url_params', False)
if wms_url_params:
log.debug("get_wms_url_params() read configuration {}".format(wms_url_params))
if isinstance(wms_url_params, dict):
result = wms_url_params
result = params
if not params:
wms_url_params = Config.get('print', {}).get('wms_url_params', False)
if wms_url_params:
log.debug("get_wms_url_params() read configuration {}".format(wms_url_params))
if isinstance(wms_url_params, dict):
result = wms_url_params
else:
log.warning("get_wms_url_params() ignoring unaccepted configuration value {}"
.format(wms_url_params))
else:
log.warning("get_wms_url_params() ignoring unaccepted configuration value {}"
.format(wms_url_params))
log.info("no wms_url_params configuration detected; using default value")
result = {'TRANSPARENT': 'true'}

else:
log.info("no wms_url_params configuration detected; using default value")
result = {'TRANSPARENT': 'true'}
for param_key, param_value in params.items(): # TODO make this Python 2.x compatible!
if isinstance(param_value, str):
result[param_key] = param_value
else:
result[param_key] = ",".join(param_value)

return result

Expand Down Expand Up @@ -277,17 +285,20 @@ def convert_to_printable_extract(self, extract_dict, feature_geometry, pdf_to_jo
[restriction_on_landownership['ResponsibleOffice']]

url, params = parse_url(restriction_on_landownership['Map']['ReferenceWMS'])
wms_url_params_from_DB = Config.get('print', {}).get('wms_url_params_from_DB', False)

restriction_on_landownership['baseLayers'] = {
'layers': [{
'type': 'wms',
'type': params.pop('SERVICE', 'wms')[0].lower(),
'opacity': restriction_on_landownership['Map'].get('layerOpacity', 0.6),
'styles': 'default',
'styles': params.pop('STYLES', 'default')[0],
'baseURL': urlparse.urlunsplit((url.scheme, url.netloc, url.path, None, None)),
'layers': params['LAYERS'][0].split(','),
'imageFormat': 'image/png',
'customParams': wms_url_params,
'layers': params.pop('LAYERS', '')[0].split(','),
'imageFormat': params.pop('FORMAT', 'image/png')[0],
'customParams': self.get_wms_url_params(params if wms_url_params_from_DB else None),
}, basemap]
}

restriction_on_landownership['legend'] = restriction_on_landownership['Map'].get(
'LegendAtWeb', '')

Expand Down

0 comments on commit 7cea1df

Please sign in to comment.