Interactive Maps
Create beautiful, interactive maps with MapLibre GL JS and Vue 3 components with reactive data binding.
Build interactive maps with ease using Vue 3 and MapLibre GL JS
Install the package:
# Using yarn
yarn add vue3-maplibre-gl
# Using npm
npm install vue3-maplibre-gl
Use in your Vue 3 application:
<template>
<Mapbox :options="mapOptions" style="height: 500px" @load="onMapLoad">
<GeoJsonSource :data="geoJsonData">
<FillLayer :style="fillStyle" />
<CircleLayer :style="circleStyle" />
</GeoJsonSource>
<Marker :lnglat="[0, 0]" :draggable="true">
<div class="marker">π</div>
</Marker>
<PopUp :lnglat="[0, 0]" :show="showPopup">
<div class="popup-content">
<h3>Welcome to Vue MapLibre GL!</h3>
<p>Interactive maps made easy with Vue 3</p>
</div>
</PopUp>
</Mapbox>
</template>
<script setup>
import { ref } from 'vue';
import {
Mapbox,
GeoJsonSource,
FillLayer,
CircleLayer,
Marker,
PopUp,
} from 'vue3-maplibre-gl';
import 'vue3-maplibre-gl/dist/style.css';
const mapOptions = ref({
style: 'https://demotiles.maplibre.org/style.json',
center: [0, 0],
zoom: 2,
});
const geoJsonData = ref({
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: { type: 'Point', coordinates: [0, 0] },
properties: { name: 'Sample Point' },
},
],
});
const fillStyle = ref({
'fill-color': '#088',
'fill-opacity': 0.8,
});
const circleStyle = ref({
'circle-radius': 6,
'circle-color': '#007cbf',
});
const showPopup = ref(true);
function onMapLoad(map) {
console.log('Map loaded:', map);
}
</script>
<style>
.marker {
font-size: 24px;
cursor: pointer;
}
.popup-content {
padding: 10px;
max-width: 200px;
}
</style>