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 241dba4 commit 91c927f
Show file tree
Hide file tree
Showing 3 changed files with 39 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 @@ -119,6 +119,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
49 changes: 32 additions & 17 deletions pyramid_oereb/contrib/print_proxy/mapfish_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,33 @@ def __call__(self, value, system):
return content

@staticmethod
def get_wms_url_params():
def get_wms_url_params(params = {}):
"""
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 @@ -258,17 +266,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 Expand Up @@ -769,3 +780,7 @@ def sort_legend_elem(elem):
value = -elem.get(geom_type, 0)

return category, value

def extract_param(self, params, key, default):
param = params.pop(key, default)
# if type(param) is string
4 changes: 4 additions & 0 deletions pyramid_oereb/lib/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,7 @@ def url_to_base64(url):
raise AttributeError(dedicated_msg)

return base64.b64encode(response.read())


def get_wms_url_params(params, url):
return {}

0 comments on commit 91c927f

Please sign in to comment.