Vue + OpenLayers 快速入門學習教程
Openlayers 是一個模塊化、高性能并且功能豐富的WebGIS客戶端的JavaScript包,用于顯示地圖及空間數(shù)據(jù),并與之進行交互,具有靈活的擴展機制。
簡單來說,使用 Openlayers(后面簡稱ol) 可以很靈活自由的做出各種地圖和空間數(shù)據(jù)的展示。而且這個框架是完全免費和開源的。
前言
本文記錄 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>
到此這篇關于Vue + OpenLayers 快速入門學習教程的文章就介紹到這了,更多相關Vue OpenLayers入門內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
element ui table(表格)實現(xiàn)點擊一行展開功能
這篇文章主要給大家介紹了關于element ui table(表格)實現(xiàn)點擊一行展開功能的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2018-12-12前端element-ui兩層dialog嵌套遮罩層消失的問題解決辦法
最近使用vue+elementUI做項目,使用過程中很多地方會用到dialog這個組件,有好幾個地方用到了dialog的嵌套,這篇文章主要給大家介紹了關于前端element-ui兩層dialog嵌套遮罩層消失的問題解決辦法,需要的朋友可以參考下2024-08-08element-ui 中使用upload多文件上傳只請求一次接口
這篇文章主要介紹了element-ui 中使用upload多文件上傳只請求一次接口,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-07-07Nuxt封裝@nuxtjs/axios請求后端數(shù)據(jù)方式
這篇文章主要介紹了Nuxt封裝@nuxtjs/axios請求后端數(shù)據(jù)方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-10-10