Avoid false positives for line and polygon hit detection

This commit is contained in:
ahocevar
2019-07-23 19:24:27 +02:00
parent 2dda7127ed
commit 387f797f23
+13 -9
View File
@@ -344,11 +344,13 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer {
let i, ii; let i, ii;
for (i = 0, ii = renderedTiles.length; i < ii; ++i) { for (i = 0, ii = renderedTiles.length; i < ii; ++i) {
const tile = renderedTiles[i]; const tile = renderedTiles[i];
const tileExtent = tileGrid.getTileCoordExtent(tile.wrappedTileCoord);
const tileContainsCoordinate = containsCoordinate(tileExtent, coordinate);
if (!declutter) { if (!declutter) {
// When not decluttering, we only need to consider the tile that contains the given // When not decluttering, we only need to consider the tile that contains the given
// coordinate, because each feature will be rendered for each tile that contains it. // coordinate, because each feature will be rendered for each tile that contains it.
const tileExtent = tileGrid.getTileCoordExtent(tile.wrappedTileCoord); if (!tileContainsCoordinate) {
if (!containsCoordinate(tileExtent, coordinate)) {
continue; continue;
} }
} }
@@ -361,13 +363,15 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer {
* @return {?} Callback result. * @return {?} Callback result.
*/ */
function(feature) { function(feature) {
let key = feature.getId(); if (tileContainsCoordinate || (declutteredFeatures && declutteredFeatures.indexOf(feature) !== -1)) {
if (key === undefined) { let key = feature.getId();
key = getUid(feature); if (key === undefined) {
} key = getUid(feature);
if (!(key in features)) { }
features[key] = true; if (!(key in features)) {
return callback(feature, layer); features[key] = true;
return callback(feature, layer);
}
} }
}, layer.getDeclutter() ? declutteredFeatures : null); }, layer.getDeclutter() ? declutteredFeatures : null);
} }