Show how to add a map view through typescript

This commit is contained in:
Eli Ribble 2026-03-21 18:13:40 +00:00
parent 0126d24242
commit 1e67c0090d
No known key found for this signature in database
7 changed files with 254 additions and 5 deletions

View file

@ -0,0 +1,38 @@
<script setup lang="ts">
import { onMounted, onUnmounted, ref } from 'vue';
import maplibregl from 'maplibre-gl';
const mapContainer = ref<HTMLDivElement | null>(null);
let map: maplibregl.Map | null = null;
onMounted(() => {
if (!mapContainer.value) return;
map = new maplibregl.Map({
container: mapContainer.value,
style: 'https://demotiles.maplibre.org/style.json',
center: [-74.5, 40], // [lng, lat]
zoom: 9
});
// Add a marker as an example
new maplibregl.Marker()
.setLngLat([-74.5, 40])
.addTo(map);
});
onUnmounted(() => {
map?.remove();
});
</script>
<template>
<div ref="mapContainer" class="map-container"></div>
</template>
<style scoped>
.map-container {
width: 100%;
height: 500px;
}
</style>