地图展示
示例
代码实现
vue
<template>
<div id="map" class="w-full h-96"></div>
</template>
<script setup>
import { onMounted } from "vue";
import "ol/ol.css";
import Map from "ol/Map";
import View from "ol/View";
import TileLayer from "ol/layer/Tile";
import XYZ from "ol/source/XYZ";
import { fromLonLat } from "ol/proj";
onMounted(() => {
const map = new Map({
target: "map",
layers: [
new TileLayer({
source: new XYZ({
url: "http://{a-c}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png",
}),
}),
],
view: new View({
center: fromLonLat([-0.09, 51.505]),
zoom: 13,
}),
});
});
</script>
<style scoped>
.w-full {
width: 100%;
}
.h-96 {
height: 24rem;
}
</style>