Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use individual wms url parameters for the baseLayers #985

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 if all parameters specified in the original URL should be reused in the map
# request for the restriction_on_landownership baseLayers.
wms_url_keep_params: false
% endif

# The "app_schema" property contains only one sub property "name". This is directly related to the database
Expand Down
47 changes: 30 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,35 @@ 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.
Args:
params: optional argument used for given custom parameters. Expecting a dict
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
params: optional argument used for given custom parameters. Expecting a dict
params (dict): Optional argument used for given custom parameters.

See another function to have the right syntax to generate the documentation (I'm not sure for your "return" doc)


: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 params else {}
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!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this todo ?

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 +287,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_keep_params = Config.get('print', {}).get('wms_url_keep_params', 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_keep_params else None),
}, basemap]
}

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

Expand Down
3 changes: 3 additions & 0 deletions pyramid_oereb/standard/pyramid_oereb.yml.mako
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ pyramid_oereb:
# Specify any additional URL parameters that the print shall use for WMS calls
wms_url_params:
TRANSPARENT: 'true'
# Set this to true if all parameters specified in the original URL should be reused in the map
# request for the restriction_on_landownership baseLayers.
wms_url_keep_params: false
% endif

# The "app_schema" property contains only one sub property "name". This is directly related to the database
Expand Down
4 changes: 4 additions & 0 deletions tests/contrib/print_proxy/resources/test_custom_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pyramid_oereb:

print:
wms_url_keep_params: true
22 changes: 22 additions & 0 deletions tests/contrib/print_proxy/test_mapfish_print_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@ def test_bad_config_wms_url_params():
assert config == {}


def test_custom_config_wms_url_params():
Config._config = None
Config.init('./tests/contrib/print_proxy/resources/test_custom_config.yml', 'pyramid_oereb')
renderer = Renderer(DummyRenderInfo())
wms_url_keep_params = Config.get('print', {}).get('wms_url_keep_params', False)
params = {
'TRANSPARENT': ['true'],
'OTHERCUSTOM': ['myvalue'],
'epoch': ['2018-11-29T15:13:31']
}
config = renderer.get_wms_url_params(params if wms_url_keep_params else None)
# Restore normal config
Config._config = None
Config.init('./pyramid_oereb/standard/pyramid_oereb.yml', 'pyramid_oereb')
# Do the check for this test. Value should match the one from the YAML configuration.
assert config == {
'TRANSPARENT': 'true',
'OTHERCUSTOM': 'myvalue',
'epoch': '2018-11-29T15:13:31'
}


def test_default_wms_url_param_config():
renderer = Renderer(DummyRenderInfo())
config = renderer.get_wms_url_params()
Expand Down