OpenLayers OpenLayers

Ticket #1044: kml_ns.patch

File kml_ns.patch, 4.5 kB (added by crschmidt, 1 year ago)
  • tests/Format/test_KML.html

    old new  
    2828             "read geometry collection"); 
    2929    } 
    3030 
    31     function test_Format_KML_readCdataAttributes(t) { 
     31    function test_Format_KML_readCdataAttributes_20(t) { 
    3232        t.plan(2); 
    3333        var cdata = '<kml xmlns="http://earth.google.com/kml/2.0"><Document><Placemark><name><![CDATA[Pezinok]]></name><description><![CDATA[Full of text.]]></description><styleUrl>#rel1.0</styleUrl><Point> <coordinates>17.266666, 48.283333</coordinates></Point></Placemark></Document></kml>'; 
    3434        var features = (new OpenLayers.Format.KML()).read(cdata); 
     
    3737         
    3838    } 
    3939     
     40    function test_Format_KML_readCdataAttributes_21(t) { 
     41        t.plan(2); 
     42        var cdata = '<kml xmlns="http://earth.google.com/kml/2.1"><Document><Placemark><name><![CDATA[Pezinok]]></name><description><![CDATA[Full of text.]]></description><styleUrl>#rel1.0</styleUrl><Point> <coordinates>17.266666, 48.283333</coordinates></Point></Placemark></Document></kml>'; 
     43        var features = (new OpenLayers.Format.KML()).read(cdata); 
     44        t.eq(features[0].attributes.description, "Full of text.", "Description attribute in cdata read correctly"); 
     45        t.eq(features[0].attributes.name, "Pezinok", "title attribute in cdata read correctly"); 
     46         
     47    } 
     48     
    4049    function test_Format_KML_write(t) { 
    4150        // make sure id, name, and description are preserved 
    4251        t.plan(1); 
  • lib/OpenLayers/Format/KML.js

    old new  
    4848     * {Boolean} Extract attributes from KML.  Default is true. 
    4949     */ 
    5050    extractAttributes: true, 
     51     
     52    /** 
     53     * Property: internalns 
     54     * {String} KML Namespace to use -- defaults to the namespace of the 
     55     *     Placemark node being parsed, but falls back to kmlns.  
     56     */ 
     57    internalns: null, 
    5158 
    5259    /** 
    5360     * Constructor: OpenLayers.Format.KML 
     
    8390            data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); 
    8491        } 
    8592        var featureNodes = this.getElementsByTagNameNS(data, 
    86                                                        this.kmlns
     93                                                       '*'
    8794                                                       "Placemark"); 
    8895        var numFeatures = featureNodes.length; 
    8996        var features = new Array(numFeatures); 
     
    116123        var type, nodeList, geometry, parser; 
    117124        for(var i=0; i<order.length; ++i) { 
    118125            type = order[i]; 
    119             nodeList = this.getElementsByTagNameNS(node, this.kmlns, type); 
     126            this.internalns = node.namespaceURI ?  
     127                    node.namespaceURI : this.kmlns; 
     128            nodeList = this.getElementsByTagNameNS(node,  
     129                                                   this.internalns, type); 
    120130            if(nodeList.length > 0) { 
    121131                // only deal with first geometry of this type 
    122132                var parser = this.parseGeometry[type.toLowerCase()]; 
     
    165175         * {<OpenLayers.Geometry.Point>} A point geometry. 
    166176         */ 
    167177        point: function(node) { 
    168             var nodeList = this.getElementsByTagNameNS(node, this.kmlns, 
     178            var nodeList = this.getElementsByTagNameNS(node, this.internalns, 
    169179                                                       "coordinates"); 
    170180            var coords = []; 
    171181            if(nodeList.length > 0) { 
     
    200210         * {<OpenLayers.Geometry.LineString>} A linestring geometry. 
    201211         */ 
    202212        linestring: function(node, ring) { 
    203             var nodeList = this.getElementsByTagNameNS(node, this.kmlns, 
     213            var nodeList = this.getElementsByTagNameNS(node, this.internalns, 
    204214                                                       "coordinates"); 
    205215            var line = null; 
    206216            if(nodeList.length > 0) { 
     
    254264         * {<OpenLayers.Geometry.Polygon>} A polygon geometry. 
    255265         */ 
    256266        polygon: function(node) { 
    257             var nodeList = this.getElementsByTagNameNS(node, this.kmlns, 
     267            var nodeList = this.getElementsByTagNameNS(node, this.internalns, 
    258268                                                       "LinearRing"); 
    259269            var numRings = nodeList.length; 
    260270            var components = new Array(numRings);