openlayers地图覆盖物overlay常用用法-popup弹窗

 

<!-- OpenLayers -->
<template>
  <div class="OpenLayers_container">
    <div id="LBTmap" class="lbtolmap">
    </div>
    <div id="popup" class="info_popup">
        {{popupInfo.jqxx_name}} <br>
        {{popupInfo.jqxx_xx}}
    </div>

  </div>
</template>

<script>
//这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
//例如:import 《组件名称》 from '《组件路径》';
import axios from 'axios'
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  props:{

  },
  data() {
    //这里存放数据
    return {
      popupInfo:{},//弹窗信息
      popupOverlay:null,//弹窗
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    // 初始化单击选择
    initSelect(){
      var LBTselect, LBTinitSelect = [
        {
            layer: LBTvectorlayerblankpolygon,
            style: LBTstyleAploygon_S
        }
      ];
      LBTselect = LBTglobe.clickSelect(LBTinitSelect);
      var _this=this
      LBTselect.on('select', function(e) {
          LBTglobe.selectStyle(e.selected[0]);
          if (e.selected.length > 0) {
              let centerCoord= ol.extent.getCenter(e.selected[0].getGeometry().getExtent())//获取选择面的中心点
              _this.addMarker(e.selected[0].j,centerCoord)
          } else {
              console.log("没有选中要素...");
              _this.popupOverlay.setPosition(undefined)
          }
      });
    },
    // 添加信息弹窗
    addMarker(info,coord) {
        this.popupInfo=info
        this.popupOverlay = new ol.Overlay({
            position: coord,//投影坐标
            element: document.getElementById("popup"),
            positioning: "center-center",
            stopEvent: false,
            insertFirst:false,
       autoPan: true, // 定义弹出窗口在边缘点击时候可能不完整 设置自动平移效果
       autoPanAnimation: {
        duration: 250 //自动平移效果的动画时间 9毫秒)
       }
        });
        LBTmap.addOverlay(this.popupOverlay);
    },
  },
  //生命周期 - 创建完成(可以访问当前this实例)
  created() {},
  //生命周期 - 挂载完成(可以访问DOM元素)
  mounted() {
    /*
    定义地球
    */
    window.LBTglobe = new LBTGSglobe('LBTmap', LBTview, LBTstart);
    window.LBTmap = LBTglobe.map;
    /*
    增加影像图层
    */
    var LBTtilelayercn = LBTglobe.addTileLayer(LBTlayerCnTile, true);
    var LBTtilelayerhn = LBTglobe.addTileLayer(LBTlayerHnTile, true);
    /*
    增加矢量图层
    */
    window.LBTvectorlayerblankpolygon = LBTglobe.addVectorLayer(LBTlayerBlankVectorpolygon, true);
    axios.get(configBase.mapUrl.geojsonTcqy).then(res=>{
        // /*
        // 增加面feature到图层LBTvectorlayerblank
        // */
        var LBT_featuresgon = [];
        var LBT_featureName=[]
        res.data.features.forEach(item => {
          item.geometry.coordinates[0].forEach((item1,index)=>{
            item1.forEach((item2,index2)=>{
              item.geometry.coordinates[0][index][index2]=LBTglobe.toLonLat([item2[0],item2[1]])
              
            })
          })
          // 地块面feature
          let LBTfeatureInfogon = {
              geometry: LBTglobe.newGeometry('Polygon', item.geometry.coordinates[0]),
              jqxx_name:item.properties.NAME,
              jqxx_Jname:item.properties.ANAME,
              jqxx_pano:item.properties.PANOADD,
              jqxx_mj:item.properties.TAREA,
              jqxx_xx:item.properties.信息,
              jqxx_x:item.properties.Shape_Leng,
              jqxx_y:item.properties.Shape_Area,
          };
          LBT_featuresgon.push(LBTglobe.newFeature(LBTfeatureInfogon));
        });
        
        LBTglobe.addFeatures(LBTvectorlayerblankpolygon, LBT_featuresgon);
    })

    this.initSelect()

  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
};
</script>
<style lang='scss' scoped>
.OpenLayers_container{
  width: 100%;
  height: 100%;
}
.lbtolmap{
  width: 100%;
  height: 100%;
}
.check_box{
  width: 100px;
  height: 50px;
  background: blue;
  position: absolute;
  bottom: 10px;
  right: 10px;
  z-index: 5;
  cursor: pointer;
}
.info_popup{
  width: 200px;
  padding:10px 20px;
  position: absolute;
  background: #fff;
  border-radius: 5px;
  font-size: 12px;
}
</style>

 

openlayers地图覆盖物overlay常用用法-popup弹窗

 

 

上一篇:百度地图实现复杂覆盖物(Overlay)比如:Echarts


下一篇:SAS lattice_2