Show how to add a map view through typescript
This commit is contained in:
parent
0126d24242
commit
1e67c0090d
7 changed files with 254 additions and 5 deletions
38
ts/components/map-view.vue
Normal file
38
ts/components/map-view.vue
Normal 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>
|
||||
Loading…
Add table
Add a link
Reference in a new issue