mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-27 23:45:23 +01:00
Merge pull request #684 from orangemug/fix/issue-533
Fix for updating available sources cache when updating style
This commit is contained in:
commit
1e4aadbb6d
2 changed files with 46 additions and 31 deletions
|
@ -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] = {
|
sourceList[key] = {
|
||||||
type: val.type,
|
type: val.type,
|
||||||
layers: []
|
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,16 +596,17 @@ 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")) {
|
if(!json.hasOwnProperty("vector_layers")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new objects before setState
|
// Create new objects before setState
|
||||||
const sources = Object.assign({}, this.state.sources);
|
const sources = Object.assign({}, {
|
||||||
|
[key]: this.state.sources[key],
|
||||||
|
});
|
||||||
|
|
||||||
for(let layer of json.vector_layers) {
|
for(let layer of json.vector_layers) {
|
||||||
sources[key].layers.push(layer.id)
|
sources[key].layers.push(layer.id)
|
||||||
|
@ -615,9 +617,12 @@ export default class App extends React.Component {
|
||||||
sources: sources
|
sources: sources
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(err => {
|
||||||
console.error("Failed to process sources for '%s'", url, err);
|
console.error("Failed to process sources for '%s'", url, err);
|
||||||
})
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sourceList[key] = this.state.sources[key] || this.state.mapStyle.sources[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,8 @@ function findClosestCommonPrefix(layers, idx) {
|
||||||
return closestIdx
|
return closestIdx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let UID = 0;
|
||||||
|
|
||||||
// List of collapsible layer editors
|
// List of collapsible layer editors
|
||||||
class LayerListContainer extends React.Component {
|
class LayerListContainer extends React.Component {
|
||||||
static propTypes = {...layerListPropTypes}
|
static propTypes = {...layerListPropTypes}
|
||||||
|
@ -49,6 +51,9 @@ class LayerListContainer extends React.Component {
|
||||||
this.state = {
|
this.state = {
|
||||||
collapsedGroups: {},
|
collapsedGroups: {},
|
||||||
areAllGroupsExpanded: false,
|
areAllGroupsExpanded: false,
|
||||||
|
keys: {
|
||||||
|
add: UID++,
|
||||||
|
},
|
||||||
isOpen: {
|
isOpen: {
|
||||||
add: false,
|
add: false,
|
||||||
}
|
}
|
||||||
|
@ -57,6 +62,10 @@ class LayerListContainer extends React.Component {
|
||||||
|
|
||||||
toggleModal(modalName) {
|
toggleModal(modalName) {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
keys: {
|
||||||
|
...this.state.keys,
|
||||||
|
[modalName]: UID++,
|
||||||
|
},
|
||||||
isOpen: {
|
isOpen: {
|
||||||
...this.state.isOpen,
|
...this.state.isOpen,
|
||||||
[modalName]: !this.state.isOpen[modalName]
|
[modalName]: !this.state.isOpen[modalName]
|
||||||
|
@ -253,6 +262,7 @@ class LayerListContainer extends React.Component {
|
||||||
|
|
||||||
return <div className="maputnik-layer-list" ref={this.scrollContainerRef}>
|
return <div className="maputnik-layer-list" ref={this.scrollContainerRef}>
|
||||||
<AddModal
|
<AddModal
|
||||||
|
key={this.state.keys.add}
|
||||||
layers={this.props.layers}
|
layers={this.props.layers}
|
||||||
sources={this.props.sources}
|
sources={this.props.sources}
|
||||||
isOpen={this.state.isOpen.add}
|
isOpen={this.state.isOpen.add}
|
||||||
|
|
Loading…
Reference in a new issue