欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue+OpenLayers?創(chuàng)建地圖并顯示鼠標(biāo)所在經(jīng)緯度(完整代碼)

 更新時(shí)間:2023年11月09日 09:27:25   作者:L221545  
這篇文章主要介紹了Vue+OpenLayers?創(chuàng)建地圖并顯示鼠標(biāo)所在經(jīng)緯度,本文使用的是高德地圖,結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

1、效果

2、創(chuàng)建地圖

本文用的是高德地圖
頁(yè)面

 <div class="map" id="map"></div>
                    <div id="mouse-position" class="position_coordinate"></div>

初始化地圖

     var gaodeLayer = new TileLayer({
          title: "高德地圖",
          source: new XYZ({
            url: 'http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}',
            wrapX: false
          })
        });
        this.map = new Map({
          layers: [gaodeLayer],
          target: 'map',
          view: new View({
            center: transform([123.23, 25.73], 'EPSG:4326', 'EPSG:3857'), //地圖初始中心點(diǎn)
            projection: 'EPSG:3857',
            zoom: 4,
            minZoom: 1
          }),
        });

3、添加經(jīng)緯度

   var mousePositionControl = new MousePosition({
          coordinateFormat: function (coordinate) {
            return formatAxirs(coordinate, '經(jīng)度:{x} 緯度:{y}', 2);
          },
          projection: 'EPSG:4326',
          className: "custom-mouse-position",
          target: document.getElementById("mouse-position"), //將位置數(shù)據(jù)放到那里
          undefinedHTML: "",
        });
        this.map.addControl(mousePositionControl);

4、完整代碼

<script>
import { Map, View } from "ol";
    import TileLayer from 'ol/layer/Tile.js';
  import XYZ from 'ol/source/XYZ.js';
  import { get as getProjection, transform } from 'ol/proj.js';
    import MousePosition from "ol/control/MousePosition";
   import { format as formatAxirs } from 'ol/coordinate';
  export default {
    data() {
  return {
         map: null,
        draw: null,
      };
    },
    mounted() {
      this.initMap();
    },
      methods: {
     //初始化地圖
      initMap() {
        var gaodeMapLayer = new TileLayer({
          title: "高德地圖",
          source: new XYZ({
            url: 'http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}',
            wrapX: false
          })
        });
        this.map = new Map({
          layers: [gaodeMapLayer],
          target: 'map',
          view: new View({
            center: transform([103.23, 35.33], 'EPSG:4326', 'EPSG:3857'), //地圖初始中心點(diǎn)
            projection: 'EPSG:3857',
            zoom: 4,
            minZoom: 1
          }),
        });
        // 獲取鼠標(biāo)在地圖的經(jīng)緯度
        var mousePositionControl = new MousePosition({
          coordinateFormat: function (coordinate) {
            return formatAxirs(coordinate, '經(jīng)度:{x} 緯度:{y}', 2);
          },
          projection: 'EPSG:4326',
          className: "custom-mouse-position",
          target: document.getElementById("mouse-position"), //將位置數(shù)據(jù)放到那里
          undefinedHTML: "",
        });
        this.map.addControl(mousePositionControl);
      },
}
}

附css代碼

  .position_coordinate {
    color: #6a6a6a;
    position: absolute;
    font-size: 14px;
    bottom: 20px;
    right: 20px;
    z-index: 999;
    text-align: center;
    line-height: 30px;
  }

到此這篇關(guān)于Vue+OpenLayers 創(chuàng)建地圖并顯示鼠標(biāo)所在經(jīng)緯度的文章就介紹到這了,更多相關(guān)Vue OpenLayers 鼠標(biāo)經(jīng)緯度內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue.js學(xué)習(xí)筆記:如何加載本地json文件

    vue.js學(xué)習(xí)筆記:如何加載本地json文件

    這篇文章主要介紹了vue.js學(xué)習(xí)筆記:如何加載本地json文件,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧。
    2017-01-01
  • vue3+pinia用戶信息持久緩存token的問(wèn)題解決

    vue3+pinia用戶信息持久緩存token的問(wèn)題解決

    本文主要介紹了vue3+pinia用戶信息持久緩存token的問(wèn)題解決,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-07-07
  • vue router學(xué)習(xí)之動(dòng)態(tài)路由和嵌套路由詳解

    vue router學(xué)習(xí)之動(dòng)態(tài)路由和嵌套路由詳解

    本篇文章主要介紹了vue router 動(dòng)態(tài)路由和嵌套路由,詳細(xì)的介紹了動(dòng)態(tài)路由和嵌套路由的使用方法,有興趣的可以了解一下
    2017-09-09
  • 如何在vue3+ts項(xiàng)目中使用query和params傳參

    如何在vue3+ts項(xiàng)目中使用query和params傳參

    Vue3中的路由傳參有兩種方式:query和params,下面這篇文章主要給大家介紹了關(guān)于如何在vue3+ts項(xiàng)目中使用query和params傳參的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-04-04
  • vue  composition-api 封裝組合式函數(shù)的操作方法

    vue  composition-api 封裝組合式函數(shù)的操作方法

    在 Vue 應(yīng)用的概念中,“組合式函數(shù)”(Composables) 是一個(gè)利用 Vue 的組合式 API 來(lái)封裝和復(fù)用有狀態(tài)邏輯的函數(shù),這篇文章主要介紹了vue  composition-api 封裝組合式函數(shù)的操作方法,需要的朋友可以參考下
    2022-10-10
  • Vue3父子組件傳參有關(guān)sync修飾符的用法詳解

    Vue3父子組件傳參有關(guān)sync修飾符的用法詳解

    這篇文章主要給大家介紹關(guān)于前端Vue3父子組件傳參有關(guān)sync修飾符的用法詳細(xì)解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助
    2021-09-09
  • vue2.0 實(shí)現(xiàn)富文本編輯器功能

    vue2.0 實(shí)現(xiàn)富文本編輯器功能

    這篇文章主要介紹了vue2.0 實(shí)現(xiàn)富文本編輯器功能,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下
    2019-05-05
  • 在VUE中使用lodash的debounce和throttle操作

    在VUE中使用lodash的debounce和throttle操作

    這篇文章主要介紹了在VUE中使用lodash的debounce和throttle操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-11-11
  • 解決vue.js 數(shù)據(jù)渲染成功仍報(bào)錯(cuò)的問(wèn)題

    解決vue.js 數(shù)據(jù)渲染成功仍報(bào)錯(cuò)的問(wèn)題

    今天小編就為大家分享一篇解決vue.js 數(shù)據(jù)渲染成功仍報(bào)錯(cuò)的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-08-08
  • vue?echarts移動(dòng)端踩坑解決記錄

    vue?echarts移動(dòng)端踩坑解決記錄

    這篇文章主要為大家介紹了vue?echarts移動(dòng)端踩坑解決記錄,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-07-07

最新評(píng)論