【问题标题】:Mapbox queryRenderedFeatures does not work as expected with bboxMapbox queryRenderedFeatures 不能按预期与 bbox 一起工作
【发布时间】: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


    【解决方案1】:

    我的猜测是您的 box 被解释为一条线,从左下角到右上角。尝试投影并提供bboxGeom 的所有坐标。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-07
      • 1970-01-01
      • 1970-01-01
      • 2018-11-15
      相关资源
      最近更新 更多