mirror of
https://github.com/visgl/luma.gl.git
synced 2025-12-08 17:36:19 +00:00
Handle cases when canvas is not defined (#1236)
This commit is contained in:
parent
f41d4a5d29
commit
f7a200db76
@ -2,7 +2,11 @@
|
||||
|
||||
// multiplier need to convert CSS size to Device size
|
||||
export function cssToDeviceRatio(gl) {
|
||||
return gl.drawingBufferWidth / (gl.canvas.clientWidth || gl.canvas.width);
|
||||
if (gl.canvas) {
|
||||
return gl.drawingBufferWidth / (gl.canvas.clientWidth || gl.canvas.width || 1);
|
||||
}
|
||||
// use default device pixel ratio
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Maps CSS pixel position to device pixel position
|
||||
|
||||
@ -338,5 +338,12 @@ test('webgl#cssToDeviceRatio', t => {
|
||||
MAP_TEST_CASES.forEach(tc => {
|
||||
t.equal(cssToDeviceRatio(tc.gl), tc.ratio, 'cssToDeviceRatio should return correct value');
|
||||
});
|
||||
|
||||
const glWithNoCanvas = {};
|
||||
t.equal(
|
||||
cssToDeviceRatio(glWithNoCanvas),
|
||||
1,
|
||||
'cssToDeviceRatio should return 1 when there is no canvas'
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user