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 28 28 "read geometry collection"); 29 29 } 30 30 31 function test_Format_KML_readCdataAttributes (t) {31 function test_Format_KML_readCdataAttributes_20(t) { 32 32 t.plan(2); 33 33 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 34 var features = (new OpenLayers.Format.KML()).read(cdata); … … 37 37 38 38 } 39 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>'; 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 40 49 function test_Format_KML_write(t) { 41 50 // make sure id, name, and description are preserved 42 51 t.plan(1); -
lib/OpenLayers/Format/KML.js
old new 48 48 * {Boolean} Extract attributes from KML. Default is true. 49 49 */ 50 50 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, 51 58 52 59 /** 53 60 * Constructor: OpenLayers.Format.KML … … 83 90 data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); 84 91 } 85 92 var featureNodes = this.getElementsByTagNameNS(data, 86 this.kmlns,93 '*', 87 94 "Placemark"); 88 95 var numFeatures = featureNodes.length; 89 96 var features = new Array(numFeatures); … … 116 123 var type, nodeList, geometry, parser; 117 124 for(var i=0; i<order.length; ++i) { 118 125 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); 120 130 if(nodeList.length > 0) { 121 131 // only deal with first geometry of this type 122 132 var parser = this.parseGeometry[type.toLowerCase()]; … … 165 175 * {<OpenLayers.Geometry.Point>} A point geometry. 166 176 */ 167 177 point: function(node) { 168 var nodeList = this.getElementsByTagNameNS(node, this. kmlns,178 var nodeList = this.getElementsByTagNameNS(node, this.internalns, 169 179 "coordinates"); 170 180 var coords = []; 171 181 if(nodeList.length > 0) { … … 200 210 * {<OpenLayers.Geometry.LineString>} A linestring geometry. 201 211 */ 202 212 linestring: function(node, ring) { 203 var nodeList = this.getElementsByTagNameNS(node, this. kmlns,213 var nodeList = this.getElementsByTagNameNS(node, this.internalns, 204 214 "coordinates"); 205 215 var line = null; 206 216 if(nodeList.length > 0) { … … 254 264 * {<OpenLayers.Geometry.Polygon>} A polygon geometry. 255 265 */ 256 266 polygon: function(node) { 257 var nodeList = this.getElementsByTagNameNS(node, this. kmlns,267 var nodeList = this.getElementsByTagNameNS(node, this.internalns, 258 268 "LinearRing"); 259 269 var numRings = nodeList.length; 260 270 var components = new Array(numRings);
