mapbox弹框使用vue组件、mapbox弹框添加自定义事件

一、popup内容使用vue组件,添加轮播图

1、新建Popup.vue文件,添加弹框内容

<template>
  <div>
    <div class="pop_tit" @click="openD(obj)">
      {{ obj.name }}<i class="iconfont icon-jiancedianweidanchuang-you"></i>
    </div>
    <!-- 轮播图 -->
    <el-carousel height="240px" :interval="4000" trigger="click">
      <el-carousel-item v-for="item in obj.Vimages" :key="item">
        <img :src="item" class="vima" />
      </el-carousel-item>
    </el-carousel>
  </div>
</template>
<script>
import Bus from "../../utils/bus";
export default {
  name: "Popup",
  props: ["obj"],
  methods: {
    openD(geom) {
      Bus.$emit("detailVUE", geom);
    },
  },
};
</script>

2、地图页面map.vue

第一引入上面弹框组件,同时引入vue实例

import Bus from "../../utils/bus";
import Popup from "./Popup"; //引入弹框组件
import Vue from "vue";

第二挂载弹框内容

propsData里面是要传递到弹框的参数

methos:{
 createVideoPopUp(currentFeature) {
      var that = this;
      that.videoObj = currentFeature;//传递到弹框页面的数据
      var Vimages = [
        "http://****:8080/static/images/map/waterNew/img_shili1.png",
        "http://****:8080/static/images/map/waterNew/img_shili2.png",
        "http://****:8080/static/images/map/waterNew/img_shili3.png",
      ];//轮播图的图片
      that.videoObj.Vimages = Vimages;
      const p = Vue.extend(Popup);
      let vm = new p({
        propsData: {
          obj: that.videoObj,
          isShowName: true,
        },//传参
      });
      vm.$mount();//挂载
      this.popupTemp = vm.$el;
    }
 }

第三mapbox创建弹框

注意这里需要使用setDOMContent来设置弹框内容

//点击地图上面的标记点位,弹出弹框
 this.map.on("click", "QTstation", function (e) {
	 var that = this
	 var coordinates = e.features[0].geometry.coordinates.slice();
	 this.map.on("click", "QTstation", function (e) {
		that.createPopUp(e.features[0].properties);//第二步中的创建内容的方法
		new mapboxgl.Popup({ closeButton: false })
		    .setLngLat(coordinates)
		    .setDOMContent(that.popupTemp)
		    .addTo(that.map);
	})
})

3、mapbox弹出窗口中的Click事件

通过Bus 进行通信,上述代码中有体现(openD方法)

最终实现效果图:
在这里插入图片描述

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值