Vue中使用Openlayers添加提示信息

部分关键代码

<!-- 主页面 -->
<template>
	<div id="coalmap"  class="map">
		<div v-for="(i, index) in popupList" :key="index">
	        <home-popup :id="i.id" :popup="i" @closepop="closepop"></home-popup>
	      </div>
      </div>
</template>
export default {
	data () {
		return {
			coalMap: null,
			sendataForm: null,
			popupList: []
		}
	},
	components: {
      homePopup
    }
	methods: {
	  ...
	  // 监听单击事件
      monitorsbclick () {
        let self = this
        this.coalMap.on('singleclick', function (e) {
          let pixel = self.coalMap.getEventPixel(e.originalEvent)
          let fet = self.coalMap.forEachFeatureAtPixel(pixel, function (fe) {
            return fe
          })
          if (fet) { // 点击到图标
            let value = JSON.parse(fet.get('value'))
            self.sendataForm.name = value.name
            self.sendataForm.location = value.location
            self.getIconData(value)
          }
        })
      },
		// 查询点位信息
      getIconData (val) {
        this.messList = []
        this.$http({
          url: this.$http.adornUrl('/api/home/getDevAttrs'),
          method: 'get',
          params: this.$http.adornParams({
            'code': val.code,
            'type': val.type
          })
        }).then(({data}) => {
          this.messList = data.data
          // 生成弹窗
          this.setPoper(val, data.data)
        })
      },
      // 生成弹窗
      setPoper (val, list) {
        let a = this.popupList.filter(i => {
          return i.id === val.id + ''
        })
        let vid = val.id + ''
        if (a.length === 0) {
          this.popupList.push({
            id: vid,
            name: JSON.parse(JSON.stringify(this.sendataForm.name)),
            messList: list
          })
        }
        this.$nextTick(() => {
          let container = document.getElementById(vid)
          let overlay = new ol.Overlay(({
            id: `odom${vid}`,
            element: container,
            autoPan: true,
            positioning: 'bottom-left',
            autoPanAnimation: {
              duration: 250
            }
          }))
          this.coalMap.addOverlay(overlay)
          overlay.setPosition([parseFloat(val.xAxis), parseFloat(val.yAxis)])
        })
      },
      closepop (ids) {
        let b = this.coalMap.getOverlays().getArray()
        for (var i = 0; i < b.length; i++) {
          if (b[i].id === `odom${ids}`) {
            b[i].setPosition(undefined)
          }
        }
      },
      ...
	}
}
<!-- 组件 -->
<template>
  <div class="ol-popup">
    <div class="fontTitle">
      <span>{{popup.name}}</span>
      <i class="el-icon-close closeIcon" @click="closepop(popup.id)"></i>
    </div>
    <div class="popup-content">
      <hr class="style-five" />
      <div v-for="(a, aindex) in popup.messList" :key="aindex">
        {{a.name}}
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    props: {
      popup: {
        type: Object
      }
    },
    methods: {
      closepop (id) {
        this.$emit('closepop', id)
      }
    }
  }
</script>

<style lang="scss">
  .ol-popup {
    min-width: 100px;
    min-height: 30px;
    max-height: 140px;
    overflow-y: auto;
    background: rgba(53,55,58,0.8);
    -webkit-box-shadow: -5px 0px 15px #494A4F inset, 10px 0px 15px #494A4F inset;
     box-shadow: -5px 0px 15px #494A4F inset, 10px;
    margin-left: 12px;
    margin-bottom: 20px;
  }
  .closeIcon {
    color: #ED2641;
    cursor: pointer;
    float: right;
    font-size: 20px;
    line-height: 30px;
    margin-top: 1px;
    margin-right: 1px;
  }
  .fontTitle {
    span {
      font-size: 14px;
      line-height: 30px;
      margin-right: 10px;
      margin-left: 10px;
      color: #fff;
    }
  }
  .popup-content {
    max-height: 100px;
    overflow-y: auto;
    margin-right: 0px;
    float: left;
    font-size: 12px;
    line-height: 20px;
    color: #fff;
  }
</style>

效果
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值