// @ts-check import DeveloperError from "../Core/DeveloperError.js"; import BufferPoint from "./BufferPoint.js"; import BufferPointCollection from "./BufferPointCollection.js"; import BufferPointMaterial from "./BufferPointMaterial.js"; import BufferPolygon from "./BufferPolygon.js"; import BufferPolygonCollection from "./BufferPolygonCollection.js"; import BufferPolygonMaterial from "./BufferPolygonMaterial.js"; import BufferPolyline from "./BufferPolyline.js"; import BufferPolylineCollection from "./BufferPolylineCollection.js"; import BufferPolylineMaterial from "./BufferPolylineMaterial.js"; import Cesium3DTileFeature from "./Cesium3DTileFeature.js"; import Color from "../Core/Color.js"; import defined from "../Core/defined.js"; /** @import BufferPrimitive from "./BufferPrimitive.js"; */ /** @import BufferPrimitiveMaterial from "./BufferPrimitiveMaterial.js"; */ /** @import Cesium3DTileBatchTable from "./Cesium3DTileBatchTable.js"; */ /** @import Cesium3DTileContent from "./Cesium3DTileContent.js"; */ /** @import Cesium3DTileset from "./Cesium3DTileset.js"; */ /** @import VectorGltf3DTileContent from "./VectorGltf3DTileContent.js"; */ const point = new BufferPoint(); const polyline = new BufferPolyline(); const polygon = new BufferPolygon(); const pointMaterial = new BufferPointMaterial(); const polylineMaterial = new BufferPolylineMaterial(); const polygonMaterial = new BufferPolygonMaterial(); /** * A vector feature of a {@link Cesium3DTileset}. *
* Provides access to a feature's properties stored in the tile's batch table, as well * as the ability to show/hide and style the feature *
*
* Modifications to a Cesium3DTileVectorFeature object have the lifetime of the tile's
* content. If the tile's content is unloaded, e.g., due to it going out of view and needing
* to free space in the cache for visible tiles, listen to the {@link Cesium3DTileset#tileUnload} event to save any
* modifications. Also listen to the {@link Cesium3DTileset#tileVisible} event to reapply any modifications.
*
* Do not construct this directly. Access it through {@link Cesium3DTileContent#getFeature} * or picking using {@link Scene#pick} and {@link Scene#pickPosition}. *
* * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. * * @example * // On mouse over, display all the properties for a feature in the console log. * handler.setInputAction(function(movement) { * const feature = scene.pick(movement.endPosition); * if (feature instanceof Cesium.Cesium3DTileVectorFeature) { * const propertyIds = feature.getPropertyIds(); * const length = propertyIds.length; * for (let i = 0; i < length; ++i) { * const propertyId = propertyIds[i]; * console.log(`{propertyId}: ${feature.getProperty(propertyId)}`); * } * } * }, Cesium.ScreenSpaceEventType.MOUSE_MOVE); * * @ignore */ class Cesium3DTileVectorFeature { /** @private */ _color = new Color(); /** @private */ _outlineColor = new Color(); /** * @param {VectorGltf3DTileContent} content * @param {number} batchId * @param {number} [batchTableId=0] */ constructor(content, batchId, batchTableId = 0) { this._content = content; this._batchId = batchId; this._batchTableId = batchTableId; /** * For each collection index N, this map returns the indices of all * primitive in the collection associated with this feature. * @type {Mapprimitive property. This returns
* the tileset containing the feature.
*
* @type {Cesium3DTileset}
*/
get primitive() {
return this._content.tileset;
}
/**
* Get the feature ID associated with this feature. Using EXT_mesh_features,
* this is the feature ID from the selected feature ID set.
*
* @type {number}
*
* @readonly
*/
get featureId() {
return this._batchId;
}
/**
* @type {Cesium3DTileBatchTable|undefined}
* @private
*/
get _batchTable() {
return this._content.batchTables[this._batchTableId];
}
/**
* @type {number[]}
* @ignore
*/
get pickIds() {
const pickIds = [];
for (const prim of this._iteratePrimitives()) {
pickIds.push(prim._pickId);
}
return pickIds;
}
/**
* Returns whether the feature contains this property. This includes properties from this feature's
* class and inherited classes when using a batch table hierarchy.
*
* @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_batch_table_hierarchy}
*
* @param {string} name The case-sensitive name of the property.
* @returns {boolean} Whether the feature contains this property.
*/
hasProperty(name) {
if (!defined(this._batchTable)) {
return false;
}
return this._batchTable.hasProperty(this._batchId, name);
}
/**
* Returns an array of property IDs for the feature. This includes properties from this feature's
* class and inherited classes when using a batch table hierarchy.
*
* @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_batch_table_hierarchy}
*
* @param {string[]} [results] An array into which to store the results.
* @returns {string[]} The IDs of the feature's properties.
*/
getPropertyIds(results) {
if (!defined(this._batchTable)) {
return [];
}
return this._batchTable.getPropertyIds(this._batchId, results);
}
/**
* Returns a copy of the value of the feature's property with the given name. This includes properties from this feature's
* class and inherited classes when using a batch table hierarchy.
*
* @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_batch_table_hierarchy}
*
* @param {string} name The case-sensitive name of the property.
* @returns {*} The value of the property or undefined if the feature does not have this property.
*
* @example
* // Display all the properties for a feature in the console log.
* const propertyIds = feature.getPropertyIds();
* const length = propertyIds.length;
* for (let i = 0; i < length; ++i) {
* const propertyId = propertyIds[i];
* console.log(`{propertyId} : ${feature.getProperty(propertyId)}`);
* }
*/
getProperty(name) {
if (!defined(this._batchTable)) {
return undefined;
}
return this._batchTable.getProperty(this._batchId, name);
}
/**
* Returns a copy of the value of the feature's property with the given name.
* If the feature is contained within a tileset that has metadata (3D Tiles 1.1)
* or uses the 3DTILES_metadata extension, tileset, group and tile metadata is
* inherited.
* * To resolve name conflicts, this method resolves names from most specific to * least specific by metadata granularity in the order: feature, tile, group, * tileset. Within each granularity, semantics are resolved first, then other * properties. *
* @param {string} name The case-sensitive name of the property. * @returns {*} The value of the property orundefined if the feature does not have this property.
* @private
* @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
*/
getPropertyInherited(name) {
return Cesium3DTileFeature.getPropertyInherited(
// @ts-expect-error Requires type checking in Cesium3DTileContent.
this._content,
this._batchId,
name,
this._batchTable,
);
}
/**
* Sets the value of the feature's property with the given name.
* * If a property with the given name doesn't exist, it is created. *
* * @param {string} name The case-sensitive name of the property. * @param {*} value The value of the property that will be copied. * * @exception {DeveloperError} Inherited batch table hierarchy property is read only. * * @example * const height = feature.getProperty('Height'); // e.g., the height of a building * * @example * const name = 'clicked'; * if (feature.getProperty(name)) { * console.log('already clicked'); * } else { * feature.setProperty(name, true); * console.log('first click'); * } */ setProperty(name, value) { throw new DeveloperError("Not implemented"); } /** * Returns whether the feature's class name equalsclassName. Unlike {@link Cesium3DTileVectorFeature#isClass}
* this function only checks the feature's exact class and not inherited classes.
*
* This function returns false if no batch table hierarchy is present.
*
className
*
* @private
*/
isExactClass(className) {
if (!defined(this._batchTable)) {
return false;
}
return this._batchTable.isExactClass(this._batchId, className);
}
/**
* Returns whether the feature's class or any inherited classes are named className.
*
* This function returns false if no batch table hierarchy is present.
*
className
*
* @private
*/
isClass(className) {
if (!defined(this._batchTable)) {
return false;
}
return this._batchTable.isClass(this._batchId, className);
}
/**
* Returns the feature's class name.
*
* This function returns undefined if no batch table hierarchy is present.
*