Openlayers 是一个模块化、高性能并且功能丰富的WEBGIS客户端的javascript包,用于显示地图及空间数据,并与之进行交互,具有灵活的扩展机制。 简单来说,使用 O
Openlayers 是一个模块化、高性能并且功能丰富的WEBGIS客户端的javascript包,用于显示地图及空间数据,并与之进行交互,具有灵活的扩展机制。
简单来说,使用 Openlayers(后面简称ol) 可以很灵活自由的做出各种地图和空间数据的展示。而且这个框架是完全免费和开源的。
本文记录 Vue 使用 OpenLayers 入门,使用 OpenLayers 创建地图组件,分别使用 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).
官方地址:https://openlayers.org/
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 快速入门学习教程的文章就介绍到这了,更多相关Vue OpenLayers入门内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: Vue + OpenLayers 快速入门学习教程
本文链接: https://www.lsjlt.com/news/135777.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-01-12
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0