Vue中使用百度地图demo Vue Baidu Map(vue-baidu-map)设置窗口信息

简介: Vue中使用百度地图demo Vue Baidu Map(vue-baidu-map)设置窗口信息

1.全局引入

安装  npm install --save vue-baidu-map

1.2全局配置 在main.js中配置

 

效果图:

二.代码

<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <!--百度地图-->
    <baidu-map
      class="bm-view"
      :center="center"
      :zoom="zoom"
      @ready="handler"
      :auto-resize="true"
      :scroll-wheel-zoom="true"
    >
      <bm-marker
        v-for="(item, index) in points"
        :key="index"
        :position="{ lng: item.lng, lat: item.lat }"
        @click="clickHandler(item.content,item.lng,item.lat)"
        :icon="item.icon"
      >
      </bm-marker>
      <bm-info-window
        :show="show"
        :position="windowposition"
        @close="infoWindowClose"
        @open="infoWindowOpen"
        >{{content}}</bm-info-window
      >
      <bm-polyline
        :path="points"
        stroke-style="dashed"
        stroke-color="blue"
        :stroke-opacity="0.3"
        :stroke-weight="1"
      ></bm-polyline>
      
    </baidu-map>
  </div>
</template>
<script>
export default {
  name: 'HelloWorld',
  data () {
    return {
      msg: 'Welcome to map',
      center: { lng: 112, lat: 37 },
      zoom: 14,
      points: [],
      windowposition: {},
      content: {},
      show: false,
      icon: { url: "http://api.map.baidu.com/library/LuShu/1.2/examples/car.png"},
    }
  },
    mounted() {
    this.addPoints();
  },
  methods: {
    //地图实例
    handler({ BMap, map }) {
      console.log(BMap, map);
      this.center.lng = 112.404;
      this.center.lat = 37.755;
      this.zoom = 10;
    },
    clickHandler(content,lng,lat) {
      // alert(`单击点的坐标为:${e.point.lng}, ${e.point.lat}`);
      this.windowposition = { lng: lng, lat: lat };
      this.content=content;
      this.show = true;
    },
    addPoints() {
      const points = [];
      for (var i = 0; i < 10; i++) {
        let icon = this.icon;
        const position = {
          lng: Math.random() + 112,
          lat: Math.random() + 37,
          content: "我爱北京天安门" + i,
          ico: icon,
        };
        points.push(position);
      }
      this.points = points;
      console.log("this.points", this.points);
    },
    infoWindowOpen() {
      this.show = true;
    },
    infoWindowClose() {
      this.show = false;
    },
  }
}
</script>
<style scoped>
.bm-view {
  width: 100%;
  height: 800px;
}
</style>

3.参考百度Vue Baidu Map

4.代码下载 代码下载

目录
打赏
0
0
0
0
218
分享
相关文章
|
5月前
|
vue尚品汇商城项目-day07【52.打包文件,处理map文件】
vue尚品汇商城项目-day07【52.打包文件,处理map文件】
33 3
Vue2使用百度地图展示或搜索地点(vue-baidu-map)
本文介绍了如何在 Vue 项目中使用 `vue-baidu-map` 插件,包括安装、全局注册及具体应用。首先通过 `yarn add vue-baidu-map` 安装插件,并在 `main.js` 中全局注册。然后展示了如何在地图上显示特定位置的标记,以及如何搜索地点并获取其经纬度和详细地址信息。代码示例提供了详细的实现方法和样式调整。如需使用,请确保已获取百度地图 API 的密钥。
996 1
Vue 系类之 this.tabledatas.map 无效
这篇文章讲述了在Vue项目中使用`this.tabledatas.map`处理接口返回的数组数据时遇到的问题,原因是由于取错了后端返回的数据集合字段值,导致`.map`方法无效,通过检查和修正数据取值解决了问题。
Vue 系类之 this.tabledatas.map 无效
Vue中传递自定义参数到后端、后端获取数据(使用Map接收参数)
这篇文章讲述了如何在Vue中通过Axios二次封装传递自定义参数到后端,并展示了后端如何使用Map接收这些参数,以及如何避免参数转换错误和统一接口设计的方法。
vue-baidu-map 绘制行政区划的轮廓,添加行政区划名称(含给覆盖物添加点击事件)——vue 百度地图开发
vue-baidu-map 绘制行政区划的轮廓,添加行政区划名称(含给覆盖物添加点击事件)——vue 百度地图开发
345 1
vue-baidu-map 百度地图检索、获取坐标
vue-baidu-map 百度地图检索、获取坐标
143 1
vue 百度地图开发【教程】1. 绘制百度地图(不使用 vue-baidu-map,解决 BMap is undefined)
vue 百度地图开发【教程】1. 绘制百度地图(不使用 vue-baidu-map,解决 BMap is undefined)
491 0
ES6的Set和Map你都知道吗?一文了解集合和字典在前端中的应用
该文章详细介绍了ES6中Set和Map数据结构的特性和使用方法,并探讨了它们在前端开发中的具体应用,包括如何利用这些数据结构来解决常见的编程问题。
ES6的Set和Map你都知道吗?一文了解集合和字典在前端中的应用
java集合框架复习----(4)Map、List、set
这篇文章是Java集合框架的复习总结,重点介绍了Map集合的特点和HashMap的使用,以及Collections工具类的使用示例,同时回顾了List、Set和Map集合的概念和特点,以及Collection工具类的作用。
java集合框架复习----(4)Map、List、set
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等