From 3944a5a0387e4a686aac2033c13153d8cc340c33 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Wed, 4 Mar 2020 15:59:52 +0100 Subject: [PATCH] Make DEVICE_PIXEL_RATIO work in non-window context --- src/ol/has.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ol/has.js b/src/ol/has.js index bfc8aabef3..9bf3e354bf 100644 --- a/src/ol/has.js +++ b/src/ol/has.js @@ -37,7 +37,13 @@ export const MAC = ua.indexOf('macintosh') !== -1; * @type {number} * @api */ -export const DEVICE_PIXEL_RATIO = window.devicePixelRatio || 1; +export const DEVICE_PIXEL_RATIO = (function() { + try { + return self.devicePixelRatio; + } catch (e) { + return window.devicePixelRatio || 1; + } +})(); /** * Image.prototype.decode() is supported.