Skip to content

Commit 5ccc13e

Browse files
committed
Merge remote-tracking branch 'origin/master' into null-crs
# Conflicts: # CHANGES.md
2 parents 32ecf41 + c384bf8 commit 5ccc13e

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Change Log
1313
* Fixed a bug where creating a custom geometry with attributes and indices that have values that are not a typed array would cause a crash. [#4419](https://github.com/AnalyticalGraphicsInc/cesium/pull/4419)
1414
* Fixed a bug with rotated, textured rectangles. [#4430](https://github.com/AnalyticalGraphicsInc/cesium/pull/4430)
1515
* Fixed a bug when morphing from 2D to 3D. [#4388](https://github.com/AnalyticalGraphicsInc/cesium/pull/4388)
16+
* Fixed a bug where when KML features had duplicate IDs, only one was drawn. [#3941](https://github.com/AnalyticalGraphicsInc/cesium/issues/3941)
1617
* `GeoJsonDataSource` now treats null crs values as a no-op instead of failing to load.
1718
* `GeoJsonDataSource` now gracefully handles missing style icons instead of failing to load.
1819
* Added `Rectangle.simpleIntersection`.

Source/DataSources/KmlDataSource.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,24 @@ define([
285285

286286
// an optional context is passed to allow for some malformed kmls (those with multiple geometries with same ids) to still parse
287287
// correctly, as they do in Google Earth.
288-
function getOrCreateEntity(node, entityCollection, context) {
288+
function createEntity(node, entityCollection, context) {
289289
var id = queryStringAttribute(node, 'id');
290290
id = defined(id) && id.length !== 0 ? id : createGuid();
291291
if(defined(context)){
292292
id = context + id;
293293
}
294-
var entity = entityCollection.getOrCreateEntity(id);
294+
295+
// If we have a duplicate ID just generate one.
296+
// This isn't valid KML but Google Earth handles this case.
297+
var entity = entityCollection.getById(id);
298+
if (defined(entity)) {
299+
id = createGuid();
300+
if(defined(context)){
301+
id = context + id;
302+
}
303+
}
304+
305+
entity = entityCollection.add(new Entity({id : id}));
295306
if (!defined(entity.kml)) {
296307
entity.addProperty('kml');
297308
entity.kml = new KmlFeatureData();
@@ -1358,7 +1369,7 @@ define([
13581369
var childNode = childNodes.item(i);
13591370
var geometryProcessor = geometryTypes[childNode.localName];
13601371
if (defined(geometryProcessor)) {
1361-
var childEntity = getOrCreateEntity(childNode, entityCollection, context);
1372+
var childEntity = createEntity(childNode, entityCollection, context);
13621373
childEntity.parent = entity;
13631374
childEntity.name = entity.name;
13641375
childEntity.availability = entity.availability;
@@ -1514,7 +1525,7 @@ define([
15141525
}
15151526

15161527
function processFeature(dataSource, parent, featureNode, entityCollection, styleCollection, sourceUri, uriResolver) {
1517-
var entity = getOrCreateEntity(featureNode, entityCollection);
1528+
var entity = createEntity(featureNode, entityCollection);
15181529
var kmlData = entity.kml;
15191530
var styleEntity = computeFinalStyle(entity, dataSource, featureNode, styleCollection, sourceUri, uriResolver);
15201531

Specs/DataSources/KmlDataSourceSpec.js

+17
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,23 @@ defineSuite([
406406
});
407407
});
408408

409+
it('Feature: duplicate id', function() {
410+
var kml = '<?xml version="1.0" encoding="UTF-8"?>\
411+
<Document xmlns="http://www.opengis.net/kml/2.2"\
412+
xmlns:gx="http://www.google.com/kml/ext/2.2">\
413+
<Placemark id="Bob">\
414+
</Placemark>\
415+
<Placemark id="Bob">\
416+
</Placemark>\
417+
</Document>';
418+
419+
return KmlDataSource.load(parser.parseFromString(kml, "text/xml"), options).then(function(dataSource) {
420+
var entities = dataSource.entities.values;
421+
expect(entities[0].id).toBe('Bob');
422+
expect(entities[1].id).not.toBe('Bob');
423+
});
424+
});
425+
409426
it('Feature: name', function() {
410427
var kml = '<?xml version="1.0" encoding="UTF-8"?>\
411428
<Placemark>\

0 commit comments

Comments
 (0)