18910140161

vue使用openlayers5本地上传geojson渲染出来点击出现弹框?

顺晟科技

2022-09-16 07:34:16

153

map_click() {
  this.map.on("click", (e) => {
    var pixel = this.map.getEventPixel(e.originalEvent);
    console.log(pixel)
    var coordinate = e.coordinate;
    var feature = this.map.forEachFeatureAtPixel(pixel, (feature) => {return feature});
    console.log(feature)
    if(feature){
      console.log("获取到点击的要素" + "jingdu:" + coordinate[0]);  //其中lei是定义的属性
      // this.datas = feature.values_
      this.$refs.popup_content.innerHTML = '<code>' + feature.values_.id + '</code>';    //弹窗内容
      this.overlay.setPosition(coordinate);
    }else {
      this.overlay.setPosition(undefined);  // 如果没有点击坐标点,就隐藏弹窗
    }
  });
},

这个是点击矢量图层出现弹框的代码下面一个一个绿色的小圆圈就是一个个的矢量图层image.png首次进入这个页面的时候,从本地获取到数据渲染出来然后点击绿色的小圆点,获取不到上述代码里面的feature这个时候把上面的console.log() 这个给注释掉保存代码以后 不要刷新页面从新渲染一次绿色的小圆点这个时候点击就会出现image.png是那一步出错了呢?

我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航