Pullup for KML needs to automatically determine the namespace of the document
it is handling. (Closes #1044) git-svn-id: http://svn.openlayers.org/branches/openlayers/2.5@4798 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -49,6 +49,13 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
*/
|
*/
|
||||||
extractAttributes: true,
|
extractAttributes: true,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: internalns
|
||||||
|
* {String} KML Namespace to use -- defaults to the namespace of the
|
||||||
|
* Placemark node being parsed, but falls back to kmlns.
|
||||||
|
*/
|
||||||
|
internalns: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor: OpenLayers.Format.KML
|
* Constructor: OpenLayers.Format.KML
|
||||||
* Create a new parser for KML.
|
* Create a new parser for KML.
|
||||||
@@ -83,7 +90,7 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
|
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
|
||||||
}
|
}
|
||||||
var featureNodes = this.getElementsByTagNameNS(data,
|
var featureNodes = this.getElementsByTagNameNS(data,
|
||||||
this.kmlns,
|
'*',
|
||||||
"Placemark");
|
"Placemark");
|
||||||
var numFeatures = featureNodes.length;
|
var numFeatures = featureNodes.length;
|
||||||
var features = new Array(numFeatures);
|
var features = new Array(numFeatures);
|
||||||
@@ -116,7 +123,10 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
var type, nodeList, geometry, parser;
|
var type, nodeList, geometry, parser;
|
||||||
for(var i=0; i<order.length; ++i) {
|
for(var i=0; i<order.length; ++i) {
|
||||||
type = order[i];
|
type = order[i];
|
||||||
nodeList = this.getElementsByTagNameNS(node, this.kmlns, type);
|
this.internalns = node.namespaceURI ?
|
||||||
|
node.namespaceURI : this.kmlns;
|
||||||
|
nodeList = this.getElementsByTagNameNS(node,
|
||||||
|
this.internalns, type);
|
||||||
if(nodeList.length > 0) {
|
if(nodeList.length > 0) {
|
||||||
// only deal with first geometry of this type
|
// only deal with first geometry of this type
|
||||||
var parser = this.parseGeometry[type.toLowerCase()];
|
var parser = this.parseGeometry[type.toLowerCase()];
|
||||||
@@ -165,7 +175,7 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
* {<OpenLayers.Geometry.Point>} A point geometry.
|
* {<OpenLayers.Geometry.Point>} A point geometry.
|
||||||
*/
|
*/
|
||||||
point: function(node) {
|
point: function(node) {
|
||||||
var nodeList = this.getElementsByTagNameNS(node, this.kmlns,
|
var nodeList = this.getElementsByTagNameNS(node, this.internalns,
|
||||||
"coordinates");
|
"coordinates");
|
||||||
var coords = [];
|
var coords = [];
|
||||||
if(nodeList.length > 0) {
|
if(nodeList.length > 0) {
|
||||||
@@ -200,7 +210,7 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
* {<OpenLayers.Geometry.LineString>} A linestring geometry.
|
* {<OpenLayers.Geometry.LineString>} A linestring geometry.
|
||||||
*/
|
*/
|
||||||
linestring: function(node, ring) {
|
linestring: function(node, ring) {
|
||||||
var nodeList = this.getElementsByTagNameNS(node, this.kmlns,
|
var nodeList = this.getElementsByTagNameNS(node, this.internalns,
|
||||||
"coordinates");
|
"coordinates");
|
||||||
var line = null;
|
var line = null;
|
||||||
if(nodeList.length > 0) {
|
if(nodeList.length > 0) {
|
||||||
@@ -254,7 +264,7 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
* {<OpenLayers.Geometry.Polygon>} A polygon geometry.
|
* {<OpenLayers.Geometry.Polygon>} A polygon geometry.
|
||||||
*/
|
*/
|
||||||
polygon: function(node) {
|
polygon: function(node) {
|
||||||
var nodeList = this.getElementsByTagNameNS(node, this.kmlns,
|
var nodeList = this.getElementsByTagNameNS(node, this.internalns,
|
||||||
"LinearRing");
|
"LinearRing");
|
||||||
var numRings = nodeList.length;
|
var numRings = nodeList.length;
|
||||||
var components = new Array(numRings);
|
var components = new Array(numRings);
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
"read geometry collection");
|
"read geometry collection");
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_Format_KML_readCdataAttributes(t) {
|
function test_Format_KML_readCdataAttributes_20(t) {
|
||||||
t.plan(2);
|
t.plan(2);
|
||||||
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>';
|
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>';
|
||||||
var features = (new OpenLayers.Format.KML()).read(cdata);
|
var features = (new OpenLayers.Format.KML()).read(cdata);
|
||||||
@@ -37,6 +37,15 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_Format_KML_readCdataAttributes_21(t) {
|
||||||
|
t.plan(2);
|
||||||
|
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>';
|
||||||
|
var features = (new OpenLayers.Format.KML()).read(cdata);
|
||||||
|
t.eq(features[0].attributes.description, "Full of text.", "Description attribute in cdata read correctly");
|
||||||
|
t.eq(features[0].attributes.name, "Pezinok", "title attribute in cdata read correctly");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function test_Format_KML_write(t) {
|
function test_Format_KML_write(t) {
|
||||||
// make sure id, name, and description are preserved
|
// make sure id, name, and description are preserved
|
||||||
t.plan(1);
|
t.plan(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user