markers
markers
Marker building utilities.
Classes:
-
MarkerGlyph–A marker glyph's HTML, split at the end of its caller-supplied
stylevalue.
markers.MarkerGlyph
Bases: NamedTuple
A marker glyph's HTML, split at the end of its caller-supplied style value.
:meth:Map.add_points splices a per-point colour between the two halves — a later
declaration wins in an inline style attribute — so its JavaScript factory carries the
shared markup once instead of once per point.
markers.build_icon_marker
build_icon_marker(
icon: str,
css: dict[str, str],
caption: str | RawHTML | None,
caption_css: dict[str, str],
caption_id: str | None = None,
) -> DivIcon
Build an icon-based DivIcon marker with optional caption.
Parameters:
-
icon(str) –Icon name or full CSS class string. Strings containing a space (e.g.
"fa-solid fa-house") are used verbatim. Bare names starting with"fa-"get an"fa-solid"prefix; other bare names (e.g."home") get a"glyphicon"prefix. -
css(dict[str, str]) –CSS property overrides for the icon element.
-
caption(str | RawHTML | None) –Optional caption text below the icon. Plain strings are HTML-escaped and shown literally; wrap in :class:
~mapyta.markdown.RawHTMLto render inline markup such as<sub>. -
caption_css(dict[str, str]) –CSS property overrides for the caption.
-
caption_id(str | None, default:None) –Optional DOM
idon the caption<div>, used by zoom-dependent visibility JS to target the caption independently of its marker.
Returns:
-
DivIcon–
Source code in mapyta/markers.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
markers.build_marker
build_marker(
marker: str | None,
css: dict[str, str],
caption: str | RawHTML | None,
caption_css: dict[str, str],
caption_id: str | None = None,
) -> DivIcon
Build the DivIcon for marker, classified as icon or text/emoji by :func:marker_glyph.
Parameters:
-
marker(str | None) –Icon name, full CSS class string, or emoji/text.
Nonefalls back to the defaultarrow-downicon. -
css(dict[str, str]) –CSS property overrides for the glyph element.
-
caption(str | RawHTML | None) –Optional caption text below the glyph. Escaped as on :func:
build_icon_marker. -
caption_css(dict[str, str]) –CSS property overrides for the caption.
-
caption_id(str | None, default:None) –Optional DOM
idon the caption<div>, used by zoom-dependent visibility JS to target the caption independently of its marker.
Returns:
-
DivIcon–
Source code in mapyta/markers.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
markers.build_text_marker
build_text_marker(
text: str,
css: dict[str, str],
caption: str | RawHTML | None,
caption_css: dict[str, str],
caption_id: str | None = None,
) -> DivIcon
Build a text/emoji DivIcon marker with optional caption.
Parameters:
-
text(str) –The actual text/emoji to render.
-
css(dict[str, str]) –CSS property overrides for the text element.
-
caption(str | RawHTML | None) –Optional caption text below the text. Escaped as on :func:
build_icon_marker. -
caption_css(dict[str, str]) –CSS property overrides for the caption.
-
caption_id(str | None, default:None) –Optional DOM
idon the caption<div>, used by zoom-dependent visibility JS to target the caption independently of its marker.
Returns:
-
DivIcon–A DivIcon rendering the text and optional caption.
Source code in mapyta/markers.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | |
markers.caption_open_tag
caption_open_tag(
css: dict[str, str],
top_px: int,
element_id: str | None = None,
class_name: str | None = None,
) -> str
Open a caption <div> pinned to the horizontal center of its parent.
Anchoring the div's own midpoint at left:50% keeps it centred however wide the
text grows; the caller must give the parent position:relative and
overflow:visible. element_id targets one caption from the zoom-visibility
JS, class_name a whole bulk layer's captions at once; either makes the caption
zoom-gated, so it starts hidden rather than flashing before that JS first runs.
Parameters:
-
css(dict[str, str]) –CSS property overrides merged onto :data:
DEFAULT_CAPTION_CSS. -
top_px(int) –Vertical offset, in pixels, from the parent's top edge to the caption's top edge. Typically the glyph height plus a small gap.
-
element_id(str | None, default:None) –DOM
id/classfor zoom-dependent visibility. Mutually exclusive. -
class_name(str | None, default:None) –DOM
id/classfor zoom-dependent visibility. Mutually exclusive.
Returns:
-
str–The opening
<div ...>tag; the caller supplies the text and</div>.
Source code in mapyta/markers.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
markers.classify_marker
classify_marker(s: str) -> Literal['emoji', 'icon_class', 'icon_name']
Classify a marker string.
Returns:
-
emoji–Non-ASCII content (emojis, unicode symbols) → render as text.
-
icon_class–Full CSS class string containing a space (e.g.
"fa fa-home") → use as-is. -
icon_name–Bare icon name (e.g.
"home","fa-arrow-right") → auto-prefix.
Source code in mapyta/markers.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
markers.css_to_style
css_to_style(css: dict[str, str]) -> str
Convert a CSS property dict to an inline style string.
Source code in mapyta/markers.py
42 43 44 | |
markers.icon_glyph
icon_glyph(icon: str, css: dict[str, str]) -> MarkerGlyph
Build the <i> glyph for an icon marker.
Source code in mapyta/markers.py
105 106 107 108 109 110 111 112 113 114 | |
markers.marker_glyph
marker_glyph(marker: str | None, css: dict[str, str]) -> MarkerGlyph
Classify marker and build its glyph, falling back to the arrow-down icon.
Source code in mapyta/markers.py
129 130 131 132 133 | |
markers.marker_wrapper_open
marker_wrapper_open(width: int, height: int) -> str
Open the flex-centred outer wrapper shared by every marker path.
Sized to match the DivIcon's icon_size and uses flex centring so the
glyph's visual centre coincides with icon_anchor regardless of the
FontAwesome viewBox aspect ratio (e.g. fa-xmark is 0.75em wide).
Captions are nested inside this wrapper (not siblings) so click/hover
events bubble up to the Leaflet marker even though they render outside
icon_size via overflow:visible.
Source code in mapyta/markers.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
markers.point_layer_js
point_layer_js(
marker: str | None,
marker_css: dict[str, str],
caption_css: dict[str, str],
caption_class: str | None,
tooltip: TooltipStyle,
popup: PopupStyle,
) -> str
Build the browser-side onEachFeature factory used by :meth:Map.add_points.
The JavaScript counterpart of :func:build_marker: same wrapper, same glyph, same
caption nested inside, assembled per point in the browser instead of per point in
Python. Both live here so the two renderings of one marker cannot drift apart.
Every constant — the wrapper div, the glyph markup, the caption CSS — is written into
the function once, so a feature carries only what genuinely differs between points.
Styling through Folium's style_function instead would defeat that: it compiles to a
switch with one case per distinct style, putting the output back at O(n) bytes.
Source code in mapyta/markers.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
markers.px_to_int
px_to_int(value: str, default: int) -> int
Convert a CSS length string like "12px" or "12.5px" to an int.
Falls back to default for non-px units ("1em", "medium")
and malformed values so icon size estimation never raises.
Source code in mapyta/markers.py
47 48 49 50 51 52 53 54 55 56 | |
markers.resolve_icon_class
resolve_icon_class(icon: str) -> str
Resolve a marker icon name to its full CSS class.
A string containing a space is already a class list and is used as-is; a bare
"fa-" name gets the FontAwesome 6 fa-solid prefix, anything else Glyphicon's.
Source code in mapyta/markers.py
78 79 80 81 82 83 84 85 86 87 88 | |
markers.text_glyph
text_glyph(text: str, css: dict[str, str]) -> MarkerGlyph
Build the <div> glyph for a text or emoji marker.
Source code in mapyta/markers.py
117 118 119 120 121 122 123 124 125 126 | |