Merge pull request #6964 from fredj/kml_DataParser
Fix KML ExtendedData reading
This commit is contained in:
@@ -1092,13 +1092,13 @@ ol.format.KML.setCommonGeometryProperties_ = function(multiGeometry,
|
|||||||
ol.format.KML.DataParser_ = function(node, objectStack) {
|
ol.format.KML.DataParser_ = function(node, objectStack) {
|
||||||
var name = node.getAttribute('name');
|
var name = node.getAttribute('name');
|
||||||
ol.xml.parseNode(ol.format.KML.DATA_PARSERS_, node, objectStack);
|
ol.xml.parseNode(ol.format.KML.DATA_PARSERS_, node, objectStack);
|
||||||
var featureObject =
|
var featureObject = /** @type {Object} */ (objectStack[objectStack.length - 1]);
|
||||||
/** @type {Object} */ (objectStack[objectStack.length - 1]);
|
|
||||||
if (name !== null) {
|
if (name !== null) {
|
||||||
featureObject[name] = featureObject.value;
|
featureObject[name] = featureObject.value;
|
||||||
} else if (featureObject.displayName !== null) {
|
} else if (featureObject.displayName !== null) {
|
||||||
featureObject[featureObject.displayName] = featureObject.value;
|
featureObject[featureObject.displayName] = featureObject.value;
|
||||||
}
|
}
|
||||||
|
delete featureObject['value'];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1580,9 +1580,31 @@ describe('ol.format.KML', function() {
|
|||||||
expect(fs).to.have.length(1);
|
expect(fs).to.have.length(1);
|
||||||
var f = fs[0];
|
var f = fs[0];
|
||||||
expect(f).to.be.an(ol.Feature);
|
expect(f).to.be.an(ol.Feature);
|
||||||
|
expect(f.getProperties()).to.only.have.keys(['foo', 'geometry']);
|
||||||
expect(f.get('foo')).to.be('bar');
|
expect(f.get('foo')).to.be('bar');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can read ExtendedData with no values', function() {
|
||||||
|
var text =
|
||||||
|
'<kml xmlns="http://earth.google.com/kml/2.2">' +
|
||||||
|
' <Placemark xmlns="http://earth.google.com/kml/2.2">' +
|
||||||
|
' <ExtendedData>' +
|
||||||
|
' <Data name="foo">' +
|
||||||
|
' <value>200</value>' +
|
||||||
|
' </Data>' +
|
||||||
|
' <Data name="bar"/>' +
|
||||||
|
' </ExtendedData>' +
|
||||||
|
' </Placemark>' +
|
||||||
|
'</kml>';
|
||||||
|
var fs = format.readFeatures(text);
|
||||||
|
expect(fs).to.have.length(1);
|
||||||
|
var f = fs[0];
|
||||||
|
expect(f).to.be.an(ol.Feature);
|
||||||
|
expect(f.getProperties()).to.only.have.keys(['foo', 'bar', 'geometry']);
|
||||||
|
expect(f.get('foo')).to.be('200');
|
||||||
|
expect(f.get('bar')).to.be(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
it('can read ExtendedData with displayName instead of name', function() {
|
it('can read ExtendedData with displayName instead of name', function() {
|
||||||
var text =
|
var text =
|
||||||
'<kml xmlns="http://earth.google.com/kml/2.2">' +
|
'<kml xmlns="http://earth.google.com/kml/2.2">' +
|
||||||
|
|||||||
Reference in New Issue
Block a user