Skip to content

๐Ÿงฉ LSVGOverlay โ€‹

Used to load and display a single svg over specific bounds of the map.

๐Ÿงช Demo โ€‹

Markers

  • 0 - lng (X): 0 - lat (Y): 0
  • 1 - lng (X): 100 - lat (Y): 0
  • 2 - lng (X): 0 - lat (Y): 100
  • 3 - lng (X): 100 - lat (Y): 100
  • 4 - lng (X): 0 - lat (Y): 50
  • 5 - lng (X): 50 - lat (Y): 0
  • 6 - lng (X): 50 - lat (Y): 100
  • 7 - lng (X): 100 - lat (Y): 50
vue
<script setup lang="ts">
import { computed, ref, onMounted } from 'vue'

import { LMap, LMarker, LPopup, LSVGOverlay } from '@maxel01/vue-leaflet'
import { CRS, type LatLngBoundsLiteral } from 'leaflet'

const width = ref(100)
const height = ref(100)

const svgElement = ref()
onMounted(() => {
    svgElement.value = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
    svgElement.value.setAttribute('xmlns', 'http://www.w3.org/2000/svg')
    svgElement.value.setAttribute('viewBox', '0 0 200 200')
    svgElement.value.innerHTML = '<rect width="200" height="200"/><rect x="75" y="23" width="50" height="50" style="fill:red"/><rect x="75" y="123" width="50" height="50" style="fill:#0013ff"/>'
})

const bounds = computed(
    () =>
        [
            [0, 0],
            [height.value, width.value]
        ] as LatLngBoundsLiteral
)

const markers = ref([
    { coordinates: { lng: 0, lat: 0 } },
    { coordinates: { lng: 100, lat: 0 } },
    { coordinates: { lng: 0, lat: 100 } },
    { coordinates: { lng: 100, lat: 100 } },
    { coordinates: { lng: 0, lat: 50 } },
    { coordinates: { lng: 50, lat: 0 } },
    { coordinates: { lng: 50, lat: 100 } },
    { coordinates: { lng: 100, lat: 50 } }
])
</script>

<template>
    <LMap :zoom="1" :crs="CRS.Simple" :center="[height / 2, width / 2]" :minZoom="-5">
        <LSVGOverlay v-if="svgElement" :svg="svgElement" :bounds="bounds" />

        <LMarker v-for="(marker, idx) in markers" :key="idx" :lat-lng="marker.coordinates">
            <LPopup>{{ idx }}</LPopup>
        </LMarker>
    </LMap>

    <!-- Bounds settings -->
    <label for="width">Width: </label>
    <input type="number" id="width" placeholder="Width" v-model="width" />
    <label for="height">Height: </label>
    <input type="number" id="height" placeholder="Height" v-model="height" />

    <!-- Marker settings -->
    <div class="markers-list">
        <h4>Markers</h4>
        <ul>
            <li v-for="(marker, idx) in markers" :key="idx">
                {{ idx }} - lng (X): {{ marker.coordinates.lng }} - lat (Y):
                {{ marker.coordinates.lat }}
            </li>
        </ul>
    </div>
</template>

<style scoped>
input {
    border: 1px solid;
}
</style>

โš™๏ธ Props โ€‹

Prop nameDescriptionTypeReactiveDefaultRequired
svgUrl of the svg or the SVGElementstring | SVGElementinitOnly-true

๐Ÿ”— Inherited props โ€‹

from ImageOverlayAbstractProps
Prop nameDescriptionTypeReactiveDefaultRequired
boundsThe geographical boundsLatLngBoundsExpressiontrue-true
classNameA custom class name to assign to the image. Empty by default.stringinitOnly-false
zIndexThe explicit zIndex of the overlay layer.numbertrue-false
errorOverlayUrlURL to the overlay image to show in place of the overlay that failed to load.stringinitOnly-false
crossOriginWhether the crossOrigin attribute will be added to the image. If a String is provided, the image will have its crossOrigin attribute set to the String provided. This is needed if you want to access image pixel data. Refer to CORS Settings for valid String values.booleaninitOnly-false
interactiveIf true, the image overlay will emit mouse events when clicked or hoveredbooleaninitOnly-false
altText for the alt attribute of the image (useful for accessibility).stringinitOnly-false
opacityThe opacity of the image overlay.numbertrue-false
from LayerProps
Prop nameDescriptionTypeReactiveDefaultRequired
paneBy default, the layer will be added to the map's overlay pane. Overriding this option will cause the layer to be placed on another pane by default. Not effective if the renderer option is set (the renderer option will override the pane option).stringinitOnly-false
attributionString to be shown in the attribution control, e.g. "ยฉ OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.stringtrue-false
name-stringtrue-false
layerType-LayerTypetrue-false
visible-booleantrue-false
from ComponentProps
Prop nameDescriptionTypeReactiveDefaultRequired
optionsLeaflet options to pass to the component constructor.TinitOnly-false

๐Ÿ“ก Emits โ€‹

EventArgumentsDescription
update:visiblebooleanTriggers when the visible prop needs to be updated
readyTTriggers when the component is ready

๐ŸŽฏ Slots โ€‹

NameDescription
defaultUsed to inject Leaflet child components like <LPopup> or <LTooltip> into the LCircleMarker.

๐Ÿงญ Exposes โ€‹

NameTypeDescription
readyRef<boolean>Indicates whether the component and its underlying Leaflet object are fully initialized.
leafletObjectRef<SVGOverlay | undefined>The underlying Leaflet instance. Can be used to directly interact with the Leaflet API (e.g. calling methods or accessing internal state).