要将leaflet集成到Vue项目中,首先需要安装Leaflet和Vue2-leaflet插件。
npm install leaflet vue2-leaflet
import { LMap, LTileLayer, LMarker } from 'vue2-leaflet';
import 'leaflet/dist/leaflet.css';
export default {
components: {
LMap,
LTileLayer,
LMarker,
}
}
<template>
<l-map
style="height: 400px;"
:zoom="zoom"
:center="center"
>
<l-tile-layer
:url="url"
></l-tile-layer>
<l-marker
:lat-lng="marker"
></l-marker>
</l-map>
</template>
data() {
return {
zoom: 13,
center: [37.7749, -122.4194],
url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
marker: [37.7749, -122.4194],
};
}
通过以上步骤,您可以将Leaflet集成到Vue项目中,并在Vue组件中使用Leaflet地图组件。