Skip to content

LImageOverlay

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

Demo

WARNING

The demo still needs to be fixed.

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
<template>
  <LMap
    style="height: 350px"
    :zoom="1"
    :crs="crs"
    :center="[height / 2, width / 2]"
    :minZoom="-5"
  >
    <LTileLayer
      url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
      attribution="&amp;copy; <a href=&quot;https://www.openstreetmap.org/&quot;>OpenStreetMap</a> contributors"
      layer-type="base"
      name="OpenStreetMap"
    />
    <LImageOverlay :url="imageOverlayUrl" :bounds="bounds" />

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

  <!-- Map Settings -->
  <label for="imageOverlayUrl">Url to render: </label>
  <input
    type="text"
    id="imageOverlayUrl"
    placeholder="Url for image overlay"
    v-model="imageOverlayUrl"
  />
  <!-- 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/>

<script setup lang="ts">
import { CRS } from "leaflet/dist/leaflet-src.esm";
import { computed, ref } from "vue";

const imageOverlayUrl = ref(
  "https://www.printablee.com/postpic/2011/06/blank-100-square-grid-paper_405041.jpg"
);
const width = ref(100);
const height = ref(100);

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 } },
]);

const bounds = computed(
  () =>
    [
      [0, 0],
      [height.value, width.value],
    ] as L.LatLngBoundsLiteral
);
const crs = CRS.Simple;
</script>

Props

Prop nameDescriptionTypeRequiredDefault
opacityThe opacity of the image overlayNumber-1.0
altText for the alt attribute of the image (useful for accessibility)String-''
interactiveIf true, the image overlay will emit mouse events when clicked or hoveredBoolean-false
crossOriginWhether the crossOrigin attribute will be added to the imageBoolean-false
errorOverlayUrlURL to the overlay image to show in place of the overlay that failed to loadString-''
zIndexThe explicit zIndex of the overlay layerNumber-1
classNameA custom class name to assign to the image. Empty by default.String-''
urlStringtrue
boundsArray|Object as L.LatLngBoundsExpressiontruenull

Inherited props

from layer.ts
Prop nameDescriptionTypeRequiredDefault
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 defaultString-'overlayPane'
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.String-null
nameString--
layerTypeString in ["base", "overlay"]--
visibleBoolean-true
from component.ts
Prop nameDescriptionTypeRequiredDefault
optionsLeaflet options to pass to the component constructorObject-{}

Events

Event nameTypeDescription
update:visiblebooleanTriggers when the visible prop needs to be updated
readyobjectTriggers when the component is ready