From a452915d8a5ca85b20004e2201f15b10f9498f07 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Fri, 24 May 2013 09:29:30 +0200 Subject: [PATCH] Store the KML Placemark identifier --- src/ol/parser/kml.js | 7 +++++++ test/spec/ol/parser/kml.test.js | 1 + test/spec/ol/parser/kml/extended_data.kml | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ol/parser/kml.js b/src/ol/parser/kml.js index 1133f75d39..a64c05bb31 100644 --- a/src/ol/parser/kml.js +++ b/src/ol/parser/kml.js @@ -104,6 +104,7 @@ ol.parser.KML = function(opt_options) { 'Placemark': function(node, obj) { var container = {properties: {}}; var sharedVertices, callback; + var id = node.getAttribute('id'); this.readChildNodes(node, container); if (goog.isDef(container.track)) { var track = container.track, j, jj; @@ -125,6 +126,9 @@ ol.parser.KML = function(opt_options) { container.properties['altitude'] = track.points[i].coordinates[2]; } var feature = new ol.Feature(container.properties); + if (!goog.isNull(id)) { + feature.setFeatureId(id); + } var geom = track.points[i]; if (geom) { sharedVertices = undefined; @@ -150,6 +154,9 @@ ol.parser.KML = function(opt_options) { } } feature = new ol.Feature(container.properties); + if (!goog.isNull(id)) { + feature.setFeatureId(id); + } if (container.geometry) { sharedVertices = undefined; if (this.readFeaturesOptions_) { diff --git a/test/spec/ol/parser/kml.test.js b/test/spec/ol/parser/kml.test.js index 0cf36ffec5..ece7ed1fb1 100644 --- a/test/spec/ol/parser/kml.test.js +++ b/test/spec/ol/parser/kml.test.js @@ -86,6 +86,7 @@ describe('ol.parser.kml', function() { 'itself \n at the height of the underlying terrain.'; expect(obj.features[0].get('description')).to.eql(description); expect(obj.features[0].get('foo')).to.eql('bar'); + expect(obj.features[0].getFeatureId()).to.eql('foobarbaz'); }); }); it('Extended data read correctly [2]', function() { diff --git a/test/spec/ol/parser/kml/extended_data.kml b/test/spec/ol/parser/kml/extended_data.kml index fb3a6d38a9..6b4bdd8651 100644 --- a/test/spec/ol/parser/kml/extended_data.kml +++ b/test/spec/ol/parser/kml/extended_data.kml @@ -1,6 +1,6 @@ - + Extended data placemark Attached to the ground. Intelligently places itself at the height of the underlying terrain.