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

vue利用openlayers加載天地圖和高德地圖

 更新時間:2022年04月20日 14:41:46   作者:~HT貓L~  
這篇文章主要介紹了?vue利用openlayers加載天地圖和高德地圖,下文章主要由兩部分完成openlayers加載天地圖和加載高德地圖,下面來看看詳細內(nèi)容吧,需要的朋友可以參考一下,希望對大家有所幫助

一、天地圖部分

1、在vue中安裝openlayers

npm i --save ol

這里說的vue是基于腳手架構(gòu)建的。 新建個頁面,也就是vue文件,配置好路由。接著就是可以直接放入我的代碼運行顯示了。

vue利用openlayers加載天地圖和高德地圖
<template>
  <div class="wrapper">
    <div>天地圖</div>
    <div class="map" id="olMap"></div>
  </div>
</template>
<script>
import "ol/ol.css";
import {
  Tile as TileLayer } from "ol/layer";
import XYZ from "ol/source/XYZ";
import {
  defaults as defaultControls } from "ol/control";
import Map from "ol/Map.js";
import View from "ol/View.js";
export default {
  data() {
   return {
      map: null,
      parser: null,
    };
  },
  mounted() {
    this.initMap();
  },
  methods: {
    initMap() {
     const map = new Map({
       target: "olMap",
        view: new View({
 
          center: [0, 0], //中心點經(jīng)緯度
          zoom: 4, //圖層縮放大小
          projection: "EPSG:4326",
        }),
        controls: defaultControls({
          zoom: true,
          attribution: false,
          rotate: false,
        }),
      });
      this.map = map;
      // 添加地圖
      let url = "http://t{0-7}.tianditu.com/DataServer?x={x}&y={y}&l={z}";
      url = `${
   url}&T=vec_c&tk=替代你的key`;
      const source = new XYZ({
     url: url,
        projection: "EPSG:4326",
      });
      const tdtLayer = new TileLayer({
        source: source,
      });
      this.map.addLayer(tdtLayer);
      // 添加注記
      url = "http://t{0-7}.tianditu.com/DataServer?x={x}&y={y}&l={z}";
      url = `${
   url}&T=cva_c&tk=替代你的key`;
      const sourceCVA = new XYZ({
        url: url,
        projection: "EPSG:4326",
      });
      const tdtcvaLayer = new TileLayer({
        source: sourceCVA,
      });
      this.map.addLayer(tdtcvaLayer);
    },
  },
};
</script>
<style scoped>
.map {
  width: 100%;
  height: 100vh;
}
</style>

天地圖就可以顯示出來了。

效果圖:

二、高德地圖部分

相對于天地圖,高德地圖就容易多了,直接上代碼

<template>
  <div class="wrapper">
    <div>高德地圖</div>
    <div id="map"></div>
  </div>
</template>
<script>
import {
 Map,View,Feature} from 'ol'

import * as olProj from 'ol/proj'
import {
 Point} from 'ol/geom'
import {
  Style, Fill, Stroke, Circle as sCircle } from "ol/style";
// 添加圖層
import Tilelayer from 'ol/layer/Tile'
import {
 Vector as VectorLayer} from 'ol/layer'
import {
 XYZ,Vector as VectorSource} from 'ol/source'
//引入樣式文件
import "ol/ol.css"
export default {
  data() {
  return {
    map:null
    }
  },
  mounted() {
  this.init();
   this.setMarker();
  },
  methods: {
    init(){
       this.map=new Map({
         target:'map',
         layers:[new Tilelayer({
           source: new XYZ({
               url:'https://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}',
           })
         })
         ],
        view:new View({

            // 將西安作為地圖中心 
            // olProj.fromLonLat方法將經(jīng)緯度轉(zhuǎn)換成對應(yīng)的坐標
          center:olProj.fromLonLat([108.945951, 34.465262]),
          zoom:2
        }),
       })
    },
    setMarker(){
        let _style = new Style({
            image:new sCircle({
                radius:10,
                stroke:new Stroke({
                    color:"#fff",
                }),
                fill: new Fill({
                    color:'#3399CC',
                }),
            }),
        });
        let _feature = new Feature({
 
            geometry:new Point(olProj.fromLonLat([108.945951, 34.465262])),
        });
        _feature.setStyle(_style);
        let _marker = new VectorLayer({

            source: new VectorSource({
               feature:[_feature],
            }),
        });
        this.map.addLayer(_marker);
    },
  },
}
</script>
<style scoped>
  #map{
      /* 屏幕寬高 */
    width: 100vw;
    height: 100vh;
  }
</style>

到此這篇關(guān)于 vue利用openlayers加載天地圖和高德地圖的文章就介紹到這了,更多相關(guān)openlayers加載天地圖和高德地圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue 組件高級用法實例詳解

    vue 組件高級用法實例詳解

    這篇文章主要介紹了vue 組件高級用法,需要的朋友可以參考下
    2018-04-04
  • vue實現(xiàn)聊天框發(fā)送表情

    vue實現(xiàn)聊天框發(fā)送表情

    這篇文章主要為大家詳細介紹了vue實現(xiàn)聊天框發(fā)送表情,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • vue 實現(xiàn)小程序或商品秒殺倒計時

    vue 實現(xiàn)小程序或商品秒殺倒計時

    這篇文章主要介紹了vue 實現(xiàn)倒計時秒殺的組件,緊接著通過實例代碼給大家介紹小程序或者vue商品秒殺倒計時功能,需要的朋友可以參考下
    2019-04-04
  • vue使用docxtemplater導(dǎo)出word

    vue使用docxtemplater導(dǎo)出word

    docxtemplater?是一種郵件合并工具,以編程方式使用并處理條件、循環(huán),并且可以擴展以插入任何內(nèi)容,下面我們來看看如何使用docxtemplater導(dǎo)出word吧
    2025-04-04
  • vue踩坑日記之params傳遞參數(shù)問題

    vue踩坑日記之params傳遞參數(shù)問題

    這篇文章主要介紹了vue踩坑日記之params傳遞參數(shù)問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-05-05
  • uniapp中使用lottie實現(xiàn)JSON動畫的操作步驟

    uniapp中使用lottie實現(xiàn)JSON動畫的操作步驟

    這篇文章主要介紹了如何在項目中使用JSON動畫組件,包括創(chuàng)建目錄結(jié)構(gòu)、下載JSON文件、編寫自定義組件代碼以及組件的使用方法,文中通過代碼介紹的非常詳細,需要的朋友可以參考下
    2025-01-01
  • vue 動態(tài)添加/刪除dom元素節(jié)點的操作代碼

    vue 動態(tài)添加/刪除dom元素節(jié)點的操作代碼

    這篇文章主要介紹了vue 動態(tài)添加/刪除dom元素,需要在點擊添加時,增加一行key/value的輸入框;點擊垃圾桶圖標時,刪除對應(yīng)行,本文結(jié)合實例代碼給大家講解的非常詳細,需要的朋友可以參考下
    2022-12-12
  • vue頁面圖片不顯示問題解決方案

    vue頁面圖片不顯示問題解決方案

    這篇文章主要介紹了vue頁面圖片不顯示問題解決方案,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下
    2021-09-09
  • Vue中EpicEditor和vue-quill-editor的使用詳解

    Vue中EpicEditor和vue-quill-editor的使用詳解

    EpicEditor和Vue-quill-editor都是基于Quill.js的富文本編輯器,并且都提供了許多強大的功能,下面我們就來介紹一下二者的具體使用,感興趣的小伙伴可以了解一下
    2023-11-11
  • Vue中l(wèi)ocalStorage那些你不知道的知識分享

    Vue中l(wèi)ocalStorage那些你不知道的知識分享

    在Vue.js中,?Vuex是一個強大的狀態(tài)管理工具,而localStorage則是一種用于存儲和獲取本地數(shù)據(jù)的機制,雖然這兩個東西都可以用來存儲數(shù)據(jù),但它們之間還是有很大的區(qū)別,本文就來簡單說說吧
    2023-05-05

最新評論

奉新县| 顺平县| 乐昌市| 迁安市| 濮阳县| 合水县| 陕西省| 宣威市| 呼伦贝尔市| 电白县| 佛坪县| 曲阜市| 满洲里市| 福安市| 高雄县| 广南县| 上林县| 乌恰县| 利川市| 大埔县| 个旧市| 永平县| 襄汾县| 讷河市| 河南省| 江山市| 德惠市| 栖霞市| 蒲江县| 工布江达县| 洪湖市| 平乡县| 东乌珠穆沁旗| 中山市| 克东县| 东乡族自治县| 大足县| 招远市| 乐都县| 买车| 宁明县|