Create a Layer Control with groups of overlays. Parameters ---------- groups : dict A dictionary where the keys are group names and the values are lists of layer objects. e.g. { "Group 1": [layer1, layer2], "Group 2": [layer
| 6 | |
| 7 | |
| 8 | class GroupedLayerControl(JSCSSMixin, MacroElement): |
| 9 | """ |
| 10 | Create a Layer Control with groups of overlays. |
| 11 | |
| 12 | Parameters |
| 13 | ---------- |
| 14 | groups : dict |
| 15 | A dictionary where the keys are group names and the values are lists |
| 16 | of layer objects. |
| 17 | e.g. { |
| 18 | "Group 1": [layer1, layer2], |
| 19 | "Group 2": [layer3, layer4] |
| 20 | } |
| 21 | exclusive_groups: bool, default True |
| 22 | Whether to use radio buttons (default) or checkboxes. |
| 23 | If you want to use both, use two separate instances of this class. |
| 24 | **kwargs |
| 25 | Additional (possibly inherited) options. See |
| 26 | https://leafletjs.com/reference.html#control-layers |
| 27 | |
| 28 | """ |
| 29 | |
| 30 | default_js = [ |
| 31 | ( |
| 32 | "leaflet.groupedlayercontrol.min.js", |
| 33 | "https://cdnjs.cloudflare.com/ajax/libs/leaflet-groupedlayercontrol/0.6.1/leaflet.groupedlayercontrol.min.js", # noqa |
| 34 | ), |
| 35 | ] |
| 36 | default_css = [ |
| 37 | ( |
| 38 | "leaflet.groupedlayercontrol.min.css", |
| 39 | "https://cdnjs.cloudflare.com/ajax/libs/leaflet-groupedlayercontrol/0.6.1/leaflet.groupedlayercontrol.min.css", # noqa |
| 40 | ) |
| 41 | ] |
| 42 | |
| 43 | _template = Template( |
| 44 | """ |
| 45 | {% macro script(this,kwargs) %} |
| 46 | |
| 47 | L.control.groupedLayers( |
| 48 | null, |
| 49 | { |
| 50 | {%- for group_name, overlays in this.grouped_overlays.items() %} |
| 51 | {{ group_name|tojson }} : { |
| 52 | {%- for overlaykey, val in overlays.items() %} |
| 53 | {{ overlaykey|tojson }} : {{val}}, |
| 54 | {%- endfor %} |
| 55 | }, |
| 56 | {%- endfor %} |
| 57 | }, |
| 58 | {{ this.options|tojavascript }}, |
| 59 | ).addTo({{this._parent.get_name()}}); |
| 60 | |
| 61 | {%- for val in this.layers_untoggle %} |
| 62 | {{ val }}.remove(); |
| 63 | {%- endfor %} |
| 64 | |
| 65 | {% endmacro %} |
nothing calls this directly
no test coverage detected
searching dependent graphs…