Fix layer canvas reuse

If the scale values have more than 6 decimals they are rounded and can no longer be
compared to the created transform string.
This commit is contained in:
Maximilian Krög
2021-05-17 14:19:37 +02:00
parent 0486caf659
commit bf0671fc08
5 changed files with 22 additions and 31 deletions

View File

@@ -1,6 +1,7 @@
/**
* @module ol/transform
*/
import {WORKER_OFFSCREEN_CANVAS} from './has.js';
import {assert} from './asserts.js';
/**
@@ -265,11 +266,24 @@ export function determinant(mat) {
}
/**
* A string version of the transform. This can be used
* @type {HTMLElement}
* @private
*/
let transformStringDiv;
/**
* A rounded string version of the transform. This can be used
* for CSS transforms.
* @param {!Transform} mat Matrix.
* @return {string} The transform as a string.
*/
export function toString(mat) {
return 'matrix(' + mat.join(', ') + ')';
const transformString = 'matrix(' + mat.join(', ') + ')';
if (WORKER_OFFSCREEN_CANVAS) {
return transformString;
}
const node =
transformStringDiv || (transformStringDiv = document.createElement('div'));
node.style.transform = transformString;
return node.style.transform;
}