Create two maps in the same window. Adding children to this objects adds them to both maps. You can access the individual maps with `DualMap.m1` and `DualMap.m2`. Uses the Leaflet plugin Sync: https://github.com/jieter/Leaflet.Sync Parameters ---------- location: tuple or
| 8 | |
| 9 | |
| 10 | class DualMap(JSCSSMixin, MacroElement): |
| 11 | """Create two maps in the same window. |
| 12 | |
| 13 | Adding children to this objects adds them to both maps. You can access |
| 14 | the individual maps with `DualMap.m1` and `DualMap.m2`. |
| 15 | |
| 16 | Uses the Leaflet plugin Sync: https://github.com/jieter/Leaflet.Sync |
| 17 | |
| 18 | Parameters |
| 19 | ---------- |
| 20 | location: tuple or list, optional |
| 21 | Latitude and longitude of center point of the maps. |
| 22 | layout : {'horizontal', 'vertical'} |
| 23 | Select how the two maps should be positioned. Either horizontal (left |
| 24 | and right) or vertical (top and bottom). |
| 25 | **kwargs |
| 26 | Keyword arguments are passed to the two Map objects. |
| 27 | |
| 28 | Examples |
| 29 | -------- |
| 30 | >>> # DualMap accepts the same arguments as Map: |
| 31 | >>> m = DualMap(location=(0, 0), tiles="cartodbpositron", zoom_start=5) |
| 32 | >>> # Add the same marker to both maps: |
| 33 | >>> Marker((0, 0)).add_to(m) |
| 34 | >>> # The individual maps are attributes called `m1` and `m2`: |
| 35 | >>> Marker((0, 1)).add_to(m.m1) |
| 36 | >>> LayerControl().add_to(m) |
| 37 | >>> m.save("map.html") |
| 38 | |
| 39 | """ |
| 40 | |
| 41 | _template = Template( |
| 42 | """ |
| 43 | {% macro script(this, kwargs) %} |
| 44 | {{ this.m1.get_name() }}.sync({{ this.m2.get_name() }}); |
| 45 | {{ this.m2.get_name() }}.sync({{ this.m1.get_name() }}); |
| 46 | {% endmacro %} |
| 47 | """ |
| 48 | ) |
| 49 | |
| 50 | default_js = [ |
| 51 | ( |
| 52 | "Leaflet.Sync", |
| 53 | "https://cdn.jsdelivr.net/gh/jieter/Leaflet.Sync/L.Map.Sync.min.js", |
| 54 | ) |
| 55 | ] |
| 56 | |
| 57 | def __init__(self, location=None, layout="horizontal", **kwargs): |
| 58 | super().__init__() |
| 59 | for key in ("width", "height", "left", "top", "position"): |
| 60 | assert key not in kwargs, f"Argument {key} cannot be used with DualMap." |
| 61 | if layout not in ("horizontal", "vertical"): |
| 62 | raise ValueError( |
| 63 | f"Undefined option for argument `layout`: {layout}. " |
| 64 | "Use either 'horizontal' or 'vertical'." |
| 65 | ) |
| 66 | width = "50%" if layout == "horizontal" else "100%" |
| 67 | height = "100%" if layout == "horizontal" else "50%" |
nothing calls this directly
no test coverage detected
searching dependent graphs…