Skip to content

Commit 9b98967

Browse files
authored
Merge pull request #7818 from AnalyticalGraphicsInc/czmlDeleteIntervals
Add syntax to to delete data from properties via CZML
2 parents f93dfe8 + 520904a commit 9b98967

File tree

3 files changed

+757
-151
lines changed

3 files changed

+757
-151
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Change Log
44

55
##### Additions :tada:
66
* Added support for new `BingMapsStyle` values `ROAD_ON_DEMAND` and `AERIAL_WITH_LABELS_ON_DEMAND`. The older versions of these, `ROAD` and `AERIAL_WITH_LABELS`, have been deprecated by Bing. [#7808](https://github.com/AnalyticalGraphicsInc/cesium/pull/7808)
7+
* Added syntax to delete data from existing properties via CZML. [#7818](https://github.com/AnalyticalGraphicsInc/cesium/pull/7818)
78
* `BingMapsImageryProvider` now uses `DiscardEmptyTileImagePolicy` by default to detect missing tiles as zero-length responses instead of inspecting pixel values. [#7810](https://github.com/AnalyticalGraphicsInc/cesium/pull/7810)
89

910
### 1.57 - 2019-05-01

Source/DataSources/CzmlDataSource.js

+116-49
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,6 @@ define([
671671
}
672672

673673
var packedLength;
674-
var isSampled;
675674
var unwrappedInterval;
676675
var unwrappedIntervalLength;
677676

@@ -684,18 +683,31 @@ define([
684683
var isValue = !defined(packetData.reference) && !defined(packetData.velocityReference);
685684
var hasInterval = defined(combinedInterval) && !combinedInterval.equals(Iso8601.MAXIMUM_INTERVAL);
686685

686+
if (packetData.delete === true) {
687+
// If deleting this property for all time, we can simply set to undefined and return.
688+
if (!hasInterval) {
689+
object[propertyName] = undefined;
690+
return;
691+
}
692+
693+
// Deleting depends on the type of property we have.
694+
return removePropertyData(object[propertyName], combinedInterval);
695+
}
696+
697+
var isSampled = false;
698+
687699
if (isValue) {
688700
unwrappedInterval = unwrapInterval(type, packetData, sourceUri);
689701
packedLength = defaultValue(type.packedLength, 1);
690702
unwrappedIntervalLength = defaultValue(unwrappedInterval.length, 1);
691703
isSampled = !defined(packetData.array) && (typeof unwrappedInterval !== 'string') && (unwrappedIntervalLength > packedLength) && (type !== Object);
692704
}
693705

694-
//Rotation is a special case because it represents a native type (Number)
695-
//and therefore does not need to be unpacked when loaded as a constant value.
706+
// Rotation is a special case because it represents a native type (Number)
707+
// and therefore does not need to be unpacked when loaded as a constant value.
696708
var needsUnpacking = typeof type.unpack === 'function' && type !== Rotation;
697709

698-
//Any time a constant value is assigned, it completely blows away anything else.
710+
// Any time a constant value is assigned, it completely blows away anything else.
699711
if (!isSampled && !hasInterval) {
700712
if (isValue) {
701713
object[propertyName] = new ConstantProperty(needsUnpacking ? type.unpack(unwrappedInterval, 0) : unwrappedInterval);
@@ -713,8 +725,8 @@ define([
713725
epoch = JulianDate.fromIso8601(packetEpoch);
714726
}
715727

716-
//Without an interval, any sampled value is infinite, meaning it completely
717-
//replaces any non-sampled property that may exist.
728+
// Without an interval, any sampled value is infinite, meaning it completely
729+
// replaces any non-sampled property that may exist.
718730
if (isSampled && !hasInterval) {
719731
if (!(property instanceof SampledProperty)) {
720732
property = new SampledProperty(type);
@@ -727,19 +739,19 @@ define([
727739

728740
var interval;
729741

730-
//A constant value with an interval is normally part of a TimeIntervalCollection,
731-
//However, if the current property is not a time-interval collection, we need
732-
//to turn it into a Composite, preserving the old data with the new interval.
742+
// A constant value with an interval is normally part of a TimeIntervalCollection,
743+
// However, if the current property is not a time-interval collection, we need
744+
// to turn it into a Composite, preserving the old data with the new interval.
733745
if (!isSampled && hasInterval) {
734-
//Create a new interval for the constant value.
746+
// Create a new interval for the constant value.
735747
combinedInterval = combinedInterval.clone();
736748
if (isValue) {
737749
combinedInterval.data = needsUnpacking ? type.unpack(unwrappedInterval, 0) : unwrappedInterval;
738750
} else {
739751
combinedInterval.data = createSpecializedProperty(type, entityCollection, packetData);
740752
}
741753

742-
//If no property exists, simply use a new interval collection
754+
// If no property exists, simply use a new interval collection
743755
if (!defined(property)) {
744756
if (isValue) {
745757
property = new TimeIntervalCollectionProperty();
@@ -750,29 +762,28 @@ define([
750762
}
751763

752764
if (isValue && property instanceof TimeIntervalCollectionProperty) {
753-
//If we create a collection, or it already existed, use it.
765+
// If we create a collection, or it already existed, use it.
754766
property.intervals.addInterval(combinedInterval);
755767
} else if (property instanceof CompositeProperty) {
756-
//If the collection was already a CompositeProperty, use it.
768+
// If the collection was already a CompositeProperty, use it.
757769
if (isValue) {
758770
combinedInterval.data = new ConstantProperty(combinedInterval.data);
759771
}
760772
property.intervals.addInterval(combinedInterval);
761773
} else {
762-
//Otherwise, create a CompositeProperty but preserve the existing data.
763-
764-
//Put the old property in an infinite interval.
774+
// Otherwise, create a CompositeProperty but preserve the existing data.
775+
// Put the old property in an infinite interval.
765776
interval = Iso8601.MAXIMUM_INTERVAL.clone();
766777
interval.data = property;
767778

768-
//Create the composite.
779+
// Create the composite.
769780
property = new CompositeProperty();
770781
object[propertyName] = property;
771782

772-
//add the old property interval
783+
// Add the old property interval.
773784
property.intervals.addInterval(interval);
774785

775-
//Change the new data to a ConstantProperty and add it.
786+
// Change the new data to a ConstantProperty and add it.
776787
if (isValue) {
777788
combinedInterval.data = new ConstantProperty(combinedInterval.data);
778789
}
@@ -788,25 +799,25 @@ define([
788799
object[propertyName] = property;
789800
}
790801

791-
//create a CompositeProperty but preserve the existing data.
802+
// Create a CompositeProperty but preserve the existing data.
792803
if (!(property instanceof CompositeProperty)) {
793-
//Put the old property in an infinite interval.
804+
// Put the old property in an infinite interval.
794805
interval = Iso8601.MAXIMUM_INTERVAL.clone();
795806
interval.data = property;
796807

797-
//Create the composite.
808+
// Create the composite.
798809
property = new CompositeProperty();
799810
object[propertyName] = property;
800811

801-
//add the old property interval
812+
// Add the old property interval.
802813
property.intervals.addInterval(interval);
803814
}
804815

805-
//Check if the interval already exists in the composite
816+
// Check if the interval already exists in the composite.
806817
var intervals = property.intervals;
807818
interval = intervals.findInterval(combinedInterval);
808819
if (!defined(interval) || !(interval.data instanceof SampledProperty)) {
809-
//If not, create a SampledProperty for it.
820+
// If not, create a SampledProperty for it.
810821
interval = combinedInterval.clone();
811822
interval.data = new SampledProperty(type);
812823
intervals.addInterval(interval);
@@ -815,6 +826,28 @@ define([
815826
updateInterpolationSettings(packetData, interval.data);
816827
}
817828

829+
function removePropertyData(property, interval) {
830+
if (property instanceof SampledProperty) {
831+
property.removeSamples(interval);
832+
return;
833+
} else if (property instanceof TimeIntervalCollectionProperty) {
834+
property.intervals.removeInterval(interval);
835+
return;
836+
} else if (property instanceof CompositeProperty) {
837+
var intervals = property.intervals;
838+
for (var i = 0; i < intervals.length; ++i) {
839+
var intersection = TimeInterval.intersect(intervals.get(i), interval, scratchTimeInterval);
840+
if (!intersection.isEmpty) {
841+
// remove data from the contained properties
842+
removePropertyData(intersection.data, interval);
843+
}
844+
}
845+
// remove the intervals from the composite
846+
intervals.removeInterval(interval);
847+
return;
848+
}
849+
}
850+
818851
function processPacketData(type, object, propertyName, packetData, interval, sourceUri, entityCollection) {
819852
if (!defined(packetData)) {
820853
return;
@@ -842,15 +875,27 @@ define([
842875
combinedInterval = constrainedInterval;
843876
}
844877

845-
var referenceFrame;
846-
var unwrappedInterval;
847-
var isSampled = false;
848-
var unwrappedIntervalLength;
849878
var numberOfDerivatives = defined(packetData.cartesianVelocity) ? 1 : 0;
850879
var packedLength = Cartesian3.packedLength * (numberOfDerivatives + 1);
880+
var unwrappedInterval;
881+
var unwrappedIntervalLength;
851882
var isValue = !defined(packetData.reference);
852883
var hasInterval = defined(combinedInterval) && !combinedInterval.equals(Iso8601.MAXIMUM_INTERVAL);
853884

885+
if (packetData.delete === true) {
886+
// If deleting this property for all time, we can simply set to undefined and return.
887+
if (!hasInterval) {
888+
object[propertyName] = undefined;
889+
return;
890+
}
891+
892+
// Deleting depends on the type of property we have.
893+
return removePositionPropertyData(object[propertyName], combinedInterval);
894+
}
895+
896+
var referenceFrame;
897+
var isSampled = false;
898+
854899
if (isValue) {
855900
if (defined(packetData.referenceFrame)) {
856901
referenceFrame = ReferenceFrame[packetData.referenceFrame];
@@ -861,7 +906,7 @@ define([
861906
isSampled = unwrappedIntervalLength > packedLength;
862907
}
863908

864-
//Any time a constant value is assigned, it completely blows away anything else.
909+
// Any time a constant value is assigned, it completely blows away anything else.
865910
if (!isSampled && !hasInterval) {
866911
if (isValue) {
867912
object[propertyName] = new ConstantPositionProperty(Cartesian3.unpack(unwrappedInterval), referenceFrame);
@@ -879,8 +924,8 @@ define([
879924
epoch = JulianDate.fromIso8601(packetEpoch);
880925
}
881926

882-
//Without an interval, any sampled value is infinite, meaning it completely
883-
//replaces any non-sampled property that may exist.
927+
// Without an interval, any sampled value is infinite, meaning it completely
928+
// replaces any non-sampled property that may exist.
884929
if (isSampled && !hasInterval) {
885930
if (!(property instanceof SampledPositionProperty) || (defined(referenceFrame) && property.referenceFrame !== referenceFrame)) {
886931
property = new SampledPositionProperty(referenceFrame, numberOfDerivatives);
@@ -893,19 +938,19 @@ define([
893938

894939
var interval;
895940

896-
//A constant value with an interval is normally part of a TimeIntervalCollection,
897-
//However, if the current property is not a time-interval collection, we need
898-
//to turn it into a Composite, preserving the old data with the new interval.
941+
// A constant value with an interval is normally part of a TimeIntervalCollection,
942+
// However, if the current property is not a time-interval collection, we need
943+
// to turn it into a Composite, preserving the old data with the new interval.
899944
if (!isSampled && hasInterval) {
900-
//Create a new interval for the constant value.
945+
// Create a new interval for the constant value.
901946
combinedInterval = combinedInterval.clone();
902947
if (isValue) {
903948
combinedInterval.data = Cartesian3.unpack(unwrappedInterval);
904949
} else {
905950
combinedInterval.data = createReferenceProperty(entityCollection, packetData.reference);
906951
}
907952

908-
//If no property exists, simply use a new interval collection
953+
// If no property exists, simply use a new interval collection
909954
if (!defined(property)) {
910955
if (isValue) {
911956
property = new TimeIntervalCollectionPositionProperty(referenceFrame);
@@ -916,29 +961,29 @@ define([
916961
}
917962

918963
if (isValue && property instanceof TimeIntervalCollectionPositionProperty && (defined(referenceFrame) && property.referenceFrame === referenceFrame)) {
919-
//If we create a collection, or it already existed, use it.
964+
// If we create a collection, or it already existed, use it.
920965
property.intervals.addInterval(combinedInterval);
921966
} else if (property instanceof CompositePositionProperty) {
922-
//If the collection was already a CompositePositionProperty, use it.
967+
// If the collection was already a CompositePositionProperty, use it.
923968
if (isValue) {
924969
combinedInterval.data = new ConstantPositionProperty(combinedInterval.data, referenceFrame);
925970
}
926971
property.intervals.addInterval(combinedInterval);
927972
} else {
928-
//Otherwise, create a CompositePositionProperty but preserve the existing data.
973+
// Otherwise, create a CompositePositionProperty but preserve the existing data.
929974

930-
//Put the old property in an infinite interval.
975+
// Put the old property in an infinite interval.
931976
interval = Iso8601.MAXIMUM_INTERVAL.clone();
932977
interval.data = property;
933978

934-
//Create the composite.
979+
// Create the composite.
935980
property = new CompositePositionProperty(property.referenceFrame);
936981
object[propertyName] = property;
937982

938-
//add the old property interval
983+
// Add the old property interval.
939984
property.intervals.addInterval(interval);
940985

941-
//Change the new data to a ConstantPositionProperty and add it.
986+
// Change the new data to a ConstantPositionProperty and add it.
942987
if (isValue) {
943988
combinedInterval.data = new ConstantPositionProperty(combinedInterval.data, referenceFrame);
944989
}
@@ -953,20 +998,20 @@ define([
953998
property = new CompositePositionProperty(referenceFrame);
954999
object[propertyName] = property;
9551000
} else if (!(property instanceof CompositePositionProperty)) {
956-
//create a CompositeProperty but preserve the existing data.
957-
//Put the old property in an infinite interval.
1001+
// Create a CompositeProperty but preserve the existing data.
1002+
// Put the old property in an infinite interval.
9581003
interval = Iso8601.MAXIMUM_INTERVAL.clone();
9591004
interval.data = property;
9601005

961-
//Create the composite.
1006+
// Create the composite.
9621007
property = new CompositePositionProperty(property.referenceFrame);
9631008
object[propertyName] = property;
9641009

965-
//add the old property interval
1010+
// Add the old property interval.
9661011
property.intervals.addInterval(interval);
9671012
}
9681013

969-
//Check if the interval already exists in the composite
1014+
//Check if the interval already exists in the composite.
9701015
var intervals = property.intervals;
9711016
interval = intervals.findInterval(combinedInterval);
9721017
if (!defined(interval) || !(interval.data instanceof SampledPositionProperty) || (defined(referenceFrame) && interval.data.referenceFrame !== referenceFrame)) {
@@ -979,6 +1024,28 @@ define([
9791024
updateInterpolationSettings(packetData, interval.data);
9801025
}
9811026

1027+
function removePositionPropertyData(property, interval) {
1028+
if (property instanceof SampledPositionProperty) {
1029+
property.removeSamples(interval);
1030+
return;
1031+
} else if (property instanceof TimeIntervalCollectionPositionProperty) {
1032+
property.intervals.removeInterval(interval);
1033+
return;
1034+
} else if (property instanceof CompositePositionProperty) {
1035+
var intervals = property.intervals;
1036+
for (var i = 0; i < intervals.length; ++i) {
1037+
var intersection = TimeInterval.intersect(intervals.get(i), interval, scratchTimeInterval);
1038+
if (!intersection.isEmpty) {
1039+
// remove data from the contained properties
1040+
removePositionPropertyData(intersection.data, interval);
1041+
}
1042+
}
1043+
// remove the intervals from the composite
1044+
intervals.removeInterval(interval);
1045+
return;
1046+
}
1047+
}
1048+
9821049
function processPositionPacketData(object, propertyName, packetData, interval, sourceUri, entityCollection) {
9831050
if (!defined(packetData)) {
9841051
return;

0 commit comments

Comments
 (0)