Merge pull request #236 from orangemug/fix/issue-234

Added guard in fetchSources
This commit is contained in:
Orange Mug 2018-02-02 11:24:23 +00:00 committed by GitHub
commit 6b22c9130f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View file

@ -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);

View file

@ -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