123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- import Check from "../Core/Check.js";
- import defaultValue from "../Core/defaultValue.js";
- import defined from "../Core/defined.js";
- import destroyObject from "../Core/destroyObject.js";
- import PrimitiveCollection from "./PrimitiveCollection.js";
- function OrderedGroundPrimitiveCollection() {
- this._length = 0;
- this._collections = {};
- this._collectionsArray = [];
- this.show = true;
- }
- Object.defineProperties(OrderedGroundPrimitiveCollection.prototype, {
-
- length: {
- get: function () {
- return this._length;
- },
- },
- });
- OrderedGroundPrimitiveCollection.prototype.add = function (primitive, zIndex) {
-
- Check.defined("primitive", primitive);
- if (defined(zIndex)) {
- Check.typeOf.number("zIndex", zIndex);
- }
-
- zIndex = defaultValue(zIndex, 0);
- var collection = this._collections[zIndex];
- if (!defined(collection)) {
- collection = new PrimitiveCollection({ destroyPrimitives: false });
- collection._zIndex = zIndex;
- this._collections[zIndex] = collection;
- var array = this._collectionsArray;
- var i = 0;
- while (i < array.length && array[i]._zIndex < zIndex) {
- i++;
- }
- array.splice(i, 0, collection);
- }
- collection.add(primitive);
- this._length++;
- primitive._zIndex = zIndex;
- return primitive;
- };
- OrderedGroundPrimitiveCollection.prototype.set = function (primitive, zIndex) {
-
- Check.defined("primitive", primitive);
- Check.typeOf.number("zIndex", zIndex);
-
- if (zIndex === primitive._zIndex) {
- return primitive;
- }
- this.remove(primitive, true);
- this.add(primitive, zIndex);
- return primitive;
- };
- OrderedGroundPrimitiveCollection.prototype.remove = function (
- primitive,
- doNotDestroy
- ) {
- if (this.contains(primitive)) {
- var index = primitive._zIndex;
- var collection = this._collections[index];
- var result;
- if (doNotDestroy) {
- result = collection.remove(primitive);
- } else {
- result = collection.removeAndDestroy(primitive);
- }
- if (result) {
- this._length--;
- }
- if (collection.length === 0) {
- this._collectionsArray.splice(
- this._collectionsArray.indexOf(collection),
- 1
- );
- this._collections[index] = undefined;
- collection.destroy();
- }
- return result;
- }
- return false;
- };
- OrderedGroundPrimitiveCollection.prototype.removeAll = function () {
- var collections = this._collectionsArray;
- for (var i = 0; i < collections.length; i++) {
- var collection = collections[i];
- collection.destroyPrimitives = true;
- collection.destroy();
- }
- this._collections = {};
- this._collectionsArray = [];
- this._length = 0;
- };
- OrderedGroundPrimitiveCollection.prototype.contains = function (primitive) {
- if (!defined(primitive)) {
- return false;
- }
- var collection = this._collections[primitive._zIndex];
- return defined(collection) && collection.contains(primitive);
- };
- OrderedGroundPrimitiveCollection.prototype.update = function (frameState) {
- if (!this.show) {
- return;
- }
- var collections = this._collectionsArray;
- for (var i = 0; i < collections.length; i++) {
- collections[i].update(frameState);
- }
- };
- OrderedGroundPrimitiveCollection.prototype.isDestroyed = function () {
- return false;
- };
- OrderedGroundPrimitiveCollection.prototype.destroy = function () {
- this.removeAll();
- return destroyObject(this);
- };
- export default OrderedGroundPrimitiveCollection;
|