高德地图信息窗体InfoWindow 使用element UI组件进行图片放大

本文介绍了如何在高德地图的InfoWindow中利用Vue.extend和Element UI的el-image组件,实现在地图信息窗口中点击图片进行大图预览的功能。原先尝试使用v-viewer插件,但由于页面解析问题导致错误,最终改用UI组件成功解决问题。
摘要由CSDN通过智能技术生成

高德地图信息窗体InfoWindow 使用element UI组件

需求:高德地图信息窗体InfoWindow里面的图片可以进行大图预览
解决方案,使用Vue.extend和element UI的el-image

import { Image }  from 'element-ui' //先要引入组件

 creatTextName(map, siteMarker, item, middleMarkers, type) {
   //这个是在驾车规划的途径点上面
      const { lineNameStr, spotNameStr, pathListNameStr } = this.toParams;
      // 给 Text 带上自定义私货
      siteMarker.lisaSiteInfo = item;
      // 监听地图- Text 的 点击事件
      const imgList = []
      const img =  this.changeImgUrl(item.image) //这里是个http地址
      imgList.push(img)
      const clickHandler1 = function (e) {
        const Content = Vue.extend({
                template: `<div>
                            <p>通行图片</p>
                            <el-image :preview-src-list="imgList" :src="imgList[0]" style="width: 300px; heigth: 300px">
                            </el-image>
                          </div>`,
                name: 'pageInfo',
                components: {
                    'el-image':Image //注册组件
                },
                data(){
                    return {
                        imgList:imgList
                    }
                }
             });
 
        const component = new Content().$mount();
        const infoWindow = new AMap.InfoWindow({})
        infoWindow.setContent(component.$el);
        infoWindow.open(map, e.lnglat)
      };
      siteMarker.on("click", clickHandler);
      siteMarker.setMap(map);
      middleMarkers.push(siteMarker);
      //-------siteText-------
      // label默认蓝框白底左上角显示,样式className为:amap-marker-label
      let text = "";
      if (type) {
        // text = item.latitude;
        text = item[spotNameStr];
      } else {
        text = "";
      }
      const siteText = new AMap.Text({
        offset: new AMap.Pixel(0, -50), //设置文本标注偏移量
        text: text,
        position: new AMap.LngLat(item.longitude, item.latitude), // 这里特殊 本数据结构, startLatitude
        map: map,
      });
      siteText.lisaSiteInfo = item;
      siteText.on("click", clickHandler);
      siteText.setMap(map);
      middleMarkers.push(siteText);
      return middleMarkers;
    },

在这里插入图片描述
点击图片后就可以直接放大预览了

刚开始使用的大图预览用的是插件v-viewer,但是v-viewer在使用的时候页面解析成了function
在这里插入图片描述
就会报错,后面只能换成UI组件,有知道原因的大佬帮忙解答一下

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

知所云

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值