8.openlayers中单击获取要素

前台

  • interaction中select方法
  • map中forEachFeatureAtPixel方法

geoserver

  • wms中getfeatureinfo
  • wfs中getfeature

interaction

      let selectSingleClick = new Select();
      selectSingleClick.on('select', function (e) {
        let features = e.target.getFeatures().getArray();
        console.log(features)
      })

      this.map.addInteraction(selectSingleClick);

map中forEachFeatureAtPixel

      this.map.on('click', (e) => {
        this.map.forEachFeatureAtPixel(e.pixel, function (feature, layer) {
          console.log(feature.getId())
          return true; // 不返回true会有层级穿透
        })
      })

wms中getfeatureinfo

      let TileWMSSource = new TileWMS({
        url: 'http://43.143.213.90:8083/geoserver/one/wms',
        params: {LAYERS: "one:base-old", TILED: true},
        serverType: "geoserver",
      })

      this.map.on('click', (e) => {
        let url = TileWMSSource.getFeatureInfoUrl(e.coordinate, this.map.getView().getResolution(), "EPSG:4326", {
          INFO_FORMAT: "application/json", //输出为json字符串
        });

        if (url) {
          fetch(url).then((res) => {
            return res.json()
          }).then(res => {
            console.log(res)
          })
        }
      })

https://www.likecs.com/show-307918330.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值