最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue使用openlayers創(chuàng)建地圖

 更新時(shí)間:2022年04月15日 09:55:45   作者:yuelianng0921  
這篇文章主要為大家詳細(xì)介紹了vue項(xiàng)目中使用openlayers創(chuàng)建地圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

vue項(xiàng)目中使用openlayers創(chuàng)建地圖,供大家參考,具體內(nèi)容如下

前期準(zhǔn)備

  • 安裝node環(huán)境
  • 安裝cnpm
  • 安裝vue-cli

以上步驟網(wǎng)上都有很多教程

搭建vue項(xiàng)目

vue create vue-ol

按照提示一步步搭建vue項(xiàng)目

cd vue-ol
npm run serve

瀏覽器打開(kāi) http://localhost:8080/ 就可以看到初始化的vue項(xiàng)目頁(yè)面

vue項(xiàng)目安裝openlayers

cnpm i ol --s

main.js中引入ol.css

import 'ol/ol.css';

創(chuàng)建地圖組件MapContainer.vue

<template>
? ? <div class="map" id="map"></div>
</template>

<script>
import Map from 'ol/Map';
import OSM from 'ol/source/OSM';
import TileLayer from 'ol/layer/Tile';
import View from 'ol/View';
import { fromLonLat } from 'ol/proj';
export default {
? ? name: "MapContainer",
?? ?methods:{
?? ??? ?createMap(){
?? ??? ??? ?let map = new Map({
?? ??? ??? ??? ?layers: [new TileLayer({
?? ??? ??? ??? ??? ?source: new OSM(),
?? ??? ??? ??? ?}) ],
?? ??? ??? ??? ?target: 'map',
?? ??? ??? ??? ?view: new View({
?? ??? ??? ??? ??? ?maxZoom: 18,
?? ??? ??? ??? ??? ?center: fromLonLat([108.92,34.28]),
?? ??? ??? ??? ??? ?zoom: 10,
?? ??? ??? ??? ?}),
?? ??? ??? ?});
?? ??? ?}
?? ?},
?? ?mounted(){
?? ??? ?this.createMap()
?? ?}
};
</script>

<style scoped>
.map {
? ? height: 100%;
? ? margin: 0;
? ? padding: 0;
? ? overflow: hidden;
? ? position: relative;
?? ?background: #1f3064;
}
</style>

在home.vue中引入地圖組件

<template>
? <div class="home">
? ? <MapContainer msg="Welcome to Your Vue.js App"/>
? </div>
</template>

<script>
import MapContainer from '@/components/MapContainer.vue'
export default {
? name: 'Home',
? components: {
? ? MapContainer
? }
}
</script>
<style>
.home{
?? ?height: 100%;
?? ?position: relative;
}
</style>

頁(yè)面截圖如下:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

化德县| 壤塘县| 子长县| 太和县| 兰州市| 林芝县| 灵台县| 葵青区| 内乡县| 河间市| 澄江县| 玉林市| 丽水市| 长岛县| 临武县| 石楼县| 新巴尔虎左旗| 金寨县| 永兴县| 会宁县| 荔浦县| 澳门| 鄱阳县| 梓潼县| 旬阳县| 高平市| 资阳市| 衡南县| 普宁市| 防城港市| 榆林市| 织金县| 申扎县| 巫山县| 安庆市| 沁源县| 吴堡县| 北宁市| 内江市| 庆城县| 孝义市|