Don't swith the background layer if we don't need to

This commit is contained in:
pietervdvn 2021-11-22 00:02:40 +01:00
parent 9b7f8bfa47
commit 7a45477ae2

View file

@ -84,9 +84,16 @@ class SingleLayerSelectionButton extends Toggle {
previousLayer.setData(previousLayer.data ?? available.data)
options.currentBackground.setData(previousLayer.data)
})
options.currentBackground.addCallbackAndRunD(background => {
if (background.category === options.preferredType) {
previousLayer.setData(background)
}
})
available.addCallbackAndRunD(availableLayer => {
available.addCallbackD(availableLayer => {
// Called whenever a better layer is available
if (previousLayer.data === undefined) {
// PreviousLayer is unset -> we definitively weren't using this category -> no need to switch
@ -96,6 +103,11 @@ class SingleLayerSelectionButton extends Toggle {
// The previously used layer doesn't match the current layer -> no need to switch
return;
}
// Is the previous layer still valid? If so, we don't bother to switch
if(previousLayer.data.feature === null || GeoOperations.inside(locationControl.data, previousLayer.data.feature)){
return
}
if (availableLayer.category === options.preferredType) {
// Allright, we can set this different layer
@ -112,12 +124,6 @@ class SingleLayerSelectionButton extends Toggle {
}
})
options.currentBackground.addCallbackAndRunD(background => {
if (background.category === options.preferredType) {
previousLayer.setData(background)
}
})
this.activate = () => {
checkPreviousLayer()
if (available.data.category !== options.preferredType) {