Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | 1x 1105x 1104x 1103x 1103x 1x 209x 1x 4x 1x 214x 213x 212x 1x 211x 211x 204x 7x 1x 30x 29x 28x 1x 27x 27x 3x 3x 27x | import Check from "../Core/Check.js";
import clone from "../Core/clone.js";
import defined from "../Core/defined.js";
import DeveloperError from "../Core/DeveloperError.js";
import MetadataEntity from "./MetadataEntity.js";
/**
* A table for storing free-form JSON metadata, as in the 3D Tiles batch table.
*
* @param {object} options Object with the following properties:
* @param {number} options.count The number of entities in the table.
* @param {Object<string, Array>} options.properties The JSON representation of the metadata table. All the arrays must have exactly options.count elements.
*
* @alias JsonMetadataTable
* @constructor
* @private
*/
// An empty class is used because JsonMetadataTable is an older type of metadata table
// that does not have a class definition.
const emptyClass = {};
function JsonMetadataTable(options) {
//>>includeStart('debug', pragmas.debug);
Check.typeOf.number.greaterThan("options.count", options.count, 0);
Check.typeOf.object("options.properties", options.properties);
//>>includeEnd('debug');
this._count = options.count;
this._properties = clone(options.properties, true);
}
/**
* Returns whether the table has this property.
*
* @param {string} propertyId The case-sensitive ID of the property.
* @returns {boolean} Whether the table has this property.
* @private
*/
JsonMetadataTable.prototype.hasProperty = function (propertyId) {
return MetadataEntity.hasProperty(propertyId, this._properties, emptyClass);
};
/**
* Returns an array of property IDs.
*
* @param {string[]} [results] An array into which to store the results.
* @returns {string[]} The property IDs.
* @private
*/
JsonMetadataTable.prototype.getPropertyIds = function (results) {
return MetadataEntity.getPropertyIds(this._properties, emptyClass, results);
};
/**
* Returns a copy of the value of the property with the given ID.
*
* @param {number} index The index of the entity.
* @param {string} propertyId The case-sensitive ID of the property.
* @returns {*} The value of the property or <code>undefined</code> if the entity does not have this property.
*
* @exception {DeveloperError} index is out of bounds
* @private
*/
JsonMetadataTable.prototype.getProperty = function (index, propertyId) {
//>>includeStart('debug', pragmas.debug);
Check.typeOf.number("index", index);
Check.typeOf.string("propertyId", propertyId);
if (index < 0 || index >= this._count) {
throw new DeveloperError(`index must be in the range [0, ${this._count})`);
}
//>>includeEnd('debug');
const property = this._properties[propertyId];
if (defined(property)) {
return clone(property[index], true);
}
return undefined;
};
/**
* Sets the value of the property with the given ID. If the property did not
* exist, it will be created.
*
* @param {number} index The index of the entity.
* @param {string} propertyId The case-sensitive ID of the property.
* @param {*} value The value of the property that will be copied.
*
* @exception {DeveloperError} index is out of bounds
* @private
*/
JsonMetadataTable.prototype.setProperty = function (index, propertyId, value) {
//>>includeStart('debug', pragmas.debug);
Check.typeOf.number("index", index);
Check.typeOf.string("propertyId", propertyId);
if (index < 0 || index >= this._count) {
throw new DeveloperError(`index must be in the range [0, ${this._count})`);
}
//>>includeEnd('debug');
let property = this._properties[propertyId];
if (!defined(property)) {
// Property does not exist. Create it.
property = new Array(this._count);
this._properties[propertyId] = property;
}
property[index] = clone(value, true);
};
export default JsonMetadataTable;
|