GIS
vue3-openlayers
원2
2024. 6. 14. 18:10
728x90
반응형
시작하기
필요버전
- ol: ^9.1.0
- ol-contextmenu: ^5.4.0
- ol-ext: ^4.0.15
- vue: ^3.4.0
인스톨 npm 기준
npm i ol ol-ext ol-contextmenu # install the peerDependencies
npm i vue3-openlayers # install this library
main.js or main.ts
import { createApp } from "vue";
import App from "./App.vue";
// The style are only needed for some map controls.
// However, you can also style them by your own
import "vue3-openlayers/styles.css"; // 추가
import OpenLayersMap from "vue3-openlayers"; // 추가
const app = createApp(App);
app.use(OpenLayersMap /*, options */); // 추가(전역설정)
app.mount("#app");
기본적인 map 띄우기
* ol 태그가 노란줄로 인식이 안될 수 있는데 무시하고 실행하면 나옴
<template>
<form>
<label for="zoom">Zoom:</label>
<input type="number" id="zoom" v-model="zoom" />
</form>
<ol-map style="height: 400px">
<ol-view
ref="view"
:center="center"
:rotation="rotation"
:zoom="zoom"
:projection="projection"
@change:center="centerChanged"
@change:resolution="resolutionChanged"
@change:rotation="rotationChanged"
/>
<ol-tile-layer>
<ol-source-osm />
</ol-tile-layer>
<ol-rotate-control></ol-rotate-control>
<ol-interaction-link />
</ol-map>
<ul>
<li>center : {{ currentCenter }}</li>
<li>resolution : {{ currentResolution }}</li>
<li>zoom : {{ currentZoom }}</li>
<li>rotation : {{ currentRotation }}</li>
</ul>
</template>
<script setup>
import { ref } from "vue";
const center = ref([40, 40]);
const projection = ref("EPSG:4326");
const zoom = ref(8);
const rotation = ref(0);
const currentCenter = ref(center.value);
const currentZoom = ref(zoom.value);
const currentRotation = ref(rotation.value);
const currentResolution = ref(0);
function resolutionChanged(event) {
currentResolution.value = event.target.getResolution();
currentZoom.value = event.target.getZoom();
}
function centerChanged(event) {
currentCenter.value = event.target.getCenter();
}
function rotationChanged(event) {
currentRotation.value = event.target.getRotation();
}
</script>
<style scoped>
.ol-map {
position: relative;
}
.ol-map-loading:after {
content: "";
box-sizing: border-box;
position: absolute;
top: 50%;
left: 50%;
width: 80px;
height: 80px;
margin-top: -40px;
margin-left: -40px;
border-radius: 50%;
border: 5px solid rgba(180, 180, 180, 0.6);
border-top-color: var(--vp-c-brand-1);
animation: spinner 0.6s linear infinite;
}
@keyframes spinner {
to {
transform: rotate(360deg);
}
}
</style>
성공ㅋ
728x90
반응형