OpenLayers OpenLayers
Show
Ignore:
Timestamp:
10/03/07 17:18:39 (1 year ago)
Author:
crschmidt
Message:

Pullup for KML needs to automatically determine the namespace of the document
it is handling. (Closes #1044)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/openlayers/2.5/lib/OpenLayers/Format/KML.js

    r4432 r4798  
    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    /** 
     
    8491        } 
    8592        var featureNodes = this.getElementsByTagNameNS(data, 
    86                                                        this.kmlns
     93                                                       '*'
    8794                                                       "Placemark"); 
    8895        var numFeatures = featureNodes.length; 
     
    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 
     
    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 = []; 
     
    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; 
     
    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; 
  • branches/openlayers/2.5/tests/Format/test_KML.html

    r4432 r4798  
    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>'; 
     34        var features = (new OpenLayers.Format.KML()).read(cdata); 
     35        t.eq(features[0].attributes.description, "Full of text.", "Description attribute in cdata read correctly"); 
     36        t.eq(features[0].attributes.name, "Pezinok", "title attribute in cdata read correctly"); 
     37         
     38    } 
     39     
     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>'; 
    3443        var features = (new OpenLayers.Format.KML()).read(cdata); 
    3544        t.eq(features[0].attributes.description, "Full of text.", "Description attribute in cdata read correctly");