MCPcopy Create free account
hub / github.com/python-visualization/folium / FitOverlays

Class FitOverlays

folium/map.py:701–749  ·  view source on GitHub ↗

Fit the bounds of the maps to the enabled overlays. Parameters ---------- padding: int, default 0 Amount of padding in pixels applied in the corners. max_zoom: int, optional The maximum possible zoom to use when fitting to the bounds. fly: bool, default False

Source from the content-addressed store, hash-verified

699
700
701class FitOverlays(MacroElement):
702 """Fit the bounds of the maps to the enabled overlays.
703
704 Parameters
705 ----------
706 padding: int, default 0
707 Amount of padding in pixels applied in the corners.
708 max_zoom: int, optional
709 The maximum possible zoom to use when fitting to the bounds.
710 fly: bool, default False
711 Use a smoother, longer animation.
712 fit_on_map_load: bool, default True
713 Apply the fit when initially loading the map.
714 """
715
716 _template = Template(
717 """
718 {% macro script(this, kwargs) %}
719 function customFlyToBounds() {
720 let bounds = L.latLngBounds([]);
721 {{ this._parent.get_name() }}.eachLayer(function(layer) {
722 if (typeof layer.getBounds === 'function') {
723 bounds.extend(layer.getBounds());
724 }
725 });
726 if (bounds.isValid()) {
727 {{ this._parent.get_name() }}.{{ this.method }}(bounds, {{ this.options|tojavascript }});
728 }
729 }
730 {{ this._parent.get_name() }}.on('overlayadd', customFlyToBounds);
731 {%- if this.fit_on_map_load %}
732 customFlyToBounds();
733 {%- endif %}
734 {% endmacro %}
735 """
736 )
737
738 def __init__(
739 self,
740 padding: int = 0,
741 max_zoom: Optional[int] = None,
742 fly: bool = False,
743 fit_on_map_load: bool = True,
744 ):
745 super().__init__()
746 self._name = "FitOverlays"
747 self.method = "flyToBounds" if fly else "fitBounds"
748 self.fit_on_map_load = fit_on_map_load
749 self.options = remove_empty(padding=(padding, padding), max_zoom=max_zoom)
750
751
752class CustomPane(MacroElement):

Callers

nothing calls this directly

Calls 1

TemplateClass · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…