Skip to content

Components API Reference

Vue3 MapLibre GL provides a comprehensive set of Vue 3 components for building interactive maps with MapLibre GL JS. All components are designed with TypeScript support, reactive data binding, and comprehensive error handling.

Maplibre

The main map component that renders the MapLibre GL JS map. This is the core component that provides the map container and manages the MapLibre GL instance.

Props

PropTypeDefaultDescription
optionsPartial<MapOptions>{}Map configuration options from MapLibre GL
register(actions: MaplibreActions) => voidundefinedCallback for registering map actions
debugbooleanfalseEnable debug logging
autoCleanupbooleantrueAutomatically cleanup resources on unmount
containerIdstring'maplibre'Container ID for the map element
containerClassstring''Custom container class names
onError(error: any) => voidundefinedError handling callback
onLoad(map: Map) => voidundefinedLoad success callback

Events

EventPayloadDescription
registerMaplibreActionsFired when map actions are registered
loadMapLibreEventFired when the map has finished loading
errorErrorEventFired when an error occurs
clickMapMouseEventFired when the map is clicked
dblclickMapMouseEventFired when the map is double-clicked
contextmenuMapMouseEventFired when right-clicking the map
mousemoveMapMouseEventFired when mouse moves over the map
mouseupMapMouseEventFired when mouse button is released
mousedownMapMouseEventFired when mouse button is pressed
mouseoutMapMouseEventFired when mouse leaves the map
mouseoverMapMouseEventFired when mouse enters the map
movestartMapLibreEventFired when map movement starts
moveMapLibreEventFired during map movement
moveendMapLibreEventFired when map movement ends
zoomstartMapLibreEventFired when zoom starts
zoomMapLibreEventFired during zoom
zoomendMapLibreEventFired when zoom ends
rotatestartMapLibreEventFired when rotation starts
rotateMapLibreEventFired during rotation
rotateendMapLibreEventFired when rotation ends
dragstartMapLibreEventFired when dragging starts
dragMapLibreEventFired during dragging
dragendMapLibreEventFired when dragging ends
pitchstartMapLibreEventFired when pitch starts
pitchMapLibreEventFired during pitch
pitchendMapLibreEventFired when pitch ends
wheelMapWheelEventFired on mouse wheel events
terrainMapTerrainEventFired on terrain events

Slots

SlotDescription
defaultMain content slot for child components
loadingContent shown while map is loading
errorContent shown when map encounters an error

Example

vue
<template>
  <Maplibre
    :options="mapOptions"
    :debug="true"
    @load="onMapLoad"
    @error="onMapError"
    style="height: 500px"
  >
    <template #loading>
      <div class="loading">Loading map...</div>
    </template>

    <template #error>
      <div class="error">Failed to load map</div>
    </template>

    <!-- Child components -->
    <GeoJsonSource :data="geoJsonData">
      <FillLayer :style="fillStyle" />
    </GeoJsonSource>
  </Maplibre>
</template>

<script setup>
import { ref } from 'vue';
import { Maplibre, GeoJsonSource, FillLayer } from 'vue3-maplibre-gl';

const mapOptions = ref({
  style: 'https://demotiles.maplibre.org/style.json',
  center: [0, 0],
  zoom: 2,
});

const geoJsonData = ref({
  type: 'FeatureCollection',
  features: [],
});

const fillStyle = ref({
  'fill-color': '#088',
  'fill-opacity': 0.8,
});

function onMapLoad(map) {
  console.log('Map loaded:', map);
}

function onMapError(error) {
  console.error('Map error:', error);
}
</script>

GeoJsonSource

A component for adding GeoJSON data sources to the map. This component provides the data that can be styled by layer components. It supports reactive data updates, clustering, and comprehensive error handling.

Props

PropTypeDefaultDescription
idstringundefinedUnique identifier for the source
dataGeoJSONSourceSpecification['data']{ type: 'FeatureCollection', features: [] }GeoJSON data or URL to GeoJSON
optionsPartial<GeoJSONSourceSpecification>{}Additional GeoJSON source options
debugbooleanfalseEnable debug logging
autoCleanupbooleantrueAutomatically cleanup resources on unmount
register(actions: CreateGeoJsonSourceActions) => voidundefinedCallback for registering source actions
onLoad(source: any) => voidundefinedLoad success callback
onError(error: any) => voidundefinedError handling callback
onDataUpdate(data: GeoJSONSourceSpecification['data']) => voidundefinedData update callback

Events

EventPayloadDescription
registerCreateGeoJsonSourceActionsFired when source is registered
loadGeoJSONSourceFired when source is loaded
errorErrorFired when an error occurs
data-updateGeoJSONSourceSpecification['data']Fired when data is updated

Example

vue
<template>
  <Maplibre :options="mapOptions">
    <GeoJsonSource
      id="my-source"
      :data="geoJsonData"
      :cluster="true"
      :cluster-max-zoom="14"
      :cluster-radius="50"
    >
      <CircleLayer :style="circleStyle" />
    </GeoJsonSource>
  </Maplibre>
</template>

<script setup>
import { ref } from 'vue';
import { Maplibre, GeoJsonSource, CircleLayer } from 'vue3-maplibre-gl';

const geoJsonData = ref({
  type: 'FeatureCollection',
  features: [
    {
      type: 'Feature',
      geometry: {
        type: 'Point',
        coordinates: [0, 0],
      },
      properties: {
        name: 'Sample Point',
      },
    },
  ],
});

const circleStyle = ref({
  'circle-radius': 6,
  'circle-color': '#007cbf',
});
</script>

FillLayer

A component for rendering filled polygons from a data source. Supports all MapLibre GL fill layer properties with reactive updates and comprehensive event handling.

Props

PropTypeDefaultDescription
idstringundefinedUnique identifier for the layer
sourcestring | objectundefinedData source for the layer
sourceLayerstringundefinedSource layer name for vector sources
filterFilterSpecification['all']Filter expression to apply to the layer
styleFillLayerStyle{}Style configuration for the fill layer
maxzoomnumber24Maximum zoom level for layer visibility
minzoomnumber0Minimum zoom level for layer visibility
metadataobjectundefinedArbitrary metadata for the layer
beforeIdstringundefinedID of layer before which to insert this layer
visiblebooleantrueWhether the layer is visible

Events

EventPayloadDescription
registerCreateLayerActionsFired when layer is registered
clickMapLayerMouseEventFired when layer is clicked
dblclickMapLayerMouseEventFired when layer is double-clicked
mousedownMapLayerMouseEventFired when mouse button is pressed on layer
mouseupMapLayerMouseEventFired when mouse button is released on layer
mousemoveMapLayerMouseEventFired when mouse moves over layer
mouseenterMapLayerMouseEventFired when mouse enters layer
mouseleaveMapLayerMouseEventFired when mouse leaves layer
mouseoverMapLayerMouseEventFired when mouse is over layer
mouseoutMapLayerMouseEventFired when mouse leaves layer
contextmenuMapLayerMouseEventFired when right-clicking layer
touchstartMapLayerTouchEventFired when touch starts on layer
touchendMapLayerTouchEventFired when touch ends on layer
touchcancelMapLayerTouchEventFired when touch is cancelled on layer

Example

vue
<template>
  <Maplibre :options="mapOptions">
    <GeoJsonSource :data="polygonData">
      <FillLayer
        id="polygon-fill"
        :style="fillStyle"
        :filter="['==', 'type', 'polygon']"
        @click="onPolygonClick"
      />
    </GeoJsonSource>
  </Maplibre>
</template>

<script setup>
import { ref } from 'vue';
import { Maplibre, GeoJsonSource, FillLayer } from 'vue3-maplibre-gl';

const fillStyle = ref({
  'fill-color': [
    'case',
    ['boolean', ['feature-state', 'hover'], false],
    '#627BC1',
    '#41B883',
  ],
  'fill-opacity': 0.8,
});

function onPolygonClick(event) {
  console.log('Polygon clicked:', event.features[0]);
}
</script>

CircleLayer

A component for rendering circles from point data sources. Perfect for displaying point data with customizable radius, color, and stroke properties.

Props

PropTypeDefaultDescription
idstringundefinedUnique identifier for the layer
sourcestring | objectundefinedData source for the layer
sourceLayerstringundefinedSource layer name for vector sources
filterFilterSpecification['all']Filter expression to apply to the layer
styleCircleLayerStyle{}Style configuration for the circle layer
maxzoomnumber24Maximum zoom level for layer visibility
minzoomnumber0Minimum zoom level for layer visibility
metadataobjectundefinedArbitrary metadata for the layer
beforeIdstringundefinedID of layer before which to insert this layer
visiblebooleantrueWhether the layer is visible

Events

Same events as FillLayer (click, mousemove, etc.)

Example

vue
<template>
  <Maplibre :options="mapOptions">
    <GeoJsonSource :data="pointData">
      <CircleLayer id="points" :style="circleStyle" @click="onPointClick" />
    </GeoJsonSource>
  </Maplibre>
</template>

<script setup>
import { ref } from 'vue';
import { Maplibre, GeoJsonSource, CircleLayer } from 'vue3-maplibre-gl';

const circleStyle = ref({
  'circle-radius': ['interpolate', ['linear'], ['zoom'], 5, 2, 15, 10],
  'circle-color': [
    'interpolate',
    ['linear'],
    ['get', 'magnitude'],
    1,
    '#ffffcc',
    5,
    '#fd8d3c',
    10,
    '#800026',
  ],
  'circle-stroke-width': 1,
  'circle-stroke-color': '#fff',
});

function onPointClick(event) {
  console.log('Point clicked:', event.features[0]);
}
</script>

LineLayer

A component for rendering lines from line data sources. Ideal for displaying routes, boundaries, and other linear features with customizable styling.

Props

PropTypeDefaultDescription
idstringundefinedUnique identifier for the layer
sourcestring | objectundefinedData source for the layer
sourceLayerstringundefinedSource layer name for vector sources
filterFilterSpecification['all']Filter expression to apply to the layer
styleLineLayerStyle{}Style configuration for the line layer
maxzoomnumber24Maximum zoom level for layer visibility
minzoomnumber0Minimum zoom level for layer visibility
metadataobjectundefinedArbitrary metadata for the layer
beforeIdstringundefinedID of layer before which to insert this layer
visiblebooleantrueWhether the layer is visible

Events

Same events as FillLayer (click, mousemove, etc.)

Example

vue
<template>
  <Maplibre :options="mapOptions">
    <GeoJsonSource :data="lineData">
      <LineLayer id="routes" :style="lineStyle" @click="onLineClick" />
    </GeoJsonSource>
  </Maplibre>
</template>

<script setup>
import { ref } from 'vue';
import { Maplibre, GeoJsonSource, LineLayer } from 'vue3-maplibre-gl';

const lineStyle = ref({
  'line-color': '#007cbf',
  'line-width': ['interpolate', ['linear'], ['zoom'], 5, 1, 15, 8],
  'line-opacity': 0.8,
});

function onLineClick(event) {
  console.log('Line clicked:', event.features[0]);
}
</script>

SymbolLayer

A component for rendering symbols (icons and text) from point data sources. Perfect for displaying labels, icons, and other symbolic representations on the map.

Props

PropTypeDefaultDescription
idstringundefinedUnique identifier for the layer
sourcestring | objectundefinedData source for the layer
sourceLayerstringundefinedSource layer name for vector sources
filterFilterSpecification['all']Filter expression to apply to the layer
styleSymbolLayerStyle{}Style configuration for the symbol layer
maxzoomnumber24Maximum zoom level for layer visibility
minzoomnumber0Minimum zoom level for layer visibility
metadataobjectundefinedArbitrary metadata for the layer
beforeIdstringundefinedID of layer before which to insert this layer
visiblebooleantrueWhether the layer is visible

Events

Same events as FillLayer (click, mousemove, etc.)

Example

vue
<template>
  <Maplibre :options="mapOptions">
    <GeoJsonSource :data="pointData">
      <SymbolLayer id="labels" :style="symbolStyle" @click="onSymbolClick" />
    </GeoJsonSource>
  </Maplibre>
</template>

<script setup>
import { ref } from 'vue';
import { Maplibre, GeoJsonSource, SymbolLayer } from 'vue3-maplibre-gl';

const symbolStyle = ref({
  'text-field': ['get', 'name'],
  'text-font': ['Open Sans Regular'],
  'text-size': 12,
  'text-color': '#333',
  'text-halo-color': '#fff',
  'text-halo-width': 1,
  'text-anchor': 'top',
  'text-offset': [0, 1],
});

function onSymbolClick(event) {
  console.log('Symbol clicked:', event.features[0]);
}
</script>

Marker

A component for adding HTML markers to the map. Supports custom HTML content, dragging, and comprehensive styling options.

Props

PropTypeDefaultDescription
lnglatLngLatLikeundefinedGeographic coordinates for the marker
popupPopupundefinedPopup to associate with the marker
optionsMarkerOptions{}Marker configuration options
draggablebooleanfalseWhether the marker is draggable
elementHTMLElementundefinedCustom HTML element for the marker
offsetPointLikeundefinedOffset from the marker's position
anchorAnchorundefinedAnchor point for the marker
colorstringundefinedColor of the default marker
clickTolerancenumberundefinedTolerance for click events
rotationnumberundefinedRotation angle in degrees
rotationAlignmentAlignmentundefinedRotation alignment relative to the map
pitchAlignmentAlignmentundefinedPitch alignment relative to the map
scalenumberundefinedScale factor for the marker
occludedOpacitynumberundefinedOpacity when marker is occluded

Events

EventPayloadDescription
dragstartEventFired when dragging starts
dragEventFired during dragging
dragendEventFired when dragging ends

Example

vue
<template>
  <Maplibre :options="mapOptions">
    <Marker
      :lng-lat="markerPosition"
      :draggable="true"
      @dragend="onMarkerDragEnd"
    >
      <div class="custom-marker">📍</div>
    </Marker>
  </Maplibre>
</template>

<script setup>
import { ref } from 'vue';
import { Maplibre, Marker } from 'vue3-maplibre-gl';

const markerPosition = ref([0, 0]);

function onMarkerDragEnd(event) {
  markerPosition.value = event.target.getLngLat().toArray();
  console.log('Marker moved to:', markerPosition.value);
}
</script>

<style>
.custom-marker {
  font-size: 24px;
  cursor: pointer;
}
</style>

A component for displaying popup windows on the map. Supports custom HTML content, positioning, and comprehensive event handling.

Props

PropTypeDefaultDescription
classNamestringundefinedCSS class name for the popup
lnglatLngLatLikeundefinedGeographic coordinates for the popup
showbooleantrueWhether the popup is visible
withMapbooleantrueWhether to attach popup to the map
optionsPopupOptions{}Popup configuration options
htmlstringundefinedHTML content for the popup
maxWidthstringundefinedMaximum width of the popup
closeButtonbooleantrueWhether to show close button
closeOnClickbooleantrueWhether to close on map click
closeOnEscapebooleantrueWhether to close on escape key

Events

EventPayloadDescription
closevoidFired when popup is closed
openvoidFired when popup is opened
update:showbooleanFired when show state changes (for v-model support)

Example

vue
<template>
  <Maplibre :options="mapOptions">
    <PopUp :lng-lat="popupPosition" :close-button="true" @close="onPopupClose">
      <div class="popup-content">
        <h3>Hello World!</h3>
        <p>This is a popup at {{ popupPosition }}.</p>
      </div>
    </PopUp>
  </Maplibre>
</template>

<script setup>
import { ref } from 'vue';
import { Maplibre, PopUp } from 'vue3-maplibre-gl';

const popupPosition = ref([0, 0]);

function onPopupClose() {
  console.log('Popup closed');
}
</script>

<style>
.popup-content {
  padding: 10px;
  max-width: 200px;
}
</style>

Image

A component for managing and loading images for use in MapLibre GL styles. Supports multiple image formats and provides loading state management.

Props

PropTypeDefaultDescription
imagesImageItem[][]Array of images to load
optionsPartial<StyleImageMetadata>{}Default options applied to all images
showLoadingbooleantrueWhether to show loading state
debugbooleanfalseWhether to enable debug logging

ImageItem Interface

PropertyTypeDescription
idstringUnique identifier for the image
imageImageDatas | stringImage data (URL string or ImageData/HTMLImageElement)
optionsPartial<StyleImageMetadata>Optional image metadata and options

Example

vue
<template>
  <Maplibre :options="mapOptions">
    <Image :images="mapImages" :show-loading="true" />
    <GeoJsonSource :data="pointData">
      <SymbolLayer :style="symbolStyle" />
    </GeoJsonSource>
  </Maplibre>
</template>

<script setup>
import { ref } from 'vue';
import { Maplibre, Image, GeoJsonSource, SymbolLayer } from 'vue3-maplibre-gl';

const mapImages = ref([
  {
    id: 'custom-marker',
    image: '/path/to/marker.png',
    options: { sdf: false },
  },
]);

const symbolStyle = ref({
  'icon-image': 'custom-marker',
  'icon-size': 1.5,
});
</script>

GeolocateControls

A component for adding geolocation controls to the map. Provides user location tracking with comprehensive event handling and error management.

Props

PropTypeDefaultDescription
positionControlPositionundefinedPosition of the control on the map
optionsGeolocateControlOptions{}Geolocate control configuration options
debugbooleanfalseEnable debug logging
autoCleanupbooleantrueAutomatically cleanup resources on unmount
onError(error: any) => voidundefinedError handling callback
onGeolocate(data: GeolocateSuccess) => voidundefinedSuccess callback for geolocation
onTrackingStart(data: GeolocateSuccess) => voidundefinedCallback when user location tracking starts
onTrackingEnd(data: GeolocateSuccess) => voidundefinedCallback when user location tracking ends
onOutOfMaxBounds(data: GeolocateSuccess) => voidundefinedCallback when user location is out of max bounds

Events

EventPayloadDescription
registerGeolocateControlFired when control is registered
geolocateGeolocateSuccessFired when geolocation is successful
errorGeolocationPositionErrorFired when geolocation error occurs
trackingstartGeolocateSuccessFired when location tracking starts
trackingendGeolocateSuccessFired when location tracking ends
outofmaxboundsGeolocateSuccessFired when location is out of max bounds

Example

vue
<template>
  <Maplibre :options="mapOptions">
    <GeolocateControls
      position="top-right"
      :options="geolocateOptions"
      @geolocate="onGeolocate"
      @error="onGeolocateError"
    />
  </Maplibre>
</template>

<script setup>
import { ref } from 'vue';
import { Maplibre, GeolocateControls } from 'vue3-maplibre-gl';

const geolocateOptions = ref({
  positionOptions: {
    enableHighAccuracy: true,
  },
  trackUserLocation: true,
  showUserHeading: true,
});

function onGeolocate(data) {
  console.log('User location:', data.coords);
}

function onGeolocateError(error) {
  console.error('Geolocation error:', error);
}
</script>

Released under the MIT License.