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

Class Class

folium/map.py:38–73  ·  view source on GitHub ↗

The root class of the leaflet class hierarchy

Source from the content-addressed store, hash-verified

36
37
38class Class(MacroElement):
39 """The root class of the leaflet class hierarchy"""
40
41 _includes: DefaultDict[str, dict] = defaultdict(dict)
42
43 @classmethod
44 def include(cls, **kwargs):
45 cls._includes[cls].update(**kwargs)
46
47 @classproperty
48 def includes(cls):
49 return cls._includes[cls]
50
51 @property
52 def leaflet_class_name(self):
53 # TODO: I did not check all Folium classes to see if
54 # this holds up. This breaks at least for CustomIcon.
55 return f"L.{self._name}"
56
57 def render(self, **kwargs):
58 figure = self.get_root()
59 assert isinstance(
60 figure, Figure
61 ), "You cannot render this Element if it is not in a Figure."
62 if self.includes:
63 stmt = IncludeStatement(self.leaflet_class_name, **self.includes)
64 # A bit weird. I tried adding IncludeStatement directly to both
65 # figure and script, but failed. So we render this ourself.
66 figure.script.add_child(
67 Element(stmt._template.render(this=stmt, kwargs=self.includes)),
68 # make sure each class include gets rendered only once
69 name=self._name + "_includes",
70 # make sure this renders before the element itself
71 index=-1,
72 )
73 super().render(**kwargs)
74
75
76class Evented(Class):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…