Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Kml features to respect timespan and timestamp of their parent containers #4475

Merged
merged 6 commits into from
Oct 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tfili You have essentially the same block of code copy and pasted 3 times, can you please turn this into a helper function instead.

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