From b20916fba3b8d17ae2063cd88205a8b591306b5e Mon Sep 17 00:00:00 2001 From: ftoromanoff Date: Wed, 8 Feb 2023 16:28:54 +0100 Subject: [PATCH] refactor(Style): instantiate canvas when no document --- src/Core/Style.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Core/Style.js b/src/Core/Style.js index c158a8d9d0..12a2278864 100644 --- a/src/Core/Style.js +++ b/src/Core/Style.js @@ -8,7 +8,7 @@ import itowns_stroke_single_before from './StyleChunk/itowns_stroke_single_befor export const cacheStyle = new Cache(); const inv255 = 1 / 255; -const canvas = document.createElement('canvas'); +const canvas = (typeof document !== 'undefined') ? document.createElement('canvas') : {}; const style_properties = {}; function base_altitudeDefault(properties, coordinates = { z: 0 }) { @@ -710,14 +710,17 @@ class Style { const CustomStyle = { itowns_stroke_single_before, }; -const customStyleSheet = document.createElement('style'); + +const customStyleSheet = (typeof document !== 'undefined') ? document.createElement('style') : {}; customStyleSheet.type = 'text/css'; Object.keys(CustomStyle).forEach((key) => { customStyleSheet.innerHTML += `${CustomStyle[key]}\n\n`; }); -document.getElementsByTagName('head')[0].appendChild(customStyleSheet); +if (typeof document !== 'undefined') { + document.getElementsByTagName('head')[0].appendChild(customStyleSheet); +} const style = new Style();