diff --git a/CHANGES.md b/CHANGES.md index 4fe6de43324d..1d3bcfb647fe 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,11 @@ Change Log ========== +### 1.49 - 2018-09-03 + +##### Additions :tada: +* Added `ClippingPlaneCollection.collectionChanged` event. This event is raised when a `ClippingPlane` is added or removed from the collection [#6875](https://github.com/AnalyticalGraphicsInc/cesium/pull/6875) + ### 1.48 - 2018-08-01 ##### Additions :tada: diff --git a/Source/Scene/ClippingPlaneCollection.js b/Source/Scene/ClippingPlaneCollection.js index bcb7e0e44da3..2f171a98dad3 100644 --- a/Source/Scene/ClippingPlaneCollection.js +++ b/Source/Scene/ClippingPlaneCollection.js @@ -11,6 +11,7 @@ define([ '../Core/deprecationWarning', '../Core/destroyObject', '../Core/DeveloperError', + '../Core/Event', '../Core/Intersect', '../Core/Matrix4', '../Core/PixelFormat', @@ -36,6 +37,7 @@ define([ deprecationWarning, destroyObject, DeveloperError, + Event, Intersect, Matrix4, PixelFormat, @@ -75,15 +77,6 @@ define([ this._dirtyIndex = -1; this._multipleDirtyPlanes = false; - // Add each ClippingPlane object. - var planes = options.planes; - if (defined(planes)) { - var planesLength = planes.length; - for (var i = 0; i < planesLength; ++i) { - this.add(planes[i]); - } - } - this._enabled = defaultValue(options.enabled, true); /** @@ -111,6 +104,22 @@ define([ */ this.edgeWidth = defaultValue(options.edgeWidth, 0.0); + /** + * An event triggered when a new clipping plane is added to the collection. Event handlers + * are passed the new plane and the index at which it was added. + * @type {Event} + * @default Event() + */ + this.planeAdded = new Event(); + + /** + * An event triggered when a new clipping plane is removed from the collection. Event handlers + * are passed the new plane and the index from which it was removed. + * @type {Event} + * @default Event() + */ + this.planeRemoved = new Event(); + // If this ClippingPlaneCollection has an owner, only its owner should update or destroy it. // This is because in a Cesium3DTileset multiple models may reference the tileset's ClippingPlaneCollection. this._owner = undefined; @@ -123,6 +132,15 @@ define([ this._float32View = undefined; this._clippingPlanesTexture = undefined; + + // Add each ClippingPlane object. + var planes = options.planes; + if (defined(planes)) { + var planesLength = planes.length; + for (var i = 0; i < planesLength; ++i) { + this.add(planes[i]); + } + } } function unionIntersectFunction(value) { @@ -263,6 +281,7 @@ define([ setIndexDirty(this, newPlaneIndex); this._planes.push(plane); + this.planeAdded.raiseEvent(plane, newPlaneIndex); }; /** @@ -346,6 +365,8 @@ define([ this._multipleDirtyPlanes = true; planes.length = length; + this.planeRemoved.raiseEvent(clippingPlane, index); + return true; }; @@ -365,6 +386,7 @@ define([ plane.onChangeCallback = undefined; plane.index = -1; } + this.planeRemoved.raiseEvent(plane, i); } this._multipleDirtyPlanes = true; this._planes = []; diff --git a/Specs/Scene/ClippingPlaneCollectionSpec.js b/Specs/Scene/ClippingPlaneCollectionSpec.js index bd6717110818..d7ce0aec959b 100644 --- a/Specs/Scene/ClippingPlaneCollectionSpec.js +++ b/Specs/Scene/ClippingPlaneCollectionSpec.js @@ -95,6 +95,14 @@ defineSuite([ expect(clippingPlanes._planes[0]).toBe(planes[0]); }); + it('fires the planeAdded event when a plane is added', function() { + clippingPlanes = new ClippingPlaneCollection(); + var spy = jasmine.createSpy(); + clippingPlanes.planeAdded.addEventListener(spy); + clippingPlanes.add(planes[0]); + expect(spy).toHaveBeenCalled(); + }); + it('gets the plane at an index', function() { clippingPlanes = new ClippingPlaneCollection({ planes : planes @@ -138,6 +146,43 @@ defineSuite([ expect(result).toBe(false); }); + it('remove fires planeRemoved event', function() { + clippingPlanes = new ClippingPlaneCollection({ + planes : planes + }); + + var spy = jasmine.createSpy(); + clippingPlanes.planeRemoved.addEventListener(spy); + + clippingPlanes.remove(planes[0]); + expect(spy).toHaveBeenCalled(); + }); + + it('removeAll removes all of the planes in the collection', function() { + clippingPlanes = new ClippingPlaneCollection({ + planes : planes + }); + + expect(clippingPlanes.length).toEqual(planes.length); + + clippingPlanes.removeAll(); + + expect(clippingPlanes.length).toBe(0); + }); + + it('removeAll fires planeRemoved event', function() { + clippingPlanes = new ClippingPlaneCollection({ + planes : planes + }); + + var spy = jasmine.createSpy(); + clippingPlanes.planeRemoved.addEventListener(spy); + + clippingPlanes.removeAll(); + + expect(spy).toHaveBeenCalled(); + }); + describe('uint8 texture mode', function() { beforeEach(function() { spyOn(ClippingPlaneCollection, 'useFloatTexture').and.returnValue(false);