From 269b93212b3b116ff488b903117ecbfb7d2a458a Mon Sep 17 00:00:00 2001 From: Etienne Trimaille Date: Mon, 14 Oct 2024 15:44:17 +0200 Subject: [PATCH] Two new scales when zooming : max scale for points or other geom --- lizmap/dialogs/main.py | 1 + lizmap/lizmap_api/config.py | 7 ++++ lizmap/plugin.py | 19 +++++++++ lizmap/resources/ui/ui_lizmap.ui | 68 ++++++++++++++++++++++++++------ lizmap/test/test_ui.py | 18 +++++++++ 5 files changed, 100 insertions(+), 13 deletions(-) diff --git a/lizmap/dialogs/main.py b/lizmap/dialogs/main.py index 0d781716..725c54e6 100755 --- a/lizmap/dialogs/main.py +++ b/lizmap/dialogs/main.py @@ -1017,6 +1017,7 @@ def setup_icons(self): self.group_local_layers, self.group_project_status, self.group_links, + self.group_box_max_scale_zoom, ) for widget in q_group_box: widget.setStyleSheet(COMPLETE_STYLE_SHEET) diff --git a/lizmap/lizmap_api/config.py b/lizmap/lizmap_api/config.py index ea12d854..6d5b4121 100755 --- a/lizmap/lizmap_api/config.py +++ b/lizmap/lizmap_api/config.py @@ -55,6 +55,12 @@ def __init__(self, project, fix_json=False): 'maxScale': { 'wType': 'text', 'type': 'integer', 'default': 1000000000 }, + 'max_scale_points': { + 'wType': 'scale', 'type': 'float', 'default': 5000.0 + }, + 'max_scale_lines_polygons': { + 'wType': 'scale', 'type': 'float', 'default': 5000.0 + }, 'use_native_zoom_levels': { 'wType': 'checkbox', 'type': 'boolean', 'default': True, 'always_export': True, 'use_proper_boolean': True, @@ -169,6 +175,7 @@ def __init__(self, project, fix_json=False): ), ], }, + # Deprecated, it has been removed in LWC 3.8 'zoomHistory': { 'wType': 'checkbox', 'type': 'boolean', 'default': False }, diff --git a/lizmap/plugin.py b/lizmap/plugin.py index d7b31c76..658f04af 100755 --- a/lizmap/plugin.py +++ b/lizmap/plugin.py @@ -458,6 +458,7 @@ def write_log_message(message, tag, level): self.dlg.automatic_permalink, ] self.lwc_versions[LwcVersions.Lizmap_3_9] = [ + self.dlg.group_box_max_scale_zoom, ] self.lwc_versions[LwcVersions.Lizmap_3_10] = [ ] @@ -473,6 +474,8 @@ def write_log_message(message, tag, level): # self.global_options['mapScales']['widget'] = self.dlg.list_map_scales # self.global_options['minScale']['widget'] = self.dlg.minimum_scale # self.global_options['maxScale']['widget'] = self.dlg.maximum_scale + self.global_options['max_scale_points']['widget'] = self.dlg.max_scale_points + self.global_options['max_scale_lines_polygons']['widget'] = self.dlg.max_scale_lines_polygons self.global_options['hide_numeric_scale_value']['widget'] = self.dlg.hide_scale_value self.global_options['acl']['widget'] = self.dlg.inAcl self.global_options['initialExtent']['widget'] = self.dlg.widget_initial_extent @@ -1863,6 +1866,16 @@ def read_cfg_file(self, skip_tables=False) -> dict: if key in json_options: item['widget'].setChecked(to_bool(json_options[key])) + if item['wType'] == 'scale': + item['widget'].setShowCurrentScaleButton(True) + item['widget'].setMapCanvas(self.iface.mapCanvas()) + item['widget'].setAllowNull(False) + value = json_options.get(key) + if value: + item['widget'].setScale(value) + else: + item['widget'].setScale(item['default']) + if item['wType'] in ('text', 'textarea'): if isinstance(item['default'], (list, tuple)): item['widget'].setText(", ".join(map(str, item['default']))) @@ -3720,6 +3733,12 @@ def project_config_file( if item['wType'] == 'text': input_value = item['widget'].text().strip(' \t') + if item['wType'] == 'scale': + input_value = item['widget'].scale() + if input_value == item['default']: + # Only save if different from the default value + continue + if item['wType'] == 'wysiwyg': input_value = item['widget'].html_content().strip(' \t') diff --git a/lizmap/resources/ui/ui_lizmap.ui b/lizmap/resources/ui/ui_lizmap.ui index 438a8fbe..9e490acf 100755 --- a/lizmap/resources/ui/ui_lizmap.ui +++ b/lizmap/resources/ui/ui_lizmap.ui @@ -1132,20 +1132,30 @@ QListWidget::item::selected { Scales - - + + - <html><head/><body><p>Write down integer scales separated by comma. You must enter at least 2 min and max values.<br/>Ex: 1000, 250000</p></body></html> + Use native scales according to the project CRS (better display) - - + + - Use native scales according to the project CRS (better display) + Hide numeric scale value + + + + + + + <html><head/><body><p>Write down integer scales separated by comma. You must enter at least 2 min and max values.<br/>Ex: 1000, 250000</p></body></html> + + + @@ -1236,14 +1246,41 @@ QListWidget::item::selected { - - - - - - - Hide numeric scale value + + + + Maximum scale when zooming on a feature + + + + + Points + + + + + + + true + + + + + + + Lines/polygons + + + + + + + true + + + + @@ -5514,6 +5551,11 @@ This is different to the map maximum extent (defined in QGIS project properties, QComboBox
qgis.gui
+ + QgsScaleWidget + QWidget +
qgis.gui
+
HtmlEditorWidget QWidget diff --git a/lizmap/test/test_ui.py b/lizmap/test/test_ui.py index 2d6af7da..023eb7f2 100755 --- a/lizmap/test/test_ui.py +++ b/lizmap/test/test_ui.py @@ -198,6 +198,24 @@ def test_lizmap_layer_properties(self): self.assertIsNone(output['layers']['lines'].get('externalWmsToggle')) self.assertIsNone(output['layers']['lines'].get('metatileSize')) + def test_max_scale_lwc_3_7(self): + """ Test about maximum scale when zooming. """ + lizmap = self._setup_empty_project(LwcVersions.Lizmap_3_6) + + self.assertEqual(5000.0, lizmap.dlg.max_scale_points.scale()) + self.assertEqual(5000.0, lizmap.dlg.max_scale_lines_polygons.scale()) + + # Max scale when zoomin + # Only points with a different value + lizmap.dlg.max_scale_points.setScale(1000.0) + + # Check new values in the output config + output = lizmap.project_config_file(LwcVersions.latest(), check_server=False, ignore_error=True) + + # Check scales in the CFG + self.assertEqual(1000.0, output['options']['max_scale_points']) + self.assertIsNone(output['options'].get('max_scale_lines_polygons')) + def test_general_scales_properties_lwc_3_6(self): """ Test some UI settings about general properties with LWC 3.6. """ lizmap = self._setup_empty_project(LwcVersions.Lizmap_3_6)