Skip to content

Commit

Permalink
Support labels
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 3, 2024
1 parent f1cbee9 commit 8586dc2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions felt/core/fsl_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,10 @@ def label_settings_to_fsl(settings: QgsPalLayerSettings,
settings.minimumScale)
converted_format['maxZoom'] = MapUtils.map_scale_to_leaflet_tile_zoom(
settings.maximumScale)
else:
# these are mandatory!
converted_format['minZoom'] = 1
converted_format['maxZoom'] = 24

res = {
'config': {
Expand Down
26 changes: 25 additions & 1 deletion felt/core/layer_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,22 @@ def import_from_url(layer: QgsMapLayer, target_map: Map,
)
return json.loads(reply.content().data().decode())

@staticmethod
def merge_dicts(tgt: Dict, enhancer: Dict) -> Dict:
"""
Recursively merges two dictionaries
"""
for key, val in enhancer.items():
if key not in tgt:
tgt[key] = val
continue

if isinstance(val, dict):
LayerExporter.merge_dicts(tgt[key], val)
else:
tgt[key] = val
return tgt

@staticmethod
def representative_layer_style(layer: QgsVectorLayer) -> LayerStyle:
"""
Expand All @@ -217,7 +233,15 @@ def representative_layer_style(layer: QgsVectorLayer) -> LayerStyle:
)
if fsl:
fsl['version'] = '2.1'
# TODO -- labeling

if layer.labelsEnabled():
label_def = FslConverter.label_settings_to_fsl(
layer.labeling().settings(),
context
)
if label_def:
LayerExporter.merge_dicts(fsl, label_def)

return LayerStyle(
fsl=fsl
)
Expand Down

0 comments on commit 8586dc2

Please sign in to comment.