mirror of
https://github.com/maputnik/editor.git
synced 2026-07-26 07:47:25 +00:00
Fix for updating available sources when updating style.
This commit is contained in:
+36
-31
@@ -440,9 +440,10 @@ export default class App extends React.Component {
|
|||||||
mapStyle: newStyle,
|
mapStyle: newStyle,
|
||||||
dirtyMapStyle: dirtyMapStyle,
|
dirtyMapStyle: dirtyMapStyle,
|
||||||
errors: mappedErrors,
|
errors: mappedErrors,
|
||||||
|
}, () => {
|
||||||
|
this.fetchSources();
|
||||||
})
|
})
|
||||||
|
|
||||||
this.fetchSources();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onUndo = () => {
|
onUndo = () => {
|
||||||
@@ -566,19 +567,19 @@ export default class App extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fetchSources() {
|
fetchSources() {
|
||||||
const sourceList = {...this.state.sources};
|
const sourceList = {};
|
||||||
|
|
||||||
for(let [key, val] of Object.entries(this.state.mapStyle.sources)) {
|
for(let [key, val] of Object.entries(this.state.mapStyle.sources)) {
|
||||||
if(sourceList.hasOwnProperty(key)) {
|
if(
|
||||||
continue;
|
!this.state.sources.hasOwnProperty(key) &&
|
||||||
}
|
val.type === "vector" &&
|
||||||
|
val.hasOwnProperty("url")
|
||||||
|
) {
|
||||||
|
sourceList[key] = {
|
||||||
|
type: val.type,
|
||||||
|
layers: []
|
||||||
|
};
|
||||||
|
|
||||||
sourceList[key] = {
|
|
||||||
type: val.type,
|
|
||||||
layers: []
|
|
||||||
};
|
|
||||||
|
|
||||||
if(!this.state.sources.hasOwnProperty(key) && val.type === "vector" && val.hasOwnProperty("url")) {
|
|
||||||
let url = val.url;
|
let url = val.url;
|
||||||
try {
|
try {
|
||||||
url = normalizeSourceURL(url, MapboxGl.accessToken);
|
url = normalizeSourceURL(url, MapboxGl.accessToken);
|
||||||
@@ -595,29 +596,33 @@ export default class App extends React.Component {
|
|||||||
fetch(url, {
|
fetch(url, {
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then(response => response.json())
|
||||||
return response.json();
|
.then(json => {
|
||||||
})
|
|
||||||
.then((json) => {
|
|
||||||
if(!json.hasOwnProperty("vector_layers")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create new objects before setState
|
if(!json.hasOwnProperty("vector_layers")) {
|
||||||
const sources = Object.assign({}, this.state.sources);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for(let layer of json.vector_layers) {
|
// Create new objects before setState
|
||||||
sources[key].layers.push(layer.id)
|
const sources = Object.assign({}, {
|
||||||
}
|
[key]: this.state.sources[key],
|
||||||
|
});
|
||||||
|
|
||||||
console.debug("Updating source: "+key);
|
for(let layer of json.vector_layers) {
|
||||||
this.setState({
|
sources[key].layers.push(layer.id)
|
||||||
sources: sources
|
}
|
||||||
});
|
|
||||||
})
|
console.debug("Updating source: "+key);
|
||||||
.catch((err) => {
|
this.setState({
|
||||||
console.error("Failed to process sources for '%s'", url, err);
|
sources: sources
|
||||||
})
|
});
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error("Failed to process sources for '%s'", url, err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sourceList[key] = this.state.sources[key] || this.state.mapStyle.sources[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user