【发布时间】:2022-08-19 04:02:47
【问题描述】:
我想在绘制的多边形中获取所有特征。 为了避免遍历我层的所有特征,我用 bbox 约束查询的特征。 我用 turf 库计算 bbox。
但是,返回的特征与所需的 bbox 不对应。
附上你可以在图片中看到:
- 蓝色:计算的 bbox
- 红色:从 queryRenderedFeatures() 查询返回的特征。
import bbox from \'@turf/bbox\';
const bboxGeom = bbox(drawGeometry);
// convert to pixels for queryRenderedFeatures()
const southWest = map.project([bboxGeom[0], bboxGeom[1]]);
const northEast = map.project([bboxGeom[2], bboxGeom[3]]);
const box = [[southWest.x, southWest.y], [northEast.x, northEast.y]];
const features = map.queryRenderedFeatures(
box, { layers: [\'myLayer\'] },
);
标签: javascript mapbox mapbox-gl-js