是getFeaturesAtPixel(pixel,opt_options)的错误吗?

问题描述 投票:0回答:1

当我使用此功能获取功能时,我发现:如果“功能”的“样式”(如图像和文字)在功能坐标的100像素以内,则可以使用“样式”中的像素来获得功能;但是,如果“样式”太远(超过100个像素),则无法通过使用“样式”的像素来获得“功能”。

例如将'ol / style / Text'添加到特征样式中。

new Text({
  font: '15px Microsoft YaHei',
  text: '',
  fill: new Fill({
    color: '#222'
  }),
  backgroundStroke: new Stroke({
    color: 'rgba(0,0,0,0.5)',
    width: 1
  }),
  backgroundFill: new Fill({
    color: 'rgba(0,250,154,0.3)'
  }),
  textAlign: 'middle',
  textBaseline: 'middle',
  offsetX: 200,
  offsetY: 200
})
javascript openlayers openlayers-6
1个回答
0
投票

我在github中找到了解决方案:默认情况下,OpenLayers仅将要素周围100像素的区域视为命中检测。当您使用200像素的偏移量时。您不在该地区。要修复此问题,请使用适当大小的renderBuffer配置图层。

© www.soinside.com 2019 - 2024. All rights reserved.