@@ -25,6 +25,12 @@ function refinementCommandCancellationFn(cmd) {
25
25
return true ;
26
26
}
27
27
28
+ // Cancel the command if the layer was removed between command scheduling and command execution
29
+ if ( ! cmd . requester . layerUpdateState [ cmd . layer . id ]
30
+ || ! cmd . layer . source . _featuresCaches [ cmd . layer . source . crs ] ) {
31
+ return true ;
32
+ }
33
+
28
34
return ! cmd . requester . material . visible ;
29
35
}
30
36
@@ -137,6 +143,10 @@ export function updateLayeredMaterialNodeImagery(context, layer, node, parent) {
137
143
138
144
return context . scheduler . execute ( command ) . then (
139
145
( result ) => {
146
+ // Does nothing if the layer has been removed while command was being or waiting to be executed
147
+ if ( ! node . layerUpdateState [ layer . id ] ) {
148
+ return ;
149
+ }
140
150
// TODO: Handle error : result is undefined in provider. throw error
141
151
const pitchs = extentsDestination . map ( ( ext , i ) => ext . offsetToParent ( result [ i ] . extent , nodeLayer . offsetScales [ i ] ) ) ;
142
152
nodeLayer . setTextures ( result , pitchs ) ;
@@ -206,6 +216,11 @@ export function updateLayeredMaterialNodeElevation(context, layer, node, parent)
206
216
207
217
return context . scheduler . execute ( command ) . then (
208
218
( result ) => {
219
+ // Does nothing if the layer has been removed while command was being or waiting to be executed
220
+ if ( ! node . layerUpdateState [ layer . id ] ) {
221
+ return ;
222
+ }
223
+
209
224
// Do not apply the new texture if its level is < than the current
210
225
// one. This is only needed for elevation layers, because we may
211
226
// have several concurrent layers but we can only use one texture.
0 commit comments