leaflet本体とdrawパッケージをインストール
$ yarn add leaflet leaflet-draw
Vueのソース
<script setup>
import {onMounted} from 'vue';
import L from 'leaflet';
import 'leaflet-draw';
import 'leaflet/dist/leaflet.css';
import 'leaflet-draw/dist/leaflet.draw.css';
let map;
onMounted(() => {
if (map != undefined) map.remove();
map = L.map('map').setView([35.6759323, 139.7450316], 18);
L
.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png')
.addTo(map);
var drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);
var drawControl = new L.Control.Draw({
edit: {
featureGroup: drawnItems
}
});
map.addControl(drawControl);
});
</script>
<template>
<div id="map" style="width: 100%; height: 100%"></div>
</template>
線を引いたり、円を描いたりできる。