From 5ce57d08034beed7f0d3052f5a1f9828edc65795 Mon Sep 17 00:00:00 2001 From: orangemug Date: Thu, 1 Feb 2018 21:33:07 +0000 Subject: [PATCH 1/2] Added guard in fetchSources. This will mean that autocomplete is broken for sources without vector_layers key present. --- src/components/App.jsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/App.jsx b/src/components/App.jsx index c76bf70..4eca4c3 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -202,7 +202,7 @@ export default class App extends React.Component { layers: [] }; - if(!this.state.sources.hasOwnProperty(key) && val.type === "vector") { + if(!this.state.sources.hasOwnProperty(key) && val.type === "vector" && val.hasOwnProperty("url")) { let url = val.url; try { url = mapboxUtil.normalizeSourceURL(url, MapboxGl.accessToken); @@ -215,6 +215,10 @@ export default class App extends React.Component { return response.json(); }) .then((json) => { + if(!json.hasOwnProperty("vector_layers")) { + return; + } + // Create new objects before setState const sources = Object.assign({}, this.state.sources); From 7d5927bbc84ecf8a051897bca36933e8b8769e0c Mon Sep 17 00:00:00 2001 From: orangemug Date: Thu, 1 Feb 2018 22:00:26 +0000 Subject: [PATCH 2/2] Added additional guard As checking the key name is 'openmaptiles' isn't a guarantee --- src/libs/style.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/style.js b/src/libs/style.js index cf2cff6..4441912 100644 --- a/src/libs/style.js +++ b/src/libs/style.js @@ -57,6 +57,7 @@ function indexOfLayer(layers, layerId) { function replaceAccessToken(mapStyle) { const omtSource = mapStyle.sources.openmaptiles if(!omtSource) return mapStyle + if(!omtSource.hasOwnProperty("url")) return mapStyle const metadata = mapStyle.metadata || {} const accessToken = metadata['maputnik:openmaptiles_access_token'] || tokens.openmaptiles