|
6 | 6 | from typing import Any, Callable, Optional, Union |
7 | 7 |
|
8 | 8 | import xyzservices |
9 | | -from branca.element import Element, Figure |
10 | 9 |
|
11 | 10 | from folium.map import Layer |
12 | 11 | from folium.template import Template |
@@ -285,6 +284,22 @@ class ImageOverlay(Layer): |
285 | 284 |
|
286 | 285 | _template = Template( |
287 | 286 | """ |
| 287 | + {% macro header(this, kwargs) %} |
| 288 | + {% if this.pixelated %} |
| 289 | + <style> |
| 290 | + .leaflet-image-layer { |
| 291 | + /* old android/safari*/ |
| 292 | + image-rendering: -webkit-optimize-contrast; |
| 293 | + image-rendering: crisp-edges; /* safari */ |
| 294 | + image-rendering: pixelated; /* chrome */ |
| 295 | + image-rendering: -moz-crisp-edges; /* firefox */ |
| 296 | + image-rendering: -o-crisp-edges; /* opera */ |
| 297 | + -ms-interpolation-mode: nearest-neighbor; /* ie */ |
| 298 | + } |
| 299 | + </style> |
| 300 | + {% endif %} |
| 301 | + {% endmacro %} |
| 302 | +
|
288 | 303 | {% macro script(this, kwargs) %} |
289 | 304 | var {{ this.get_name() }} = L.imageOverlay( |
290 | 305 | {{ this.url|tojson }}, |
@@ -321,31 +336,6 @@ def __init__( |
321 | 336 |
|
322 | 337 | self.url = image_to_url(image, origin=origin, colormap=colormap) |
323 | 338 |
|
324 | | - def render(self, **kwargs): |
325 | | - super().render() |
326 | | - |
327 | | - figure = self.get_root() |
328 | | - assert isinstance( |
329 | | - figure, Figure |
330 | | - ), "You cannot render this Element if it is not in a Figure." |
331 | | - if self.pixelated: |
332 | | - pixelated = """ |
333 | | - <style> |
334 | | - .leaflet-image-layer { |
335 | | - /* old android/safari*/ |
336 | | - image-rendering: -webkit-optimize-contrast; |
337 | | - image-rendering: crisp-edges; /* safari */ |
338 | | - image-rendering: pixelated; /* chrome */ |
339 | | - image-rendering: -moz-crisp-edges; /* firefox */ |
340 | | - image-rendering: -o-crisp-edges; /* opera */ |
341 | | - -ms-interpolation-mode: nearest-neighbor; /* ie */ |
342 | | - } |
343 | | - </style> |
344 | | - """ |
345 | | - figure.header.add_child( |
346 | | - Element(pixelated), name="leaflet-image-layer" |
347 | | - ) # noqa |
348 | | - |
349 | 339 | def _get_self_bounds(self) -> TypeBoundsReturn: |
350 | 340 | """ |
351 | 341 | Computes the bounds of the object itself (not including it's children) |
|
0 commit comments