您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關Vue如何創建OpenLayers組件的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
cnpm install ol
<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>
<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 href="http://xkcd.com/license.html" 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組件”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。