初始化vue项目:
在ol.vue中加入以下代码;
<template>
<div id="map" ref="rootmap"></div>
</template>
<script>
import "ol/ol.css";
import { Map, View } from "ol";
import TileLayer from "ol/layer/Tile";
import OSM from "ol/source/OSM";
export default {
name: "ol",
data() {
return {
message: "ol-test",
map: null,
};
},
mounted() {
var mapcontainer = this.$refs.rootmap;
this.map = new Map({
target: "map",
layers: [
new TileLayer({
source: new OSM(),
}),
],
view: new View({
projection: "EPSG:4326", //使用这个坐标系
center: [114.0839, 22.8857], //深圳
zoom: 12,
}),
});
},
methods: {},
};
</script>
<style scoped>
#map {
height: 100%;
}
/*隐藏ol的一些自带元素*/
.ol-attribution,
.ol-zoom {
display: none;
}
</style>
保存运行,bingo.
随笔记录
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- fupindai.com 版权所有 赣ICP备2024042792号-2
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务