Reduce work for hitdetection

Skip cloning of style if geometry is not in extent.
This commit is contained in:
Maximilian Krög
2021-02-10 21:26:53 +01:00
parent 99564671c1
commit dde6d6559c
+8 -7
View File
@@ -69,6 +69,10 @@ export function createHitDetectionImageData(
const color = '#' + ('000000' + index.toString(16)).slice(-6); const color = '#' + ('000000' + index.toString(16)).slice(-6);
for (let j = 0, jj = styles.length; j < jj; ++j) { for (let j = 0, jj = styles.length; j < jj; ++j) {
const originalStyle = styles[j]; const originalStyle = styles[j];
const geometry = originalStyle.getGeometryFunction()(feature);
if (!geometry || !intersects(extent, geometry.getExtent())) {
continue;
}
const style = originalStyle.clone(); const style = originalStyle.clone();
const fill = style.getFill(); const fill = style.getFill();
if (fill) { if (fill) {
@@ -119,13 +123,10 @@ export function createHitDetectionImageData(
byGeometryType[GeometryType.LINE_STRING] = []; byGeometryType[GeometryType.LINE_STRING] = [];
byGeometryType[GeometryType.POINT] = []; byGeometryType[GeometryType.POINT] = [];
} }
const geometry = style.getGeometryFunction()(feature); byGeometryType[geometry.getType().replace('Multi', '')].push(
if (geometry && intersects(extent, geometry.getExtent())) { geometry,
byGeometryType[geometry.getType().replace('Multi', '')].push( style
geometry, );
style
);
}
} }
} }