Skip to content

Commit

Permalink
Merge pull request #4475 from AnalyticalGraphicsInc/kml-network-link-…
Browse files Browse the repository at this point in the history
…timespan

Fixed Kml features to respect timespan and timestamp of their parent containers
  • Loading branch information
Hannah authored Oct 20, 2016
2 parents f9ddb9d + b5e5610 commit b0754dc
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Change Log
* Fixed a bug with rotated, textured rectangles. [#4430](https://github.com/AnalyticalGraphicsInc/cesium/pull/4430)
* Fixed a bug when morphing from 2D to 3D. [#4388](https://github.com/AnalyticalGraphicsInc/cesium/pull/4388)
* Fixed a bug where when KML features had duplicate IDs, only one was drawn. [#3941](https://github.com/AnalyticalGraphicsInc/cesium/issues/3941)
* Fixed `KmlDataSource` features to respect `timespan` and `timestamp` properties of it's parents (eg. Folders or NetworkLinks).
* `GeoJsonDataSource` now treats null crs values as a no-op instead of failing to load.
* `GeoJsonDataSource` now gracefully handles missing style icons instead of failing to load.
* Improve `Geocoder` usability by selecting text on click [#4464](https://github.com/AnalyticalGraphicsInc/cesium/pull/4464)
Expand Down
31 changes: 31 additions & 0 deletions Source/DataSources/KmlDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,17 @@ define([
}
entity.availability = availability;

if (defined(parent)) {
var parentAvailability = parent.availability;
if (defined(parentAvailability)) {
if (defined(availability)) {
availability.intersect(parentAvailability);
} else {
entity.availability = parentAvailability;
}
}
}

// Per KML spec "A Feature is visible only if it and all its ancestors are visible."
function ancestryIsVisible(parentEntity) {
if (!parentEntity) {
Expand Down Expand Up @@ -1934,11 +1945,21 @@ define([
var promise = when(load(dataSource, networkLinkCollection, linkUrl), function(rootElement) {
var entities = dataSource._entityCollection;
var newEntities = networkLinkCollection.values;
var networkLinkAvailability = networkEntity.availability;
entities.suspendEvents();
for (var i = 0; i < newEntities.length; i++) {
var newEntity = newEntities[i];
if (!defined(newEntity.parent)) {
newEntity.parent = networkEntity;

if (defined(networkLinkAvailability)) {
var childAvailability = newEntity.availability;
if (defined(childAvailability)) {
childAvailability.intersect(networkLinkAvailability);
} else {
newEntity.availability = networkLinkAvailability;
}
}
}
entities.add(newEntity);
}
Expand Down Expand Up @@ -2545,6 +2566,7 @@ define([
}

var networkLinkEntity = networkLink.entity;
var networkLinkAvailability = networkLinkEntity.availability;
var entityCollection = dataSource._entityCollection;
var newEntities = newEntityCollection.values;

Expand Down Expand Up @@ -2575,6 +2597,15 @@ define([
var newEntity = newEntities[i];
if (!defined(newEntity.parent)) {
newEntity.parent = networkLinkEntity;

if (defined(networkLinkAvailability)) {
var childAvailability = newEntity.availability;
if (defined(childAvailability)) {
childAvailability.intersect(networkLinkAvailability);
} else {
newEntity.availability = networkLinkAvailability;
}
}
}
entityCollection.add(newEntity);
}
Expand Down
162 changes: 162 additions & 0 deletions Specs/DataSources/KmlDataSourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2144,6 +2144,118 @@ defineSuite([
});
});

it('Folder: timespan for folder', function() {
var kml = '<?xml version="1.0" encoding="UTF-8"?>\
<Folder>\
<Placemark id="child">\
</Placemark>\
<TimeSpan>\
<begin>2000-01-01</begin>\
<end>2000-01-03</end>\
</TimeSpan>\
</Folder>';

return KmlDataSource.load(parser.parseFromString(kml, "text/xml"), options).then(function(dataSource) {
var start = JulianDate.fromIso8601('2000-01-01');
var stop = JulianDate.fromIso8601('2000-01-03');

var entities = dataSource.entities.values;
expect(entities.length).toBe(2);
var interval = entities[0].availability;
expect(interval.start).toEqual(start);
expect(interval.stop).toEqual(stop);

expect(entities[0].availability).toEqual(entities[1].availability);
});
});

it('Folder: timespan for folder and feature', function() {
var kml = '<?xml version="1.0" encoding="UTF-8"?>\
<Folder>\
<Placemark id="child">\
<TimeSpan>\
<begin>2000-01-02</begin>\
<end>2000-01-03</end>\
</TimeSpan>\
</Placemark>\
<TimeSpan>\
<begin>2000-01-01</begin>\
<end>2000-01-04</end>\
</TimeSpan>\
</Folder>';

return KmlDataSource.load(parser.parseFromString(kml, "text/xml"), options).then(function(dataSource) {
var startFolder = JulianDate.fromIso8601('2000-01-01');
var stopFolder = JulianDate.fromIso8601('2000-01-04');
var startFeature = JulianDate.fromIso8601('2000-01-02');
var stopFeature = JulianDate.fromIso8601('2000-01-03');

var entities = dataSource.entities.values;
expect(entities.length).toBe(2);
var interval = entities[0].availability;
expect(interval.start).toEqual(startFolder);
expect(interval.stop).toEqual(stopFolder);

interval = entities[1].availability;
expect(interval.start).toEqual(startFeature);
expect(interval.stop).toEqual(stopFeature);
});
});

it('Folder: timestamp for folder', function() {
var kml = '<?xml version="1.0" encoding="UTF-8"?>\
<Folder>\
<Placemark id="child">\
</Placemark>\
<TimeStamp>\
<when>2000-01-03</when>\
</TimeStamp>\
</Folder>';

return KmlDataSource.load(parser.parseFromString(kml, "text/xml"), options).then(function(dataSource) {
var start = JulianDate.fromIso8601('2000-01-03');

var entities = dataSource.entities.values;
expect(entities.length).toBe(2);
var interval = entities[0].availability;
expect(interval.start).toEqual(start);
expect(interval.stop).toEqual(Iso8601.MAXIMUM_VALUE);

expect(entities[0].availability).toEqual(entities[1].availability);
});
});

it('Folder: timestamp for folder and feature', function() {
var kml = '<?xml version="1.0" encoding="UTF-8"?>\
<Folder>\
<Placemark id="child">\
<TimeSpan>\
<begin>2000-01-04</begin>\
<end>2000-01-05</end>\
</TimeSpan>\
</Placemark>\
<TimeStamp>\
<when>2000-01-03</when>\
</TimeStamp>\
</Folder>';

return KmlDataSource.load(parser.parseFromString(kml, "text/xml"), options).then(function(dataSource) {
var startFolder = JulianDate.fromIso8601('2000-01-03');
var startFeature = JulianDate.fromIso8601('2000-01-04');
var stopFeature = JulianDate.fromIso8601('2000-01-05');

var entities = dataSource.entities.values;
expect(entities.length).toBe(2);
var interval = entities[0].availability;
expect(interval.start).toEqual(startFolder);
expect(interval.stop).toEqual(Iso8601.MAXIMUM_VALUE);

interval = entities[1].availability;
expect(interval.start).toEqual(startFeature);
expect(interval.stop).toEqual(stopFeature);
});
});

it('Geometry Point: handles empty Point', function() {
var kml = '<?xml version="1.0" encoding="UTF-8"?>\
<Placemark>\
Expand Down Expand Up @@ -3434,6 +3546,56 @@ defineSuite([
});
});

it('NetworkLink: timespan for network link', function() {
var kml = '<?xml version="1.0" encoding="UTF-8"?>\
<NetworkLink id="link">\
<Link>\
<href>./Data/KML/simple.kml</href>\
</Link>\
<TimeSpan>\
<begin>2000-01-01</begin>\
<end>2000-01-03</end>\
</TimeSpan>\
</NetworkLink>';

return KmlDataSource.load(parser.parseFromString(kml, "text/xml"), options).then(function(dataSource) {
var start = JulianDate.fromIso8601('2000-01-01');
var stop = JulianDate.fromIso8601('2000-01-03');

var entities = dataSource.entities.values;
expect(entities.length).toBe(2);
var interval = entities[0].availability;
expect(interval.start).toEqual(start);
expect(interval.stop).toEqual(stop);

expect(entities[0].availability).toEqual(entities[1].availability);
});
});

it('NetworkLink: timestamp for network link', function() {
var kml = '<?xml version="1.0" encoding="UTF-8"?>\
<NetworkLink id="link">\
<Link>\
<href>./Data/KML/simple.kml</href>\
</Link>\
<TimeStamp>\
<when>2000-01-03</when>\
</TimeStamp>\
</NetworkLink>';

return KmlDataSource.load(parser.parseFromString(kml, "text/xml"), options).then(function(dataSource) {
var start = JulianDate.fromIso8601('2000-01-03');

var entities = dataSource.entities.values;
expect(entities.length).toBe(2);
var interval = entities[0].availability;
expect(interval.start).toEqual(start);
expect(interval.stop).toEqual(Iso8601.MAXIMUM_VALUE);

expect(entities[0].availability).toEqual(entities[1].availability);
});
});

it('can load a KML file with explicit namespaces', function() {
return KmlDataSource.load('Data/KML/namespaced.kml', options).then(function(dataSource) {
expect(dataSource.entities.values.length).toBe(3);
Expand Down

0 comments on commit b0754dc

Please sign in to comment.