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

vue 使用高德地圖vue-amap組件過程解析

 更新時間:2019年09月07日 14:17:17   作者:muamaker  
這篇文章主要介紹了vue 使用高德地圖vue-amap組件過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下

這篇文章主要介紹了vue 使用高德地圖vue-amap組件過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下

首先

npm install -S vue-amap

然后在 main.js

import VueAMap from 'vue-amap'; //注意不要和 AMap原始名稱覆蓋
Vue.use(VueAMap);
// 初始化vue-amap
VueAMap.initAMapApiLoader({
 // 高德的key
 key: 'you key',
 // 插件集合
 plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor','AMap.Geolocation'],
 v: '1.4.4'
});

map.vue文件

其中有個BUS.js,是基于觀察者模式的發(fā)布訂閱封裝

<template>
  <div class="_map">
    <div class="amap-page-container">
      <el-amap-search-box class="search-box" :search-option="searchOption" :on-search-result="onSearchResult" ></el-amap-search-box>
     <el-amap ref="map" vid="amapDemo" :plugin="plugin" :zoom="zoom" :center="center" class="amap-demo" :events="events">
      <el-amap-marker vid="component-marker" :position="makerConf.position" :content="makerConf.content" ></el-amap-marker>
     </el-amap>
    </div>
    <div class="adrs">
      <ul>
        <li class="" v-for="(item,index) in list" :key="index" :class="currIndex == index ? 'active':''" @click="select(item,index)">
          <p class="address">{{item.address}}</p>
          <p class="nm">{{item.name}}</p>
        </li>
      </ul>
    </div>
  </div>
 </template>
 
 <style>
  .amap-page-container{
    height: 300px;
    position: relative;
  }
  .search-box {
   position: absolute !important;
   top: 25px;
   left: 20px;
   z-index: 200 !important;
  }
  .amap-demo {
   height: 300px;
  }
  .amap-logo {
      display: none;
   }
  .amap-copyright {
     bottom:-100px;
      display: none;
  } 
  .amap-scalecontrol{
    bottom: 4px !important;
  }
  .amap-geolocation-con{
    bottom: 30px !important;
    z-index: 199 !important;
  }
  ul li.active{
    color: deeppink;
  }
 </style>
 <script>   
  export default {
   name: 'amap-page',
   components: {},
   data() {
    var me = this;
    me.city = me.city || '武漢';
    return {
     list:[], 
     currIndex:0,
     zoom: 16,
     center: [114.397169, 30.50576],
     events:{
       init: (o) => {
       o.setCity(me.city,result => {
        console.log("----------setCity",result);
        if(result && result.length > 0){
          me.zoom = 16;
          me.makerConf.position = result;
          me.getList(result);
        }
       });
       //去掉logo
       document.getElementsByClassName("amap-logo")[0].style.display = "none";
      },
      "dragend":function(e){
        //console.log("dragging",e,this.getCenter());
        var point = this.getCenter();
        var pos = [point.lng,point.lat];
        me.makerConf.position = [point.lng,point.lat];
        me.getList(pos);
      }
     },
     makerConf: {
      position: [114.397169, 30.50576],
      content:""
     },
     searchOption: {
      city: me.city,
      citylimit: true
     },
     plugin:[
      'ToolBar',
      'Scale',
      {
      pName: 'Geolocation',
      events: {
       init(o) {
        
       },
       complete:function(result){
        //定位成功
        var address = result.formattedAddress
        var point = result.position;
        var obj = {
          address:address,
          name:"",
          location:point
        }
        me.list = [obj];
        me.makerConf.position = [point.lng,point.lat];
       },
       error:function(){
         
       }
      }
     }
     ]
    };
   },
   created(){
    var me = this; 
   },
   mounted(){   
   },
   methods: {
    select:function(item,index){
      var me = this;
      me.currIndex = index;
      var point = item.location;
      me.makerConf.position = [point.lng,point.lat];
      me.center = [point.lng,point.lat];
       
    },
    //this.$refs.map.$$getCenter()
    getList:function(result){
      //獲取列表
      var me = this;
      me.$Geocoder({
        lnglatXY:result,
        success:function(res){
          if(res.regeocode && res.regeocode.pois){
            me.list = res.regeocode.pois;
          }else{
            me.list = [];
          }
        },
        error:function(res){
          me.list = [];
        }
      });
     
    },
    onSearchResult(pois) {
      //搜索
     let latSum = 0;
     let lngSum = 0;
     var me = this;
     
     var mymap = me.$refs.map.$$getInstance();
       
     if (pois && pois.length > 0) {
       
      //如果長度為1則無需轉(zhuǎn)化
        var poi = pois[0];
        var lng = poi["lng"];
        var lat = poi["lat"];
        me.center = [lng, lat];
        me.makerConf.position = [lng, lat];
        //me.makerConf.content = poi.name;
        me.list = pois;
      }else{
        me.list = [];
      }
    },   
    $Geocoder(options){
      //將坐標點轉(zhuǎn)化為,詳細地址
      options = options || {};
      if(AMap){
        AMap.plugin(['AMap.Geocoder'], () => {
        const geocoder = new AMap.Geocoder({
          radius: options.radius || 1000,
          extensions: options.extensions || "all"
        })
        var lnglatXY = options.lnglatXY || [114.397169, 30.50576]; //已知點坐標
        geocoder.getAddress(lnglatXY, function(status, result) {
          if (status === 'complete' && result.info === 'OK') {
            options.success && options.success(result);
          }else{
            options.error && options.error(status,result);
          }
        });
        });
         
      }
       
     }
    },
    "watch":{
     list:function(){
      this.currIndex = 0;
     }
    }
    
  };
   
  /*
   me.$Geocoder({
          lnglatXY:[center.lng, center.lat],
          success:function(res){
            console.log(res);
          }
    });
   *
   * */
</script>

bus.js

let instance = null;
class EventBus {
  constructor() {
    if (!instance) {
      this.events = {};
      instance = this;
    }
    return instance;
  }
  $emit(event, message) {
    if (!this.events[event])
      return;
    const callbacks = this.events[event];
    for (let i = 0, l = callbacks.length; i < l; i++) {
      const callback = callbacks[i];
 
      callback.call(this, message);
    }
  }
  $on(event, callback) {
    if (!this.events[event])
      this.events[event] = [];
 
    this.events[event].push(callback);
  }
}
export default new EventBus();

效果圖

https://elemefe.github.io/vue-amap/#/zh-cn/introduction/install

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue中Vue.use()的原理及基本使用

    Vue中Vue.use()的原理及基本使用

    相信很多人在用Vue使用別人的組件時,會用到 Vue.use() ,例如:Vue.use(VueRouter)、Vue.use(MintUI),這篇文章主要給大家介紹了關(guān)于Vue中Vue.use()的原理及基本使用的相關(guān)資料,需要的朋友可以參考下
    2021-10-10
  • Vue實戰(zhàn)之項目開發(fā)時常見的幾個錯誤匯總

    Vue實戰(zhàn)之項目開發(fā)時常見的幾個錯誤匯總

    vue作為前端主流的3大框架之一,目前在國內(nèi)有著非常廣泛的應用,下面這篇文章主要給大家介紹了關(guān)于Vue實戰(zhàn)之項目開發(fā)時常見的幾個錯誤匯總的相關(guān)資料,對大家學習或者使用vue具有一定的參考學習價值,需要的朋友可以參考下
    2023-03-03
  • vue?點擊刪除常用方式小結(jié)

    vue?點擊刪除常用方式小結(jié)

    這篇文章主要介紹了vue?點擊刪除常用方式小結(jié),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • vue生成二維碼QR?Code的簡單實現(xiàn)方法示例

    vue生成二維碼QR?Code的簡單實現(xiàn)方法示例

    這篇文章主要為大家介紹了vue生成二維碼QR?Code的實現(xiàn)示例詳情,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-04-04
  • vue父子組件相互通信方法示例梳理總結(jié)

    vue父子組件相互通信方法示例梳理總結(jié)

    這篇文章主要為大家介紹了vue父子組件相互通信方式示例梳理總結(jié),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-05-05
  • Vite多環(huán)境配置及變量識別規(guī)則

    Vite多環(huán)境配置及變量識別規(guī)則

    這篇文章主要為大家介紹了Vite多環(huán)境配置時間及vite識別環(huán)境變量的規(guī)則,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-09-09
  • vue-cli+webpack項目打包到服務器后,ttf字體找不到的解決操作

    vue-cli+webpack項目打包到服務器后,ttf字體找不到的解決操作

    這篇文章主要介紹了vue-cli+webpack項目打包到服務器后,ttf字體找不到的解決操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • vue中$nextTick的用法講解

    vue中$nextTick的用法講解

    今天小編就為大家分享一篇關(guān)于vue中$nextTick的用法講解,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-01-01
  • 詳解Vue開發(fā)網(wǎng)站seo優(yōu)化方法

    詳解Vue開發(fā)網(wǎng)站seo優(yōu)化方法

    這篇文章主要介紹了Vue開發(fā)網(wǎng)站seo優(yōu)化方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-05-05
  • Vue中keep-alive組件的原理與緩存詳解

    Vue中keep-alive組件的原理與緩存詳解

    Vue 的 keep-alive 是一個內(nèi)置組件,用于緩存不活動的組件實例,避免重復渲染,從而優(yōu)化應用性能,下面就跟隨小編一起來看看其核心實現(xiàn)原理和緩存內(nèi)容吧
    2025-03-03

最新評論

石狮市| 科技| 霞浦县| 博罗县| 东安县| 泰顺县| 常德市| 深州市| 特克斯县| 德钦县| 隆安县| 高邑县| 翁源县| 泊头市| 郸城县| 津市市| 忻城县| 上犹县| 兴义市| 开远市| 姜堰市| 湘潭县| 利津县| 弋阳县| 蓬安县| 靖西县| 宿迁市| 满洲里市| 大荔县| 兴安县| 林州市| 德安县| 邯郸县| 京山县| 宿松县| 黎城县| 察哈| 蕉岭县| 清河县| 贵溪市| 潼关县|