Skip to content

๐Ÿงฉ LControlLayers โ€‹

The layers control gives users the ability to switch between different base layers and switch overlays on/off.

๐Ÿงช Demo โ€‹

vue
<script setup lang="ts">
import { LControlLayers, LMap, LTileLayer } from '@maxel01/vue-leaflet'
</script>

<template>
    <LMap ref="map" :zoom="2" :center="[47.41322, -1.219482]">
        <LTileLayer
            url="https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png"
            layer-type="base"
            name="Humanitarian OpenStreetMap"
            attribution="ยฉ OpenStreetMap contributors, Tiles style by Humanitarian OpenStreetMap Team hosted by OpenStreetMap France"
        />
        <LTileLayer
            url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
            layer-type="base"
            name="OpenStreetMap"
        />
        <LControlLayers />
    </LMap>
</template>

โš™๏ธ Props โ€‹

Prop nameDescriptionTypeReactiveDefaultRequired
collapsedIf true, the control will be collapsed into an icon and expanded on mouse hover, touch, or keyboard activation.booleaninitOnly-false
autoZIndexIf true, the control will assign zIndexes in increasing order to all of its layers so that the order is preserved when switching them on/off.booleaninitOnly-false
hideSingleBaseIf true, the base layers in the control will be hidden when there is only one.booleaninitOnly-false
sortLayersWhether to sort the layers. When false, layers will keep the order in which they were added to the control.booleaninitOnly-false
sortFunctionA compare function that will be used for sorting the layers, when sortLayers is true. The function receives both the L.Layer instances and their names, as in sortFunction(layerA, layerB, nameA, nameB). By default, it sorts layers alphabetically by their name.TSFunctionTypeinitOnly-false

๐Ÿ”— Inherited props โ€‹

from ControlAbstractProps
Prop nameDescriptionTypeReactiveDefaultRequired
positionThe position of the control (one of the map corners). Possible values are topleft, topright, bottomleft or bottomright.ControlPositiontrue-false
from ComponentProps
Prop nameDescriptionTypeReactiveDefaultRequired
optionsLeaflet options to pass to the component constructor.TinitOnly-false

๐Ÿ“ก Emits โ€‹

EventArgumentsDescription
readyTTriggers when the component is ready

๐Ÿงญ Exposes โ€‹

NameTypeDescription
leafletObjectRef<Control.Layers | undefined>The underlying Leaflet instance. Can be used to directly interact with the Leaflet API (e.g. calling methods or accessing internal state).