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
+4 -3
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,15 +123,12 @@ export function createHitDetectionImageData(
byGeometryType[GeometryType.LINE_STRING] = []; byGeometryType[GeometryType.LINE_STRING] = [];
byGeometryType[GeometryType.POINT] = []; byGeometryType[GeometryType.POINT] = [];
} }
const geometry = style.getGeometryFunction()(feature);
if (geometry && intersects(extent, geometry.getExtent())) {
byGeometryType[geometry.getType().replace('Multi', '')].push( byGeometryType[geometry.getType().replace('Multi', '')].push(
geometry, geometry,
style style
); );
} }
} }
}
const zIndexKeys = Object.keys(featuresByZIndex) const zIndexKeys = Object.keys(featuresByZIndex)
.map(Number) .map(Number)