有没有办法让所有在一层的一个特定像素的特征,包括隐藏由于decluttering? 目前,打电话时Map.getFeaturesAtPixel()
或Map.forEachFeatureAtPixel()
省略了这些功能。
Answer 1:
getFeaturesAtPixel
设计报告具体是怎么呈现在地图上。 如果你想获得的所有功能,在特定的位置,你可以使用ol/source/Vector
的getFeaturesInExtent
一个小的缓冲器(例如2个像素)围绕你感兴趣的坐标方法:
import {boundingExtent, buffer} from 'ol/extent';
map.on('click', function(e) {
const extent = boundingExtent([e.coordinate]);
buffer(extent, 2 / view.getResolution());
matches = source.getFeaturesInExtent(extent);
});
当您正在使用矢量瓷砖时,您可以通过先得到瓷砖达到同样的
const tileGrid = vectorTileSource.getTileGrid();
const tileCoord = tileGrid.getTileCoordForCoordAndResolution(coordinate, view.getResolution());
const tile = vectorTileSource.getTile(tileCoord);
然后得到的只是在你的缓冲程度的特征:
import {intersects} from 'ol/extent';
const features = tile.getFeatures();
const matches = [];
for (let i = 0, ii = features.length; i < ii; ++i) {
const feature = features[i];
if (intersects(extent, feature.getGeometry().getExtent()) {
matches.push(feature);
}
}
Answer 2:
对于后人。 我认为,在大多数情况下你不需要的结果中包括隐藏的功能,由于decluttering,因为这可能会导致一个非空的结果光标所在的空白区域。
什么终于做是没有decluttering打开创建附加层。 首先,我补充说所有的功能没有标签,并把它们藏根本就没有设置填充样式(图层不透明度设置为零,也将工作)。 这是给我很大的成绩,当原始decluttered功能是重叠的人,但在空区域仍然给误报。
所以最后我决定也显示背后的decluttered一个新层,用不同的造型和无标签。 通过这种方式,在视觉上可以看到的所有功能,并与标签decluttered显示在顶部,这也工作完全正常从UX的观点。
文章来源: getFeaturesAtPixel() to include decluttered (hidden) features