mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-29 09:00:29 +01:00
Added loading modal when opening styles.
This commit is contained in:
parent
7a7f2eb7de
commit
7167235146
1 changed files with 38 additions and 1 deletions
|
@ -60,13 +60,29 @@ class OpenModal extends React.Component {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onCancelActiveRequest(e) {
|
||||||
|
// Else the click propagates to the underlying modal
|
||||||
|
if(e) e.stopPropagation();
|
||||||
|
|
||||||
|
if(this.state.activeRequest) {
|
||||||
|
this.state.activeRequest.abort();
|
||||||
|
this.setState({
|
||||||
|
activeRequest: null
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onStyleSelect(styleUrl) {
|
onStyleSelect(styleUrl) {
|
||||||
this.clearError();
|
this.clearError();
|
||||||
|
|
||||||
request({
|
const activeRequest = request({
|
||||||
url: styleUrl,
|
url: styleUrl,
|
||||||
withCredentials: false,
|
withCredentials: false,
|
||||||
}, (error, response, body) => {
|
}, (error, response, body) => {
|
||||||
|
this.setState({
|
||||||
|
activeRequest: null
|
||||||
|
});
|
||||||
|
|
||||||
if (!error && response.statusCode == 200) {
|
if (!error && response.statusCode == 200) {
|
||||||
const mapStyle = style.ensureStyleValidity(JSON.parse(body))
|
const mapStyle = style.ensureStyleValidity(JSON.parse(body))
|
||||||
console.log('Loaded style ', mapStyle.id)
|
console.log('Loaded style ', mapStyle.id)
|
||||||
|
@ -76,6 +92,10 @@ class OpenModal extends React.Component {
|
||||||
console.warn('Could not open the style URL', styleUrl)
|
console.warn('Could not open the style URL', styleUrl)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
activeRequest: activeRequest
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
onOpenUrl() {
|
onOpenUrl() {
|
||||||
|
@ -169,6 +189,23 @@ class OpenModal extends React.Component {
|
||||||
{styleOptions}
|
{styleOptions}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
data-wd-key="loading-modal"
|
||||||
|
isOpen={this.state.activeRequest}
|
||||||
|
closeable={false}
|
||||||
|
title={'Loading style'}
|
||||||
|
onOpenToggle={() => this.onCancelActiveRequest()}
|
||||||
|
>
|
||||||
|
<p>
|
||||||
|
Loading...
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<Button onClick={(e) => this.onCancelActiveRequest(e)}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
</p>
|
||||||
|
</Modal>
|
||||||
</Modal>
|
</Modal>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue