1515
1616
1717class Map (object ):
18+ """Initialize a `Map` instance
19+
20+ Args:
21+ view (View): The initial view state of the map
22+ layers (list[LayerT | LayerLike | dict]): Layers initially added to the map
23+ controls (list[ControlT | dict]): Controls initially added to the map
24+ """
25+
1826 def __init__ (
1927 self ,
2028 view : View | dict = View (),
21- layers : list [LayerT | LayerLike | dict ] | None = None ,
22- controls : list [ControlT | dict ] | None = None ,
29+ layers : list [LayerT | LayerLike | dict ] = None ,
30+ controls : list [ControlT | dict ] = None ,
2331 ):
2432 self ._initial_view = view
2533 self .calls = []
2634 if layers is None :
2735 layers = [TileLayer (id = "osm" , source = OSM ())]
2836
29- # layers = [
30- # layer.model_dump() if isinstance(layer, LayerLike) else layer
31- # for layer in layers
32- # ]
3337 self .map_options = MapOptions (
3438 view = view , layers = layers , controls = controls
3539 ).model_dump ()
@@ -49,6 +53,11 @@ def add_layer_call(self, layer_id: str, method_name: str, *args: Any):
4953 self .add_call ("applyCallToLayer" , layer_id , layer_call )
5054
5155 def add_layer (self , layer : LayerT | LayerLike | dict ) -> None :
56+ """Add a layer to the map
57+
58+ Args:
59+ layer (LayerT | LayerLike | dict): The layer to be added
60+ """
5261 if isinstance (layer , LayerLike ):
5362 layer = layer .model
5463
@@ -58,40 +67,91 @@ def add_layer(self, layer: LayerT | LayerLike | dict) -> None:
5867 self .add_call ("addLayer" , layer )
5968
6069 def remove_layer (self , layer_id : str ) -> None :
70+ """Remove a layer from the map
71+
72+ Args:
73+ layer_id (str): The Id of the layer to be removed
74+ """
6175 self .add_call ("removeLayer" , layer_id )
6276
6377 def add_control (self , control : ControlT | dict ) -> None :
78+ """Add a control to the map
79+
80+ Args:
81+ control (ControlT | dict): The control to be added
82+ """
6483 if isinstance (control , ControlT ):
6584 control = control .model_dump ()
6685
6786 self .add_call ("addControl" , control )
6887
6988 def remove_control (self , control_id : str ) -> None :
89+ """Remove a control from the map
90+
91+ Args:
92+ control_id (str): The Id of the control to be removed
93+ """
7094 self .add_call ("removeControl" , control_id )
7195
7296 def add_default_tooltip (self ) -> None :
97+ """Add a default tooltip to the map
98+
99+ It renders all feature properties
100+ and is activated for all layers of the map.
101+ """
73102 self .add_tooltip ()
74103
75- def add_tooltip (self , template : str | None = None ) -> None :
104+ def add_tooltip (self , template : str = None ) -> None :
105+ """Add a tooltip to the map
106+
107+ Args:
108+ template (str): A mustache template string.
109+ If `None`, a default tooltip is added to the map
110+ """
76111 self .add_call ("addTooltip" , template )
77112
78- def set_opacity (self , layer_id : str , opacity : float = 1.0 ) -> None :
113+ def set_opacity (self , layer_id : str , opacity : float = 1 ) -> None :
114+ """Set the opacity of a layer
115+
116+ Args:
117+ layer_id (str): The Id of the layer
118+ opacity (float): The opacity of the layer. A value between 0 and 1
119+ """
79120 self .add_layer_call (layer_id , "setOpacity" , opacity )
80121
81- def set_visible (self , layer_id : str , visible : bool = False ) -> None :
122+ def set_visibility (self , layer_id : str , visible : bool = False ) -> None :
123+ """Set the visibility of the layer
124+
125+ Args:
126+ layer_id (str): The Id of the layer
127+ visible (bool): Whether the layer is visible or not
128+ """
82129 self .add_layer_call (layer_id , "setVisible" , visible )
83130
84- def set_layer_style (self , layer_id : str , style : dict | FlatStyle ) -> None :
131+ def set_style (self , layer_id : str , style : dict | FlatStyle ) -> None :
132+ """Set the style of a layer
133+
134+ Args:
135+ layer_id (str): The Id of the layer
136+ style (dict | FlatStyle): The style of the layer
137+ """
85138 if isinstance (style , FlatStyle ):
86139 style = style .model_dump ()
87140
88141 self .add_layer_call (layer_id , "setStyle" , style )
89142
90143 def to_html (self , ** kwargs ) -> str :
144+ """Render map to HTML"""
91145 data = self .map_options | dict (calls = self .calls )
92146 return HTMLTemplate ().render (data = data , ** kwargs )
93147
94148 def save (self , path : Path | str = None , preview : bool = True , ** kwargs ) -> str :
149+ """Save map as HTML document
150+
151+ Args:
152+ path (path | str): The Path to the output file. If `None`, a temporary file is created
153+ preview (bool): Whether the file should be opened in your default browser after saving
154+ """
95155 path = write_file (content = self .to_html (** kwargs ), path = path )
96156 if preview :
97157 webbrowser .open (path )
0 commit comments