From d9b6f28bb59e20d02c56c67db6afa1aa8700d9bb Mon Sep 17 00:00:00 2001 From: jPalmer Date: Wed, 31 Jan 2018 11:26:10 -0800 Subject: [PATCH 1/3] added missing glyphs property check on styleChanged - addresses #229 --- src/components/App.jsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/components/App.jsx b/src/components/App.jsx index c76bf70..919e151 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -111,6 +111,16 @@ export default class App extends React.Component { } onStyleChanged(newStyle, save=true) { + + if(newStyle.glyphs === undefined){ + let error = "Failed because no glyphs property found in style"; + this.setState({ + errors:[error] + }) + console.error(error) + return + } + if(newStyle.glyphs !== this.state.mapStyle.glyphs) { this.updateFonts(newStyle.glyphs) } From 844abd38cead642e6b375e00532070f7134e69ec Mon Sep 17 00:00:00 2001 From: jPalmer Date: Wed, 31 Jan 2018 11:28:09 -0800 Subject: [PATCH 2/3] added missing glyphs property check on styleChanged - addresses #229 --- src/components/App.jsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/App.jsx b/src/components/App.jsx index 919e151..51992d8 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -117,10 +117,9 @@ export default class App extends React.Component { this.setState({ errors:[error] }) - console.error(error) return } - + if(newStyle.glyphs !== this.state.mapStyle.glyphs) { this.updateFonts(newStyle.glyphs) } From 92ef1c4cbbb5f677e7e6cd7e3fc79b6f993e57f9 Mon Sep 17 00:00:00 2001 From: jPalmer Date: Thu, 1 Feb 2018 13:44:15 -0800 Subject: [PATCH 3/3] added more robust handling of glyphs in styles - addresses #229 --- src/components/App.jsx | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/components/App.jsx b/src/components/App.jsx index 51992d8..7652c9c 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -99,7 +99,9 @@ export default class App extends React.Component { updateFonts(urlTemplate) { const metadata = this.state.mapStyle.metadata || {} const accessToken = metadata['maputnik:openmaptiles_access_token'] || tokens.openmaptiles - downloadGlyphsMetadata(urlTemplate.replace('{key}', accessToken), fonts => { + + let glyphUrl = (typeof urlTemplate === 'string')? urlTemplate.replace('{key}', accessToken): urlTemplate; + downloadGlyphsMetadata(glyphUrl, fonts => { this.setState({ spec: updateRootSpec(this.state.spec, 'glyphs', fonts)}) }) } @@ -112,23 +114,16 @@ export default class App extends React.Component { onStyleChanged(newStyle, save=true) { - if(newStyle.glyphs === undefined){ - let error = "Failed because no glyphs property found in style"; - this.setState({ - errors:[error] - }) - return - } - - if(newStyle.glyphs !== this.state.mapStyle.glyphs) { - this.updateFonts(newStyle.glyphs) - } - if(newStyle.sprite !== this.state.mapStyle.sprite) { - this.updateIcons(newStyle.sprite) - } - const errors = styleSpec.validate(newStyle, styleSpec.latest) if(errors.length === 0) { + + if(newStyle.glyphs !== this.state.mapStyle.glyphs) { + this.updateFonts(newStyle.glyphs) + } + if(newStyle.sprite !== this.state.mapStyle.sprite) { + this.updateIcons(newStyle.sprite) + } + this.revisionStore.addRevision(newStyle) if(save) this.saveStyle(newStyle) this.setState({