123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666 |
- import BoundingRectangle from "../Core/BoundingRectangle.js";
- import Cartesian2 from "../Core/Cartesian2.js";
- import Cartesian3 from "../Core/Cartesian3.js";
- import Cartesian4 from "../Core/Cartesian4.js";
- import Color from "../Core/Color.js";
- import defaultValue from "../Core/defaultValue.js";
- import defined from "../Core/defined.js";
- import DeveloperError from "../Core/DeveloperError.js";
- import DistanceDisplayCondition from "../Core/DistanceDisplayCondition.js";
- import Matrix4 from "../Core/Matrix4.js";
- import NearFarScalar from "../Core/NearFarScalar.js";
- import SceneMode from "./SceneMode.js";
- import SceneTransforms from "./SceneTransforms.js";
- function PointPrimitive(options, pointPrimitiveCollection) {
- options = defaultValue(options, defaultValue.EMPTY_OBJECT);
-
- if (
- defined(options.disableDepthTestDistance) &&
- options.disableDepthTestDistance < 0.0
- ) {
- throw new DeveloperError(
- "disableDepthTestDistance must be greater than or equal to 0.0."
- );
- }
-
- var translucencyByDistance = options.translucencyByDistance;
- var scaleByDistance = options.scaleByDistance;
- var distanceDisplayCondition = options.distanceDisplayCondition;
- if (defined(translucencyByDistance)) {
-
- if (translucencyByDistance.far <= translucencyByDistance.near) {
- throw new DeveloperError(
- "translucencyByDistance.far must be greater than translucencyByDistance.near."
- );
- }
-
- translucencyByDistance = NearFarScalar.clone(translucencyByDistance);
- }
- if (defined(scaleByDistance)) {
-
- if (scaleByDistance.far <= scaleByDistance.near) {
- throw new DeveloperError(
- "scaleByDistance.far must be greater than scaleByDistance.near."
- );
- }
-
- scaleByDistance = NearFarScalar.clone(scaleByDistance);
- }
- if (defined(distanceDisplayCondition)) {
-
- if (distanceDisplayCondition.far <= distanceDisplayCondition.near) {
- throw new DeveloperError(
- "distanceDisplayCondition.far must be greater than distanceDisplayCondition.near."
- );
- }
-
- distanceDisplayCondition = DistanceDisplayCondition.clone(
- distanceDisplayCondition
- );
- }
- this._show = defaultValue(options.show, true);
- this._position = Cartesian3.clone(
- defaultValue(options.position, Cartesian3.ZERO)
- );
- this._actualPosition = Cartesian3.clone(this._position);
- this._color = Color.clone(defaultValue(options.color, Color.WHITE));
- this._outlineColor = Color.clone(
- defaultValue(options.outlineColor, Color.TRANSPARENT)
- );
- this._outlineWidth = defaultValue(options.outlineWidth, 0.0);
- this._pixelSize = defaultValue(options.pixelSize, 10.0);
- this._scaleByDistance = scaleByDistance;
- this._translucencyByDistance = translucencyByDistance;
- this._distanceDisplayCondition = distanceDisplayCondition;
- this._disableDepthTestDistance = defaultValue(
- options.disableDepthTestDistance,
- 0.0
- );
- this._id = options.id;
- this._collection = defaultValue(options.collection, pointPrimitiveCollection);
- this._clusterShow = true;
- this._pickId = undefined;
- this._pointPrimitiveCollection = pointPrimitiveCollection;
- this._dirty = false;
- this._index = -1;
- }
- var SHOW_INDEX = (PointPrimitive.SHOW_INDEX = 0);
- var POSITION_INDEX = (PointPrimitive.POSITION_INDEX = 1);
- var COLOR_INDEX = (PointPrimitive.COLOR_INDEX = 2);
- var OUTLINE_COLOR_INDEX = (PointPrimitive.OUTLINE_COLOR_INDEX = 3);
- var OUTLINE_WIDTH_INDEX = (PointPrimitive.OUTLINE_WIDTH_INDEX = 4);
- var PIXEL_SIZE_INDEX = (PointPrimitive.PIXEL_SIZE_INDEX = 5);
- var SCALE_BY_DISTANCE_INDEX = (PointPrimitive.SCALE_BY_DISTANCE_INDEX = 6);
- var TRANSLUCENCY_BY_DISTANCE_INDEX = (PointPrimitive.TRANSLUCENCY_BY_DISTANCE_INDEX = 7);
- var DISTANCE_DISPLAY_CONDITION_INDEX = (PointPrimitive.DISTANCE_DISPLAY_CONDITION_INDEX = 8);
- var DISABLE_DEPTH_DISTANCE_INDEX = (PointPrimitive.DISABLE_DEPTH_DISTANCE_INDEX = 9);
- PointPrimitive.NUMBER_OF_PROPERTIES = 10;
- function makeDirty(pointPrimitive, propertyChanged) {
- var pointPrimitiveCollection = pointPrimitive._pointPrimitiveCollection;
- if (defined(pointPrimitiveCollection)) {
- pointPrimitiveCollection._updatePointPrimitive(
- pointPrimitive,
- propertyChanged
- );
- pointPrimitive._dirty = true;
- }
- }
- Object.defineProperties(PointPrimitive.prototype, {
-
- show: {
- get: function () {
- return this._show;
- },
- set: function (value) {
-
- if (!defined(value)) {
- throw new DeveloperError("value is required.");
- }
-
- if (this._show !== value) {
- this._show = value;
- makeDirty(this, SHOW_INDEX);
- }
- },
- },
-
- position: {
- get: function () {
- return this._position;
- },
- set: function (value) {
-
- if (!defined(value)) {
- throw new DeveloperError("value is required.");
- }
-
- var position = this._position;
- if (!Cartesian3.equals(position, value)) {
- Cartesian3.clone(value, position);
- Cartesian3.clone(value, this._actualPosition);
- makeDirty(this, POSITION_INDEX);
- }
- },
- },
-
- scaleByDistance: {
- get: function () {
- return this._scaleByDistance;
- },
- set: function (value) {
-
- if (defined(value) && value.far <= value.near) {
- throw new DeveloperError(
- "far distance must be greater than near distance."
- );
- }
-
- var scaleByDistance = this._scaleByDistance;
- if (!NearFarScalar.equals(scaleByDistance, value)) {
- this._scaleByDistance = NearFarScalar.clone(value, scaleByDistance);
- makeDirty(this, SCALE_BY_DISTANCE_INDEX);
- }
- },
- },
-
- translucencyByDistance: {
- get: function () {
- return this._translucencyByDistance;
- },
- set: function (value) {
-
- if (defined(value) && value.far <= value.near) {
- throw new DeveloperError(
- "far distance must be greater than near distance."
- );
- }
-
- var translucencyByDistance = this._translucencyByDistance;
- if (!NearFarScalar.equals(translucencyByDistance, value)) {
- this._translucencyByDistance = NearFarScalar.clone(
- value,
- translucencyByDistance
- );
- makeDirty(this, TRANSLUCENCY_BY_DISTANCE_INDEX);
- }
- },
- },
-
- pixelSize: {
- get: function () {
- return this._pixelSize;
- },
- set: function (value) {
-
- if (!defined(value)) {
- throw new DeveloperError("value is required.");
- }
-
- if (this._pixelSize !== value) {
- this._pixelSize = value;
- makeDirty(this, PIXEL_SIZE_INDEX);
- }
- },
- },
-
- color: {
- get: function () {
- return this._color;
- },
- set: function (value) {
-
- if (!defined(value)) {
- throw new DeveloperError("value is required.");
- }
-
- var color = this._color;
- if (!Color.equals(color, value)) {
- Color.clone(value, color);
- makeDirty(this, COLOR_INDEX);
- }
- },
- },
-
- outlineColor: {
- get: function () {
- return this._outlineColor;
- },
- set: function (value) {
-
- if (!defined(value)) {
- throw new DeveloperError("value is required.");
- }
-
- var outlineColor = this._outlineColor;
- if (!Color.equals(outlineColor, value)) {
- Color.clone(value, outlineColor);
- makeDirty(this, OUTLINE_COLOR_INDEX);
- }
- },
- },
-
- outlineWidth: {
- get: function () {
- return this._outlineWidth;
- },
- set: function (value) {
-
- if (!defined(value)) {
- throw new DeveloperError("value is required.");
- }
-
- if (this._outlineWidth !== value) {
- this._outlineWidth = value;
- makeDirty(this, OUTLINE_WIDTH_INDEX);
- }
- },
- },
-
- distanceDisplayCondition: {
- get: function () {
- return this._distanceDisplayCondition;
- },
- set: function (value) {
-
- if (defined(value) && value.far <= value.near) {
- throw new DeveloperError("far must be greater than near");
- }
-
- if (
- !DistanceDisplayCondition.equals(this._distanceDisplayCondition, value)
- ) {
- this._distanceDisplayCondition = DistanceDisplayCondition.clone(
- value,
- this._distanceDisplayCondition
- );
- makeDirty(this, DISTANCE_DISPLAY_CONDITION_INDEX);
- }
- },
- },
-
- disableDepthTestDistance: {
- get: function () {
- return this._disableDepthTestDistance;
- },
- set: function (value) {
- if (this._disableDepthTestDistance !== value) {
-
- if (!defined(value) || value < 0.0) {
- throw new DeveloperError(
- "disableDepthTestDistance must be greater than or equal to 0.0."
- );
- }
-
- this._disableDepthTestDistance = value;
- makeDirty(this, DISABLE_DEPTH_DISTANCE_INDEX);
- }
- },
- },
-
- id: {
- get: function () {
- return this._id;
- },
- set: function (value) {
- this._id = value;
- if (defined(this._pickId)) {
- this._pickId.object.id = value;
- }
- },
- },
-
- pickId: {
- get: function () {
- return this._pickId;
- },
- },
-
- clusterShow: {
- get: function () {
- return this._clusterShow;
- },
- set: function (value) {
- if (this._clusterShow !== value) {
- this._clusterShow = value;
- makeDirty(this, SHOW_INDEX);
- }
- },
- },
- });
- PointPrimitive.prototype.getPickId = function (context) {
- if (!defined(this._pickId)) {
- this._pickId = context.createPickId({
- primitive: this,
- collection: this._collection,
- id: this._id,
- });
- }
- return this._pickId;
- };
- PointPrimitive.prototype._getActualPosition = function () {
- return this._actualPosition;
- };
- PointPrimitive.prototype._setActualPosition = function (value) {
- Cartesian3.clone(value, this._actualPosition);
- makeDirty(this, POSITION_INDEX);
- };
- var tempCartesian3 = new Cartesian4();
- PointPrimitive._computeActualPosition = function (
- position,
- frameState,
- modelMatrix
- ) {
- if (frameState.mode === SceneMode.SCENE3D) {
- return position;
- }
- Matrix4.multiplyByPoint(modelMatrix, position, tempCartesian3);
- return SceneTransforms.computeActualWgs84Position(frameState, tempCartesian3);
- };
- var scratchCartesian4 = new Cartesian4();
- PointPrimitive._computeScreenSpacePosition = function (
- modelMatrix,
- position,
- scene,
- result
- ) {
-
- var positionWorld = Matrix4.multiplyByVector(
- modelMatrix,
- Cartesian4.fromElements(
- position.x,
- position.y,
- position.z,
- 1,
- scratchCartesian4
- ),
- scratchCartesian4
- );
- var positionWC = SceneTransforms.wgs84ToWindowCoordinates(
- scene,
- positionWorld,
- result
- );
- return positionWC;
- };
- PointPrimitive.prototype.computeScreenSpacePosition = function (scene, result) {
- var pointPrimitiveCollection = this._pointPrimitiveCollection;
- if (!defined(result)) {
- result = new Cartesian2();
- }
-
- if (!defined(pointPrimitiveCollection)) {
- throw new DeveloperError("PointPrimitive must be in a collection.");
- }
- if (!defined(scene)) {
- throw new DeveloperError("scene is required.");
- }
-
- var modelMatrix = pointPrimitiveCollection.modelMatrix;
- var windowCoordinates = PointPrimitive._computeScreenSpacePosition(
- modelMatrix,
- this._actualPosition,
- scene,
- result
- );
- if (!defined(windowCoordinates)) {
- return undefined;
- }
- windowCoordinates.y = scene.canvas.clientHeight - windowCoordinates.y;
- return windowCoordinates;
- };
- PointPrimitive.getScreenSpaceBoundingBox = function (
- point,
- screenSpacePosition,
- result
- ) {
- var size = point.pixelSize;
- var halfSize = size * 0.5;
- var x = screenSpacePosition.x - halfSize;
- var y = screenSpacePosition.y - halfSize;
- var width = size;
- var height = size;
- if (!defined(result)) {
- result = new BoundingRectangle();
- }
- result.x = x;
- result.y = y;
- result.width = width;
- result.height = height;
- return result;
- };
- PointPrimitive.prototype.equals = function (other) {
- return (
- this === other ||
- (defined(other) &&
- this._id === other._id &&
- Cartesian3.equals(this._position, other._position) &&
- Color.equals(this._color, other._color) &&
- this._pixelSize === other._pixelSize &&
- this._outlineWidth === other._outlineWidth &&
- this._show === other._show &&
- Color.equals(this._outlineColor, other._outlineColor) &&
- NearFarScalar.equals(this._scaleByDistance, other._scaleByDistance) &&
- NearFarScalar.equals(
- this._translucencyByDistance,
- other._translucencyByDistance
- ) &&
- DistanceDisplayCondition.equals(
- this._distanceDisplayCondition,
- other._distanceDisplayCondition
- ) &&
- this._disableDepthTestDistance === other._disableDepthTestDistance)
- );
- };
- PointPrimitive.prototype._destroy = function () {
- this._pickId = this._pickId && this._pickId.destroy();
- this._pointPrimitiveCollection = undefined;
- };
- export default PointPrimitive;
|