import Cartographic from "../Core/Cartographic.js"; import Color from "../Core/Color.js"; import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import Cesium3DTileFeature from "./Cesium3DTileFeature.js"; import createBillboardPointCallback from "./createBillboardPointCallback.js"; /** * 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}. *
* * @alias Cesium3DTilePointFeature * @constructor * * @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); */ function Cesium3DTilePointFeature( 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); } const scratchCartographic = new Cartographic(); Object.defineProperties(Cesium3DTilePointFeature.prototype, { /** * Gets or sets if the feature will be shown. This is set for all features * when a style's show is evaluated. * * @memberof Cesium3DTilePointFeature.prototype * * @type {boolean} * * @default true */ show: { get: function () { return this._label.show; }, set: function (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.
*
* @memberof Cesium3DTilePointFeature.prototype
*
* @type {Cesium3DTileset}
*
* @readonly
*/
primitive: {
get: function () {
return this._content.tileset;
},
},
/**
* @private
*/
pickIds: {
get: function () {
const ids = this._pickIds;
ids[0] = this._billboard.pickId;
ids[1] = this._label.pickId;
ids[2] = this._polyline.pickId;
return ids;
},
},
});
Cesium3DTilePointFeature.defaultColor = Color.WHITE;
Cesium3DTilePointFeature.defaultPointOutlineColor = Color.BLACK;
Cesium3DTilePointFeature.defaultPointOutlineWidth = 0.0;
Cesium3DTilePointFeature.defaultPointSize = 8.0;
function setBillboardImage(feature) {
const b = feature._billboard;
if (defined(feature._billboardImage) && feature._billboardImage !== b.image) {
b.image = feature._billboardImage;
return;
}
if (defined(feature._billboardImage)) {
return;
}
const newColor = defaultValue(
feature._color,
Cesium3DTilePointFeature.defaultColor
);
const newOutlineColor = defaultValue(
feature._pointOutlineColor,
Cesium3DTilePointFeature.defaultPointOutlineColor
);
const newOutlineWidth = defaultValue(
feature._pointOutlineWidth,
Cesium3DTilePointFeature.defaultPointOutlineWidth
);
const newPointSize = defaultValue(
feature._pointSize,
Cesium3DTilePointFeature.defaultPointSize
);
const currentColor = feature._billboardColor;
const currentOutlineColor = feature._billboardOutlineColor;
const currentOutlineWidth = feature._billboardOutlineWidth;
const currentPointSize = feature._billboardSize;
if (
Color.equals(newColor, currentColor) &&
Color.equals(newOutlineColor, currentOutlineColor) &&
newOutlineWidth === currentOutlineWidth &&
newPointSize === currentPointSize
) {
return;
}
feature._billboardColor = Color.clone(newColor, feature._billboardColor);
feature._billboardOutlineColor = Color.clone(
newOutlineColor,
feature._billboardOutlineColor
);
feature._billboardOutlineWidth = newOutlineWidth;
feature._billboardSize = newPointSize;
const centerAlpha = newColor.alpha;
const cssColor = newColor.toCssColorString();
const cssOutlineColor = newOutlineColor.toCssColorString();
const textureId = JSON.stringify([
cssColor,
newPointSize,
cssOutlineColor,
newOutlineWidth,
]);
b.setImage(
textureId,
createBillboardPointCallback(
centerAlpha,
cssColor,
cssOutlineColor,
newOutlineWidth,
newPointSize
)
);
}
/**
* 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.
*/
Cesium3DTilePointFeature.prototype.hasProperty = function (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.
*/
Cesium3DTilePointFeature.prototype.getPropertyIds = function (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)}`);
* }
*/
Cesium3DTilePointFeature.prototype.getProperty = function (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.
*/
Cesium3DTilePointFeature.prototype.getPropertyInherited = function (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'); * } */ Cesium3DTilePointFeature.prototype.setProperty = function (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
*/
Cesium3DTilePointFeature.prototype.isExactClass = function (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
*/
Cesium3DTilePointFeature.prototype.isClass = function (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.
*