如何在OpenLayers中使用Mapbox获取要素?

huangapple go评论58阅读模式
英文:

How to get features in openlayers with mapbox?

问题

我尝试这样做,但它不起作用,以下是我的主要代码。

在此输入图像描述

在此输入图像描述

英文:

I try to do it but it doesn't work, below is my main code.

enter image description here

enter image description here

答案1

得分: 0

你需要查询Mapbox地图上的特征

map.on('click', (e) => {
  const point = new mapboxgl.Point(e.pixel[0], e.pixel[1]);
  const features = mbMap.queryRenderedFeatures(point);
  console.log(features);
});

https://codesandbox.io/s/mapbox-layer-forked-x8mocy?file=/main.js

英文:

You need to query the features on the Mapbox map

map.on('click', (e) => {
  const point = new mapboxgl.Point(e.pixel[0], e.pixel[1]);
  const features = mbMap.queryRenderedFeatures(point);
  console.log(features);
});

https://codesandbox.io/s/mapbox-layer-forked-x8mocy?file=/main.js

huangapple
  • 本文由 发表于 2023年2月6日 17:54:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75359752.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定