Merge pull request #2 from fredj/fid

Store the KML Placemark identifier
This commit is contained in:
ahocevar
2013-05-24 06:14:29 -07:00
3 changed files with 9 additions and 1 deletions

View File

@@ -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_) {

View File

@@ -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() {

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
<Placemark>
<Placemark id="foobarbaz">
<name>Extended data placemark</name>
<description>Attached to the ground. Intelligently places itself
at the height of the underlying terrain.</description>