Adds a layer or control to the map. Args: obj: The layer or control to add to the map. position: The position of the control on the map. Defaults to "topright". **kwargs: Additional keyword arguments.
(self, obj: str | Any, position: str = "topright", **kwargs: Any)
| 272 | ) |
| 273 | |
| 274 | def add(self, obj: str | Any, position: str = "topright", **kwargs: Any) -> None: |
| 275 | """Adds a layer or control to the map. |
| 276 | |
| 277 | Args: |
| 278 | obj: The layer or control to add to the map. |
| 279 | position: The position of the control on the map. Defaults to "topright". |
| 280 | **kwargs: Additional keyword arguments. |
| 281 | """ |
| 282 | if isinstance(obj, str): |
| 283 | basemap = check_basemap(obj) |
| 284 | if basemap in basemaps.keys(): |
| 285 | super().add(get_basemap(basemap)) |
| 286 | return |
| 287 | |
| 288 | if not isinstance(obj, str): |
| 289 | super().add(obj, position=position, **kwargs) |
| 290 | return |
| 291 | |
| 292 | obj = obj.lower() |
| 293 | |
| 294 | backward_compatibilities = { |
| 295 | "zoom_ctrl": "zoom_control", |
| 296 | "fullscreen_ctrl": "fullscreen_control", |
| 297 | "scale_ctrl": "scale_control", |
| 298 | "toolbar_ctrl": "toolbar", |
| 299 | "draw_ctrl": "draw_control", |
| 300 | "data_ctrl": "search_control", |
| 301 | "search_ctrl": "search_control", |
| 302 | } |
| 303 | obj = backward_compatibilities.get(obj, obj) |
| 304 | if obj == "measure_ctrl": |
| 305 | measure = ipyleaflet.MeasureControl( |
| 306 | position=position, |
| 307 | active_color="orange", |
| 308 | primary_length_unit="kilometers", |
| 309 | ) |
| 310 | self.add(measure, position=position) |
| 311 | elif obj == "layer_ctrl": |
| 312 | layer_control = ipyleaflet.LayersControl(position=position) |
| 313 | self.add(layer_control, position=position) |
| 314 | else: |
| 315 | super().add(obj, position=position, **kwargs) |
| 316 | |
| 317 | def add_controls( |
| 318 | self, controls: list[Any] | Any, position: str = "topleft" |
no test coverage detected