MCPcopy
hub / github.com/python-visualization/folium / __init__

Method __init__

folium/features.py:1984–2023  ·  view source on GitHub ↗
(
        self,
        positions: TypeLine,
        colors: Iterable[float],
        colormap: Union[ColorMap, Sequence[Any], None] = None,
        nb_steps: int = 12,
        weight: Optional[int] = None,
        opacity: Optional[float] = None,
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

1982 """
1983
1984 def __init__(
1985 self,
1986 positions: TypeLine,
1987 colors: Iterable[float],
1988 colormap: Union[ColorMap, Sequence[Any], None] = None,
1989 nb_steps: int = 12,
1990 weight: Optional[int] = None,
1991 opacity: Optional[float] = None,
1992 **kwargs: Any,
1993 ):
1994 super().__init__(**kwargs)
1995 self._name = "ColorLine"
1996 coords = validate_locations(positions)
1997
1998 if colormap is None:
1999 cm: StepColormap = LinearColormap(
2000 ["green", "yellow", "red"],
2001 vmin=min(colors),
2002 vmax=max(colors),
2003 ).to_step(nb_steps)
2004 elif isinstance(colormap, LinearColormap):
2005 cm = colormap.to_step(nb_steps)
2006 elif isinstance(colormap, list) or isinstance(colormap, tuple):
2007 cm = LinearColormap(
2008 colormap,
2009 vmin=min(colors),
2010 vmax=max(colors),
2011 ).to_step(nb_steps)
2012 elif isinstance(colormap, StepColormap):
2013 cm = colormap
2014 else:
2015 raise TypeError(
2016 f"Unexpected type for argument `colormap`: {type(colormap)}"
2017 )
2018
2019 out: Dict[str, List[List[List[float]]]] = {}
2020 for (lat1, lng1), (lat2, lng2), color in zip(coords[:-1], coords[1:], colors):
2021 out.setdefault(cm(color), []).append([[lat1, lng1], [lat2, lng2]])
2022 for key, val in out.items():
2023 self.add_child(PolyLine(val, color=key, weight=weight, opacity=opacity))
2024
2025
2026class Control(JSCSSMixin, Class):

Callers

nothing calls this directly

Calls 4

validate_locationsFunction · 0.90
PolyLineClass · 0.90
__init__Method · 0.45
add_childMethod · 0.45

Tested by

no test coverage detected