Skip to content

Commit

Permalink
Fix custom wms parameters processing.
Browse files Browse the repository at this point in the history
  • Loading branch information
alisovenko committed Jun 15, 2017
1 parent 16b4fc2 commit b65c502
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/config_reader_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
class ConfigReaderHelper(object):

@staticmethod
def try_read_config(parser, section, param, reraise=False):
def try_read_config(parser, section, param, reraise=False, default=None):
try:
val = parser.get(section, param)
except:
if reraise:
raise
else:
val = None
val = default
return val

@staticmethod
Expand Down
1 change: 1 addition & 0 deletions src/data_source_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def __init__(self):

self.wms_url = None
self.wms_params = None
self.wms_url_params = None
self.wms_layers = None
self.wms_turn_over = None

Expand Down
45 changes: 39 additions & 6 deletions src/data_source_serializer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import absolute_import
import codecs
import os
import urlparse

from ConfigParser import ConfigParser
from .config_reader_helper import ConfigReaderHelper
from .custom_translator import CustomTranslator
Expand All @@ -10,6 +12,33 @@
from .supported_drivers import KNOWN_DRIVERS


def parse_wms_url_parameter(url, parameters_str):
wms_url = url.split("?")[0]

o = urlparse.urlparse(url)
parameters = dict(urlparse.parse_qsl(o.query))

wms_params = []
wms_url_params = []

for parameter in parameters_str.strip("&").split("&"):
if parameter.find("=") == -1:
continue
k,v = parameter.split("=")
parameters.update({k: v})

for k,v in parameters.items():
if k.upper() in ["VERSION", "REQUEST", "FORMAT", "CRS", "STYLES", "SERVICE", "DPIMODE", "CONTEXTUALWMSLEGEND"]:
wms_params.append("%s=%s"%(k,v))
else:
wms_url_params.append("%s=%s"%(k,v))

wms_params = "&".join(wms_params)
wms_url_params = "&".join(wms_url_params)

return (wms_url, wms_params, wms_url_params)


class DataSourceSerializer(object):

@classmethod
Expand Down Expand Up @@ -54,8 +83,11 @@ def read_from_ini(cls, ini_file_path):
ds.tms_origin_y = ConfigReaderHelper.try_read_config_int(parser, 'tms', 'origin_y')

#WMS
ds.wms_url = ConfigReaderHelper.try_read_config(parser, 'wms', 'url', reraise=(ds.type == KNOWN_DRIVERS.WMS))
ds.wms_params = ConfigReaderHelper.try_read_config(parser, 'wms', 'params')
ds.wms_url, ds.wms_params, ds.wms_url_params = parse_wms_url_parameter(
ConfigReaderHelper.try_read_config(parser, 'wms', 'url', reraise=(ds.type == KNOWN_DRIVERS.WMS), default=""),
ConfigReaderHelper.try_read_config(parser, 'wms', 'params', default="")
)

ds.wms_layers = ConfigReaderHelper.try_read_config(parser, 'wms', 'layers')
ds.wms_turn_over = ConfigReaderHelper.try_read_config_bool(parser, 'wms', 'turn_over')

Expand Down Expand Up @@ -122,10 +154,11 @@ def read_from_json(cls, json_data):

#WMS
if ds.type.lower() == KNOWN_DRIVERS.WMS.lower():
ds.wms_url = json_data['url']
ds.wms_params = json_data['params']
if ds.wms_params is None:
ds.wms_params = ""

ds.wms_url, ds.wms_params, ds.wms_url_params = parse_wms_url_parameter(
json_data['url'],
json_data['params']
)

ds.wms_layers = json_data['layers']
ds.wms_turn_over = json_data['turn_over']
Expand Down
2 changes: 1 addition & 1 deletion src/ds_edit_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self, parent=None):
os.path.join(
os.path.dirname(__file__),
'icons',
'mapservice.png'
'mapservices.png'
)
)

Expand Down
2 changes: 1 addition & 1 deletion src/group_edit_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, parent=None):
os.path.join(
os.path.dirname(__file__),
'icons',
'mapservice.png'
'mapservices.png'
)
)

Expand Down
2 changes: 1 addition & 1 deletion src/gui/editor_widget_wms.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, parent=None):
def feel_form(self, ds_info):
self.ds_info = ds_info
self.txtUrl.setText(ds_info.wms_url)
self.txtParams.setText(ds_info.wms_params)
self.txtParams.setText(ds_info.wms_params + "&" + ds_info.wms_url_params)
self.txtLayers.setText(ds_info.wms_layers)
self.chkTurnOver.setChecked(ds_info.wms_turn_over if ds_info.wms_turn_over else False)

Expand Down
4 changes: 3 additions & 1 deletion src/metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name=QuickMapServices
qgisMinimumVersion=2.4
description=Collection of easy to add basemaps
version=0.18.5
version=0.18.6
author=NextGIS
[email protected]
about=Convenient list of services + search for finding datasets and basemaps. Please contribute new services via http://qms.nextgis.com!
Expand All @@ -14,6 +14,8 @@ about=Convenient list of services + search for finding datasets and basemaps. Pl

# Uncomment the following line and add your changelog:
changelog=
0.18.6
* Fix custom wms parameters processing.
0.18.5
* Fix TMS services rendering 'ripple' effect due to broken tiles.
0.18.4
Expand Down
4 changes: 3 additions & 1 deletion src/qgis_map_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def add_layer_to_map(ds):
if ds.wms_turn_over:
layers.reverse()
qgis_wms_uri += '&layers=' + '&layers='.join(layers) + '&styles=' * len(layers)
qgis_wms_uri += '&url=' + ds.wms_url
qgis_wms_uri += '&url=' + ds.wms_url + "?" + ds.wms_url_params.replace("=","%3D").replace("&","%26")

# print ">>> qgis_wms_uri: ", qgis_wms_uri

layer = QgsRasterLayer(qgis_wms_uri, tr(ds.alias), KNOWN_DRIVERS.WMS.lower())
layers4add.append(layer)
Expand Down

0 comments on commit b65c502

Please sign in to comment.