import Cartographic from "../Core/Cartographic.js"; import Color from "../Core/Color.js"; import defined from "../Core/defined.js"; import Cesium3DTileFeature from "./Cesium3DTileFeature.js"; import createBillboardPointCallback from "./createBillboardPointCallback.js"; /** @import Billboard from "./Billboard.js"; */ /** @import Cesium3DTileContent from "./Cesium3DTileContent.js"; */ /** @import Cesium3DTileset from "./Cesium3DTileset.js"; */ /** @import DistanceDisplayCondition from "../Core/DistanceDisplayCondition.js"; */ /** @import HorizontalOrigin from "./HorizontalOrigin.js"; */ /** @import Label from "./Label.js"; */ /** @import NearFarScalar from "../Core/NearFarScalar.js"; */ /** @import Polyline from "./Polyline.js"; */ /** @import VerticalOrigin from "./VerticalOrigin.js"; */ /** @ignore */ const scratchCartographic = new Cartographic(); /** * A point 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 a feature and change its point properties *
*
* Modifications to a Cesium3DTilePointFeature 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.Cesium3DTilePointFeature) { * 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); */ class Cesium3DTilePointFeature { static defaultColor = Color.WHITE; static defaultPointOutlineColor = Color.BLACK; static defaultPointOutlineWidth = 0.0; static defaultPointSize = 8.0; /** * @param {Cesium3DTileContent} content * @param {number} batchId * @param {Billboard} billboard * @param {Label} label * @param {Polyline} polyline */ constructor(content, batchId, billboard, label, polyline) { this._content = content; this._billboard = billboard; this._label = label; this._polyline = polyline; this._batchId = batchId; this._billboardImage = undefined; this._billboardColor = undefined; this._billboardOutlineColor = undefined; this._billboardOutlineWidth = undefined; this._billboardSize = undefined; this._pointSize = undefined; this._color = undefined; this._pointSize = undefined; this._pointOutlineColor = undefined; this._pointOutlineWidth = undefined; this._heightOffset = undefined; this._pickIds = new Array(3); setBillboardImage(this); } /** * Gets or sets if the feature will be shown. This is set for all features * when a style's show is evaluated. * * @type {boolean} * * @default true */ get show() { return this._label.show; } set show(value) { this._label.show = value; this._billboard.show = value; this._polyline.show = value; } /** * Gets or sets the color of the point of this feature. *
* Only applied when image is undefined.
*
* Only applied when image is undefined.
*
* Only applied when image is undefined.
*
* Only applied when image is undefined.
*
* The color will be applied to the label if labelText is defined.
*
* The outline color will be applied to the label if labelText is defined.
*
* The outline width will be applied to the point if labelText is defined.
*
* Only applied when the labelText is defined.
*
* Only applied when labelText is defined.
*
* Only applied when labelText is defined.
*
* Only applied when labelText is defined.
*
* Only applied when labelText is defined.
*
* Only applied when heightOffset is defined.
*
* Only applied when heightOffset is defined.
*
primitive property. This returns
* the tileset containing the feature.
*
* @type {Cesium3DTileset}
*
* @readonly
*/
get primitive() {
return this._content.tileset;
}
/**
* @private
*/
get pickIds() {
const ids = this._pickIds;
ids[0] = this._billboard.pickId;
ids[1] = this._label.pickId;
ids[2] = this._polyline.pickId;
return ids;
}
/**
* 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) {
return this._content.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) {
return this._content.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) {
return this._content.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(
this._content,
this._batchId,
name,
);
}
/**
* 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) { this._content.batchTable.setProperty(this._batchId, name, value); // PERFORMANCE_IDEA: Probably overkill, but maybe only mark the tile dirty if the // property is in one of the style's expressions or - if it can be done quickly - // if the new property value changed the result of an expression. this._content.featurePropertiesDirty = true; } /** * Returns whether the feature's class name equalsclassName. Unlike {@link Cesium3DTilePointFeature#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) {
return this._content.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) {
return this._content.batchTable.isClass(this._batchId, className);
}
/**
* Returns the feature's class name.
*
* This function returns undefined if no batch table hierarchy is present.
*