@@ -19951,18 +19951,32 @@ ol.control.WMSCapabilities = class olcontrolWMSCapabilities extends ol.control.B
19951
19951
this.getCapabilities(url, {
19952
19952
onload: function (cap) {
19953
19953
if (cap) {
19954
- cap.Capability.Layer.Layer.forEach(function (l) {
19955
- if (l.Name === layerName || l.Identifier === layerName) {
19956
- var options = this.getOptionsFromCap(l, cap)
19957
- var layer = this.getLayerFromOptions(options)
19958
- this.dispatchEvent({ type: 'load', layer: layer, options: options })
19959
- if (typeof (onload) === 'function')
19960
- onload({ layer: layer, options: options })
19954
+ // Find layer recursively
19955
+ function findLayer(layers) {
19956
+ for (var i=0; i<layers.length; i++) {
19957
+ var l = layers[i];
19958
+ if (l.Name === layerName || l.Identifier === layerName) {
19959
+ return l;
19960
+ } else if (l.Layer) {
19961
+ // Sub layer
19962
+ var l2 = findLayer(l.Layer)
19963
+ if (l2) return l2
19964
+ }
19961
19965
}
19962
- }.bind(this))
19963
- } else {
19964
- this.dispatchEvent({ type: 'load', error: true })
19966
+ }
19967
+ var lcap = findLayer(cap.Capability.Layer.Layer)
19968
+ // Find one
19969
+ if (lcap) {
19970
+ var options = this.getOptionsFromCap(lcap, cap)
19971
+ var layer = this.getLayerFromOptions(options)
19972
+ this.dispatchEvent({ type: 'load', layer: layer, options: options })
19973
+ if (typeof (onload) === 'function') {
19974
+ onload({ layer: layer, options: options })
19975
+ }
19976
+ return;
19977
+ }
19965
19978
}
19979
+ this.dispatchEvent({ type: 'load', error: true })
19966
19980
}.bind(this)
19967
19981
})
19968
19982
}
0 commit comments