OpenLayers OpenLayers

Changeset 9529

Show
Ignore:
Timestamp:
06/30/09 06:28:30 (7 months ago)
Author:
bartvde
Message:

add recursive parsing of layers (nested OWSContext)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/bartvde/owscontext/openlayers/lib/OpenLayers/Format/OWSContext/v0_3_1.js

    r9422 r9529  
    239239        context.layers = []; 
    240240        this.readNode(data, context); 
     241 
    241242        // we need to do postprocessing since we do not know the layer type 
    242243        // at the time we parse the Layer node 
    243         for (var i=0, len=context.layerInfo.length; i<len; i++) { 
    244             var layer = this.getLayerFromInfo(context.layerInfo[i]); 
    245             if (layer !== null) { 
    246                 context.layers.push(layer); 
    247             } 
    248         } 
    249         delete context.layerInfo; 
     244 
     245        // since an OWSContext can be nested we need to go through this 
     246        // structure recursively       
     247        this.processLayer(context.layers, context); 
    250248        return context; 
     249    }, 
     250 
     251    /** 
     252     * Method: processLayer 
     253     * Recursive function to process a layer and their childLayers 
     254     * 
     255     * Parameters: 
     256     * layer - {Object} layerInfo object 
     257     */ 
     258    processLayer: function(layerArray, layer) { 
     259        if (layer.layerInfo) { 
     260            for (var i=0, len = layer.layerInfo.length; i<len; i++) { 
     261                var l = layer.layerInfo[i]; 
     262                var layerObj  = this.getLayerFromInfo(l); 
     263                if (layerObj != null) { 
     264                    layerArray.push(layerObj); 
     265                } 
     266                if (l.layerInfo) { 
     267                    this.processLayer(layerArray, l); 
     268                } 
     269            } 
     270        } 
    251271    }, 
    252272 
     
    294314            }, 
    295315            "ResourceList": function(node, obj) { 
    296                 obj.layerInfo = []; 
    297316                this.readChildNodes(node, obj); 
    298317            }, 
     
    305324                    name: node.getAttribute("name") 
    306325                }; 
     326                if (!obj.layerInfo) { 
     327                    obj.layerInfo = []; 
     328                } 
    307329                obj.layerInfo.push(layerInfo); 
    308330                this.readChildNodes(node, layerInfo);