-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance decrease after forEachLayerAtPixel function calling #10597
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I found solution for this issue getting advanced research. Find the following file: ol/renderer/canvas/Layer.js In the function CanvasLayerRenderer.prototype.getDataAtPixel you get image data by whole context. This solution decrease performance due to scanning of all pixels. To achieve a better performance, first you should crop canvas to 1px image (drawing new 1px image) and finally get that pixel using getDataImage. I have checked this solution and received much better performance result. This is my working example: CanvasLayerRenderer.prototype.getDataAtPixel = function (pixel, frameState, hitTolerance) {
var renderPixel = applyTransform(this.inversePixelTransform, pixel.slice());
var context = this.context;
var data;
try {
var x = Math.round(renderPixel[0]);
var y = Math.round(renderPixel[1]);
var newCanvas = document.createElement("canvas");
var newContext = newCanvas.getContext('2d');
newCanvas.width = 1;
newCanvas.height = 1;
newContext.clearRect(0, 0, 1, 1);
newContext.drawImage(context.canvas, x, y, 1, 1, 0, 0, 1, 1);
data = newContext.getImageData(0, 0, 1, 1).data;
//data = context.getImageData(Math.round(renderPixel[0]), Math.round(renderPixel[1]), 1, 1).data;
}
catch (err) {
if (err.name === 'SecurityError') {
// tainted canvas, we assume there is data at the given pixel (although there might not be)
return new Uint8Array();
}
return data;
}
if (data[3] === 0) {
return null;
}
return data;
}; Check this solution and please, improve this function. Regards. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Why didn't you improve this feature. It could help many people? |
Description
Perormance decreasing when clicking on ImageLayer and getting color by forEachLayerAtPixel function.
The problem mainly appears in full-screen mode in.
Tested on Chrome.
To Reproduce
This example only contains one ImageLayer, but my original application has many ImageLayers and the problem is more serious.
Thank you, in advance, for your support and reply.
Best regards.
The text was updated successfully, but these errors were encountered: