"""Module for interactive map controls."""
[docs]
class ControlsMixin:
"""Mixin class for interactive map controls."""
[docs]
def add_layer_control(self, layers=None, pos=None, x=10, y=10, title="Layers"):
"""
Add a collapsible layer control widget (expands on hover).
Args:
layers (list): List of layer IDs to control. If None, finds all layers with IDs.
pos (string): Predefined position ("top-right", "top-left", etc.). Overrides x, y.
x (int): X position of the control.
y (int): Y position of the control.
title (string): Title of the control panel.
"""
self.layer_control_config = {"layers": layers, "pos": pos, "x": x, "y": y, "title": title}
return self
[docs]
def add_export_control(self, pos=None, x=10, y=50, title="Export"):
"""
Add a download button to export the map as SVG or PNG (expands on hover).
Args:
pos (string): Predefined position ("top-right", "top-left", etc.). Overrides x, y.
x (int): X position of the control.
y (int): Y position of the control.
title (string): Title of the button.
"""
self.export_control_config = {"pos": pos, "x": x, "y": y, "title": title}
return self
[docs]
def add_opacity_control(self, layers, pos=None, x=10, y=90, title="Opacity"):
"""
Add a slider to control the opacity of one or multiple layers.
Args:
layers (string or list): The ID(s) of the layer(s) to control.
pos (string): Predefined position ("top-right", "top-left", etc.). Overrides x, y.
x (int): X position of the control.
y (int): Y position of the control.
title (string): Title of the control.
"""
if not hasattr(self, "opacity_control_configs"):
self.opacity_control_configs = []
if isinstance(layers, str):
layers = [layers]
self.opacity_control_configs.append({"layers": layers, "pos": pos, "x": x, "y": y, "title": title})
return self