高德地图 ----- infoWindow播放视频

1. public/index.html

public 下放 liveplayer 文件夹,component 是 vue 组件方式,element 是 html 方式,两种方式都需要存在,否则可能不能加载视频,
下面的关键点在 createInfoWindow 这个函数内,这里播放视频用的是 liveplayer,easyplayer 应该也是这样的,没有尝试

	<script src="./liveplayer/component/liveplayer-lib.min.js"></script>
  	<script src="./liveplayer/element/liveplayer-element.min.js"></script>

在这里插入图片描述

1. g-marker-player

  • html
<template>
  <div>
       <g-map @gmap="getGmap" />
  </div>
</template>
  • js
<script>
import GMap from './g-map.vue';
import LivePlayer from "@liveqing/liveplayer";
export default {
    components: { GMap, LivePlayer },
    data(){
        return{
            map:null,
        }
    },
    mounted(){
        this.getGmap()
    },
    methods:{
        getGmap(val){
            this.map = val
        },
        showAllMarker(posArr){
            const that = this
            that.map.clearMap()

            posArr.forEach(ele => {
                if(ele.installLongitude && ele.installLatitude){
                    const LngLat = new AMap.LngLat(ele.installLongitude, ele.installLatitude)
                    const marker = new AMap.Marker({
                        position: LngLat
                    });

                    const infoWindow = new AMap.InfoWindow({
                        isCustom: true,
                        content: that.createInfoWindow(ele.monitorName, ele.videoStreamAddress),
                        offset: new AMap.Pixel(0, -35)
                    });

                    marker.on('click', function (e) {
                        infoWindow.open(that.map, LngLat)
                    })

                    that.map.add(marker);
                    that.map.setFitView()
                }
            });
        },
        showMarkerWithPlayer(position, title, url){
            const that = this
            const LngLat = new AMap.LngLat(position.lng, position.lat)

            const infoWindow = new AMap.InfoWindow({
                isCustom: true,
                content: that.createInfoWindow(title, url),
                offset: new AMap.Pixel(0, -35)
            });

            infoWindow.open(that.map, LngLat)
            that.map.setFitView()
        },
         createInfoWindow(title, url){
            const IW = document.createElement('div')
            const header = document.createElement('div')
            const body = document.createElement('div')

            header.innerHTML = title
            // http://220.161.87.62:8800/hls/1/index.m3u8
            body.innerHTML = `
                <live-player
                    video-url="http://220.161.87.62:8800/hls/1/index.m3u8"
                    live="true"
                    stretch="true"
                ></live-player>
                `
            IW.style.width = '500px'

            header.style.lineHeight = '30px'
            header.style.background = '#66b1ff'
            header.style.color = '#fff'
            header.style.paddingLeft = '10px'

            IW.appendChild(header)
            IW.appendChild(body)

            return IW
        }
    }
}
</script>

2. index.vue

使用 g-marker-player 组件

  • html
  <g-marker-player ref="GMarkerPlayerRef" style="height:100%;"/>
  • js
<script>
import { videoList } from '@/api/video'
import GMarkerPlayer from '@/components/Gmap/g-marker-player'
export default {
  components:{
    GMarkerPlayer
  },
  data() {
    return {
      input3:'',
      list:[]
    };
  },
  created(){
    this.getList()
  },
  methods:{
    async getList(){
      const { data } = await videoList()
      this.list = data
      this.$refs.GMarkerPlayerRef.showAllMarker(data)
    },
    handleNodeClick(item){
      // console.log(item);
      const LngLat = {
        lng: item.installLongitude,
        lat: item.installLatitude
      }
      this.$refs.GMarkerPlayerRef.showMarkerWithPlayer(LngLat, item.monitorName, item.videoStreamAddress)
    }
  }
}
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值