Vue + OpenLayers 快速入門學(xué)習(xí)教程
Openlayers 是一個(gè)模塊化、高性能并且功能豐富的WebGIS客戶端的JavaScript包,用于顯示地圖及空間數(shù)據(jù),并與之進(jìn)行交互,具有靈活的擴(kuò)展機(jī)制。
簡單來說,使用 Openlayers(后面簡稱ol) 可以很靈活自由的做出各種地圖和空間數(shù)據(jù)的展示。而且這個(gè)框架是完全免費(fèi)和開源的。
前言
本文記錄 Vue 使用 OpenLayers 入門,使用 OpenLayers 創(chuàng)建地圖組件,分別使用 OpenLayers 提供的地圖和本地圖片做為地圖。
Overview
OpenLayers makes it easy to put a dynamic map in any web page. It can display map tiles, vector data and markers loaded from any source. OpenLayers has been developed to further the use of geographic information of all kinds. It is completely free, Open Source JavaScript, released under the 2-clause BSD License (also known as the FreeBSD).
1. 安裝 OpenLayers 庫
cnpm install ol
2. Vue 創(chuàng)建 OpenLayers 組件
效果圖

Code
<template>
<div id="map" class="map"></div>
</template>
<script>
import "ol/ol.css";
import Map from "ol/Map";
import OSM from "ol/source/OSM";
import TileLayer from "ol/layer/Tile";
import View from "ol/View";
export default {
mounted() {
this.initMap();
},
methods: {
initMap() {
new Map({
layers: [
new TileLayer({
source: new OSM()
})
],
target: "map",
view: new View({
center: [0, 0],
zoom: 2
})
});
console.log("init finished");
}
}
};
</script>
<style>
.map {
width: 100%;
height: 400px;
}
</style>
3. OpenLayers 使用本地圖片作為地圖
效果圖:
Code
<template>
<div>
<div id="map" class="map"></div>
</div>
</template>
<script>
import "ol/ol.css";
import ImageLayer from "ol/layer/Image";
import Map from "ol/Map";
import Projection from "ol/proj/Projection";
import Static from "ol/source/ImageStatic";
import View from "ol/View";
import { getCenter } from "ol/extent";
let extent = [0, 0, 338, 600];
let projection = new Projection({
code: "xkcd-image",
units: "pixels",
extent: extent
});
export default {
data() {
return {
map: {}
};
},
mounted() {
this.initMap();
},
methods: {
initMap() {
this.map = new Map({
layers: [
new ImageLayer({
source: new Static({
attributions: '© <a rel="external nofollow" >xkcd</a>',
url: "http://localhost:8080/img/123.5cba1af6.jpg",
projection: projection,
imageExtent: extent
})
})
],
target: "map",
view: new View({
projection: projection,
center: getCenter(extent),
zoom: 1,
maxZoom: 4,
minZoom: 1
})
});
}
}
};
</script>
<style>
.map {
width: 100%;
height: 400px;
}
</style>
到此這篇關(guān)于Vue + OpenLayers 快速入門學(xué)習(xí)教程的文章就介紹到這了,更多相關(guān)Vue OpenLayers入門內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Vue利用openlayers實(shí)現(xiàn)點(diǎn)擊彈窗的方法詳解
- Vue使用openlayers實(shí)現(xiàn)繪制圓形和多邊形
- Vue結(jié)合Openlayers使用Overlay添加Popup彈窗實(shí)現(xiàn)
- vue使用openlayers創(chuàng)建地圖
- Vue+Openlayers實(shí)現(xiàn)實(shí)時(shí)坐標(biāo)點(diǎn)展示
- vue利用openlayers加載天地圖和高德地圖
- VUE + OPENLAYERS實(shí)現(xiàn)實(shí)時(shí)定位功能
- vue+openlayers繪制省市邊界線
- Vue openLayers實(shí)現(xiàn)圖層數(shù)據(jù)切換與加載流程詳解
相關(guān)文章
一篇文章告訴你Vue3指令是如何實(shí)現(xiàn)的
在計(jì)算機(jī)技術(shù)中,指令是由指令集架構(gòu)定義的單個(gè)的CPU操作,在更廣泛的意義上,“指令”可以是任何可執(zhí)行程序的元素的表述,例如字節(jié)碼,下面這篇文章主要給大家介紹了關(guān)于Vue3指令是如何實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下2022-01-01
vue路由傳參-如何使用encodeURI加密參數(shù)
這篇文章主要介紹了vue路由傳參-如何使用encodeURI加密參數(shù),具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-06-06
vue項(xiàng)目中chunk-vendors.js提示報(bào)錯(cuò)的查看方法(最新推薦)
在vue項(xiàng)目中,chunk-vendors.js報(bào)出的錯(cuò)誤提示經(jīng)常會(huì)導(dǎo)致開發(fā)者困惑,正確查看錯(cuò)誤的方法是從錯(cuò)誤提示的詳細(xì)信息中找到報(bào)錯(cuò)原因,下面給大家分享vue項(xiàng)目中chunk-vendors.js提示報(bào)錯(cuò)的查看方法,感興趣的朋友一起看看吧2024-12-12
Vue無法讀取HTMLCollection列表的length問題解決
這篇文章主要介紹了Vue無法讀取HTMLCollection列表的length問題解決方案,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03
vue自定義指令和動(dòng)態(tài)路由實(shí)現(xiàn)權(quán)限控制
這篇文章主要介紹了vue自定義指令和動(dòng)態(tài)路由實(shí)現(xiàn)權(quán)限控制的方法,幫助大家更好的理解和學(xué)習(xí)vue,感興趣的朋友可以了解下2020-08-08
VUE 無限層級(jí)樹形數(shù)據(jù)結(jié)構(gòu)顯示的實(shí)現(xiàn)
在做項(xiàng)目中,會(huì)遇到一些樹形的數(shù)據(jù)結(jié)構(gòu),常用在左側(cè)菜單導(dǎo)航,本文就介紹一下如何實(shí)現(xiàn),感興趣的可以了解一下2021-07-07
vue-resource?獲取本地json數(shù)據(jù)404問題的解決
這篇文章主要介紹了vue-resource?獲取本地json數(shù)據(jù)404問題的解決方案,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10

