OpenLayers OpenLayers

Ticket #1613: ticket1613.patch

File ticket1613.patch, 3.5 kB (added by bartvde, 5 months ago)
  • GML.js

    old new  
    105105     *  
    106106     * Parameters: 
    107107     * data - {String} or {DOMElement} data to read/parse. 
     108     * options - {Object} The options object may contain a returnBbox property.  If 
     109     *     the returnBbox is true, the bounding box of the feature collection 
     110     *     will be returned along with the features. 
    108111     * 
    109112     * Returns: 
    110113     * {Array(<OpenLayers.Feature.Vector>)} An array of features. 
    111114     */ 
    112     read: function(data) { 
     115    read: function(data, options) { 
    113116        if(typeof data == "string") {  
    114117            data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); 
    115118        } 
     119 
     120        var bbox; 
     121        if (options && options.returnBbox) { 
     122            var boundedByNodes = this.getElementsByTagNameNS( 
     123                data.documentElement, this.gmlns, 'boundedBy'); 
     124            for (var i=0; i < boundedByNodes.length; i++) { 
     125                // we are only interested in the top level boundedBy 
     126                // and there is currently no way to limit getElementsByTagNameNS 
     127                // to a certain level 
     128                if (boundedByNodes[i].parentNode == data.documentElement) { 
     129                    var type = 'Box'; 
     130                    var parser = this.parseGeometry[type.toLowerCase()]; 
     131                    if (parser) { 
     132                        bbox = parser.apply(this, [boundedByNodes[i]]); 
     133                    } 
     134                } 
     135            } 
     136        } 
     137 
    116138        var featureNodes = this.getElementsByTagNameNS(data.documentElement, 
    117139                                                       this.gmlns, 
    118140                                                       this.featureName); 
     
    123145                features.push(feature); 
    124146            } 
    125147        } 
    126         return features; 
     148       
     149        if (options && options.returnBbox) { 
     150            return {bbox: bbox, features: features}; 
     151        } else { 
     152            return features; 
     153        } 
    127154    }, 
    128155     
    129156    /** 
     
    263290                                                 coords[2]); 
    264291            } 
    265292        }, 
     293 
     294        /** 
     295         * Method: parseGeometry.box 
     296         * Given a GML node representing a box geometry, create an 
     297         *     OpenLayers rectangle geometry. 
     298         * 
     299         * Parameters: 
     300         * node - {DOMElement} A GML node. 
     301         * 
     302         * Returns: 
     303         * {<OpenLayers.Bounds>} A bounds representing the box. 
     304         */ 
     305        box: function(node) { 
     306            var nodeList = this.getElementsByTagNameNS(node, this.gmlns, 
     307                                                   "coordinates"); 
     308            var coordString; 
     309            var coords, beginPoint, endPoint; 
     310            if (nodeList.length > 0) { 
     311                coordString = nodeList[0].firstChild.nodeValue; 
     312                coords = coordString.split(" "); 
     313                for (var i=0; i < coords.length; i++) { 
     314                    if (i == 0) { 
     315                        beginPoint = coords[i].split(","); 
     316                    } 
     317                    if (i == 1) { 
     318                        endPoint = coords[i].split(","); 
     319                    } 
     320                } 
     321            } 
     322            return new OpenLayers.Bounds(parseInt(beginPoint[0]), 
     323                parseInt(beginPoint[1]), 
     324                parseInt(endPoint[0]), 
     325                parseInt(endPoint[1]) ); 
     326        }, 
    266327         
    267328        /** 
    268329         * Method: parseGeometry.multipoint