FeatureId support in GML (r/w) and KML (w)
Now that we have FeatureId support (see #733), we can add this back to the GML parsers (v2 and v3). Also add write support for FeatureId in KML, read support was already added by @fredj
This commit is contained in:
@@ -687,6 +687,10 @@ ol.parser.KML = function(opt_options) {
|
|||||||
},
|
},
|
||||||
'_feature': function(feature) {
|
'_feature': function(feature) {
|
||||||
var node = this.createElementNS('Placemark');
|
var node = this.createElementNS('Placemark');
|
||||||
|
var fid = feature.getFeatureId();
|
||||||
|
if (goog.isDef(fid)) {
|
||||||
|
node.setAttribute('id', fid);
|
||||||
|
}
|
||||||
this.writeNode('name', feature, null, node);
|
this.writeNode('name', feature, null, node);
|
||||||
this.writeNode('description', feature, null, node);
|
this.writeNode('description', feature, null, node);
|
||||||
var literals = feature.getSymbolizerLiterals();
|
var literals = feature.getSymbolizerLiterals();
|
||||||
|
|||||||
@@ -291,7 +291,11 @@ ol.parser.ogc.GML = function(opt_options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO set feature.type and feature.namespace
|
// TODO set feature.type and feature.namespace
|
||||||
// TODO set fid
|
var fid = node.getAttribute('fid') ||
|
||||||
|
this.getAttributeNS(node, this.defaultNamespaceURI, 'id');
|
||||||
|
if (!goog.isNull(fid)) {
|
||||||
|
feature.setFeatureId(fid);
|
||||||
|
}
|
||||||
obj.features.push(feature);
|
obj.features.push(feature);
|
||||||
},
|
},
|
||||||
'_geometry': function(node, obj) {
|
'_geometry': function(node, obj) {
|
||||||
@@ -389,8 +393,10 @@ ol.parser.ogc.GML = function(opt_options) {
|
|||||||
'_typeName': function(feature) {
|
'_typeName': function(feature) {
|
||||||
var node = this.createElementNS('feature:' + this.featureType,
|
var node = this.createElementNS('feature:' + this.featureType,
|
||||||
this.featureNS);
|
this.featureNS);
|
||||||
// TODO: https://github.com/openlayers/ol3/issues/558
|
var fid = feature.getFeatureId();
|
||||||
// this.setAttributeNS(node, null, 'fid', feature.fid);
|
if (goog.isDef(fid)) {
|
||||||
|
this.setAttributeNS(node, this.defaultNamespaceURI, 'fid', fid);
|
||||||
|
}
|
||||||
if (feature.getGeometry() !== null) {
|
if (feature.getGeometry() !== null) {
|
||||||
this.writeNode('_geometry', feature.getGeometry(), this.featureNS,
|
this.writeNode('_geometry', feature.getGeometry(), this.featureNS,
|
||||||
node);
|
node);
|
||||||
|
|||||||
@@ -94,7 +94,6 @@ ol.parser.ogc.GML_v2 = function(opt_options) {
|
|||||||
[extent.maxX, extent.maxY]], null, node);
|
[extent.maxX, extent.maxY]], null, node);
|
||||||
// srsName attribute is optional for gml:Box
|
// srsName attribute is optional for gml:Box
|
||||||
if (goog.isDef(this.srsName)) {
|
if (goog.isDef(this.srsName)) {
|
||||||
// TODO setAttribute or this.setAttributeNS
|
|
||||||
node.setAttribute('srsName', this.srsName);
|
node.setAttribute('srsName', this.srsName);
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ describe('ol.parser.kml', function() {
|
|||||||
var parser = new ol.parser.KML();
|
var parser = new ol.parser.KML();
|
||||||
|
|
||||||
describe('Test KML parser', function() {
|
describe('Test KML parser', function() {
|
||||||
it('Polygon read correctly', function() {
|
it('Polygon read / written correctly', function() {
|
||||||
var url = 'spec/ol/parser/kml/polygon.kml';
|
var url = 'spec/ol/parser/kml/polygon.kml';
|
||||||
afterLoadXml(url, function(xml) {
|
afterLoadXml(url, function(xml) {
|
||||||
var obj = parser.read(xml);
|
var obj = parser.read(xml);
|
||||||
@@ -13,11 +13,12 @@ describe('ol.parser.kml', function() {
|
|||||||
expect(xml).to.xmleql(goog.dom.xml.loadXml(output));
|
expect(xml).to.xmleql(goog.dom.xml.loadXml(output));
|
||||||
expect(obj.features.length).to.eql(1);
|
expect(obj.features.length).to.eql(1);
|
||||||
var geom = obj.features[0].getGeometry();
|
var geom = obj.features[0].getGeometry();
|
||||||
|
expect(obj.features[0].getFeatureId()).to.eql('KML.Polygon');
|
||||||
expect(geom instanceof ol.geom.Polygon).to.be.ok();
|
expect(geom instanceof ol.geom.Polygon).to.be.ok();
|
||||||
expect(geom.dimension).to.eql(3);
|
expect(geom.dimension).to.eql(3);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('Linestring read correctly', function() {
|
it('Linestring read / written correctly', function() {
|
||||||
var url = 'spec/ol/parser/kml/linestring.kml';
|
var url = 'spec/ol/parser/kml/linestring.kml';
|
||||||
afterLoadXml(url, function(xml) {
|
afterLoadXml(url, function(xml) {
|
||||||
var obj = parser.read(xml);
|
var obj = parser.read(xml);
|
||||||
@@ -31,7 +32,7 @@ describe('ol.parser.kml', function() {
|
|||||||
expect(geom instanceof ol.geom.LineString).to.be.ok();
|
expect(geom instanceof ol.geom.LineString).to.be.ok();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('Point read correctly', function() {
|
it('Point read / written correctly', function() {
|
||||||
var url = 'spec/ol/parser/kml/point.kml';
|
var url = 'spec/ol/parser/kml/point.kml';
|
||||||
afterLoadXml(url, function(xml) {
|
afterLoadXml(url, function(xml) {
|
||||||
var obj = parser.read(xml);
|
var obj = parser.read(xml);
|
||||||
@@ -99,7 +100,7 @@ describe('ol.parser.kml', function() {
|
|||||||
expect(feature.get('ElevationGain')).to.eql('10');
|
expect(feature.get('ElevationGain')).to.eql('10');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('Multi geometry read correctly', function() {
|
it('Multi geometry read / written correctly', function() {
|
||||||
var url = 'spec/ol/parser/kml/multigeometry.kml';
|
var url = 'spec/ol/parser/kml/multigeometry.kml';
|
||||||
afterLoadXml(url, function(xml) {
|
afterLoadXml(url, function(xml) {
|
||||||
var obj = parser.read(xml);
|
var obj = parser.read(xml);
|
||||||
@@ -156,7 +157,7 @@ describe('ol.parser.kml', function() {
|
|||||||
expect(obj.features[0].get('description')).to.eql('Full of text.');
|
expect(obj.features[0].get('description')).to.eql('Full of text.');
|
||||||
expect(obj.features[0].get('name')).to.eql('Pezinok');
|
expect(obj.features[0].get('name')).to.eql('Pezinok');
|
||||||
});
|
});
|
||||||
it('Test line style', function() {
|
it('Test line style (read / write)', function() {
|
||||||
var test_style = '<kml xmlns="http://www.opengis.net/kml/2.2" ' +
|
var test_style = '<kml xmlns="http://www.opengis.net/kml/2.2" ' +
|
||||||
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
|
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
|
||||||
'xsi:schemaLocation="http://www.opengis.net/kml/2.2 ' +
|
'xsi:schemaLocation="http://www.opengis.net/kml/2.2 ' +
|
||||||
@@ -176,7 +177,7 @@ describe('ol.parser.kml', function() {
|
|||||||
expect(symbolizer.opacity).to.eql(0.5294117647058824);
|
expect(symbolizer.opacity).to.eql(0.5294117647058824);
|
||||||
expect(symbolizer.strokeWidth).to.eql(10);
|
expect(symbolizer.strokeWidth).to.eql(10);
|
||||||
});
|
});
|
||||||
it('Test style fill', function() {
|
it('Test style fill (read / write)', function() {
|
||||||
var test_style_fill = '<kml xmlns="http://www.opengis.net/kml/2.2">' +
|
var test_style_fill = '<kml xmlns="http://www.opengis.net/kml/2.2">' +
|
||||||
'<Document><Placemark> <Style> <PolyStyle> <fill>1</fill> ' +
|
'<Document><Placemark> <Style> <PolyStyle> <fill>1</fill> ' +
|
||||||
'<color>870000ff</color> <width>10</width> </PolyStyle> </Style>' +
|
'<color>870000ff</color> <width>10</width> </PolyStyle> </Style>' +
|
||||||
@@ -213,7 +214,7 @@ describe('ol.parser.kml', function() {
|
|||||||
expect(symbolizer1.fillColor).to.eql('#ff0000');
|
expect(symbolizer1.fillColor).to.eql('#ff0000');
|
||||||
expect(symbolizer2.opacity).to.eql(0);
|
expect(symbolizer2.opacity).to.eql(0);
|
||||||
});
|
});
|
||||||
it('Test iconStyle', function() {
|
it('Test iconStyle (read / write)', function() {
|
||||||
var url = 'spec/ol/parser/kml/iconstyle.kml';
|
var url = 'spec/ol/parser/kml/iconstyle.kml';
|
||||||
afterLoadXml(url, function(xml) {
|
afterLoadXml(url, function(xml) {
|
||||||
var p = new ol.parser.KML({extractStyles: true});
|
var p = new ol.parser.KML({extractStyles: true});
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<Document>
|
<Document>
|
||||||
<name>Polygon.kml</name>
|
<name>Polygon.kml</name>
|
||||||
<open>0</open>
|
<open>0</open>
|
||||||
<Placemark>
|
<Placemark id="KML.Polygon">
|
||||||
<name>hollow box</name>
|
<name>hollow box</name>
|
||||||
<Polygon>
|
<Polygon>
|
||||||
<outerBoundaryIs>
|
<outerBoundaryIs>
|
||||||
|
|||||||
@@ -246,7 +246,7 @@ describe('ol.parser.gml_v2', function() {
|
|||||||
expect(feature.getGeometry() instanceof
|
expect(feature.getGeometry() instanceof
|
||||||
ol.geom.MultiPolygon).to.be.ok();
|
ol.geom.MultiPolygon).to.be.ok();
|
||||||
var attributes = feature.getAttributes();
|
var attributes = feature.getAttributes();
|
||||||
// TODO test for fid
|
expect(feature.getFeatureId()).to.eql('states.1');
|
||||||
expect(attributes['STATE_NAME']).to.eql('Illinois');
|
expect(attributes['STATE_NAME']).to.eql('Illinois');
|
||||||
expect(attributes['STATE_FIPS']).to.eql('17');
|
expect(attributes['STATE_FIPS']).to.eql('17');
|
||||||
expect(attributes['SUB_REGION']).to.eql('E N Cen');
|
expect(attributes['SUB_REGION']).to.eql('E N Cen');
|
||||||
|
|||||||
@@ -280,7 +280,7 @@ describe('ol.parser.gml_v3', function() {
|
|||||||
expect(feature.getGeometry() instanceof
|
expect(feature.getGeometry() instanceof
|
||||||
ol.geom.MultiPolygon).to.be.ok();
|
ol.geom.MultiPolygon).to.be.ok();
|
||||||
var attributes = feature.getAttributes();
|
var attributes = feature.getAttributes();
|
||||||
// TODO test for fid
|
expect(feature.getFeatureId()).to.eql('states.1');
|
||||||
expect(attributes['STATE_NAME']).to.eql('Illinois');
|
expect(attributes['STATE_NAME']).to.eql('Illinois');
|
||||||
expect(attributes['STATE_FIPS']).to.eql('17');
|
expect(attributes['STATE_FIPS']).to.eql('17');
|
||||||
expect(attributes['SUB_REGION']).to.eql('E N Cen');
|
expect(attributes['SUB_REGION']).to.eql('E N Cen');
|
||||||
@@ -297,7 +297,7 @@ describe('ol.parser.gml_v3', function() {
|
|||||||
expect(feature.getGeometry() instanceof
|
expect(feature.getGeometry() instanceof
|
||||||
ol.geom.MultiPolygon).to.be.ok();
|
ol.geom.MultiPolygon).to.be.ok();
|
||||||
var attributes = feature.getAttributes();
|
var attributes = feature.getAttributes();
|
||||||
// TODO test for fid
|
expect(feature.getFeatureId()).to.eql('states.1');
|
||||||
expect(attributes['STATE_NAME']).to.eql('Illinois');
|
expect(attributes['STATE_NAME']).to.eql('Illinois');
|
||||||
expect(attributes['STATE_FIPS']).to.eql('17');
|
expect(attributes['STATE_FIPS']).to.eql('17');
|
||||||
expect(attributes['SUB_REGION']).to.eql('E N Cen');
|
expect(attributes['SUB_REGION']).to.eql('E N Cen');
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user