|
| 1 | +let ChangeablePrimitive = (function() { |
| 2 | + function _() { |
| 3 | + } |
| 4 | + |
| 5 | + initialiseOptions = function(options) { |
| 6 | + |
| 7 | + fillOptions(this, options); |
| 8 | + |
| 9 | + this._ellipsoid = undefined; |
| 10 | + this._granularity = undefined; |
| 11 | + this._height = undefined; |
| 12 | + this._textureRotationAngle = undefined; |
| 13 | + this._id = undefined; |
| 14 | + |
| 15 | + // set the flags to initiate a first drawing |
| 16 | + this._createPrimitive = true; |
| 17 | + this._primitive = undefined; |
| 18 | + this._outlinePolygon = undefined; |
| 19 | + |
| 20 | + } |
| 21 | + |
| 22 | + setAttribute = function(name, value) { |
| 23 | + this[name] = value; |
| 24 | + this._createPrimitive = true; |
| 25 | + }; |
| 26 | + |
| 27 | + getAttribute = function(name) { |
| 28 | + return this[name]; |
| 29 | + }; |
| 30 | + |
| 31 | + /** |
| 32 | + * @private |
| 33 | + */ |
| 34 | + update = function(context, frameState, commandList) { |
| 35 | + |
| 36 | + if (!Cesium.defined(this.ellipsoid)) { |
| 37 | + throw new Cesium.DeveloperError('this.ellipsoid must be defined.'); |
| 38 | + } |
| 39 | + |
| 40 | + if (!Cesium.defined(this.appearance)) { |
| 41 | + throw new Cesium.DeveloperError('this.material must be defined.'); |
| 42 | + } |
| 43 | + |
| 44 | + if (this.granularity < 0.0) { |
| 45 | + throw new Cesium.DeveloperError('this.granularity and scene2D/scene3D overrides must be greater than zero.'); |
| 46 | + } |
| 47 | + |
| 48 | + if (!this.show) { |
| 49 | + return; |
| 50 | + } |
| 51 | + |
| 52 | + if (!this._createPrimitive && (!Cesium.defined(this._primitive))) { |
| 53 | + // No positions/hierarchy to draw |
| 54 | + return; |
| 55 | + } |
| 56 | + |
| 57 | + if (this._createPrimitive || |
| 58 | + (this._ellipsoid !== this.ellipsoid) || |
| 59 | + (this._granularity !== this.granularity) || |
| 60 | + (this._height !== this.height) || |
| 61 | + (this._textureRotationAngle !== this.textureRotationAngle) || |
| 62 | + (this._id !== this.id)) { |
| 63 | + |
| 64 | + let geometry = this.getGeometry(); |
| 65 | + if(!geometry) { |
| 66 | + return; |
| 67 | + } |
| 68 | + |
| 69 | + this._createPrimitive = false; |
| 70 | + this._ellipsoid = this.ellipsoid; |
| 71 | + this._granularity = this.granularity; |
| 72 | + this._height = this.height; |
| 73 | + this._textureRotationAngle = this.textureRotationAngle; |
| 74 | + this._id = this.id; |
| 75 | + |
| 76 | + this._primitive = this._primitive && this._primitive.destroy(); |
| 77 | + |
| 78 | + this._primitive = new Cesium.Primitive({ |
| 79 | + geometryInstances : new Cesium.GeometryInstance({ |
| 80 | + geometry : geometry, |
| 81 | + id : this.id, |
| 82 | + pickPrimitive : this |
| 83 | + }), |
| 84 | + appearance : this.appearance, |
| 85 | + asynchronous : this.asynchronous |
| 86 | + }); |
| 87 | + |
| 88 | + this._outlinePolygon = this._outlinePolygon && this._outlinePolygon.destroy(); |
| 89 | + if(this.strokeColor && this.getOutlineGeometry) { |
| 90 | + // create the highlighting frame |
| 91 | + this._outlinePolygon = new Cesium.Primitive({ |
| 92 | + geometryInstances : new Cesium.GeometryInstance({ |
| 93 | + geometry : this.getOutlineGeometry(), |
| 94 | + attributes : { |
| 95 | + color : Cesium.ColorGeometryInstanceAttribute.fromColor(this.strokeColor) |
| 96 | + } |
| 97 | + }), |
| 98 | + appearance : new Cesium.PerInstanceColorAppearance({ |
| 99 | + flat : true, |
| 100 | + renderState : { |
| 101 | + depthTest : { |
| 102 | + enabled : true |
| 103 | + }, |
| 104 | + lineWidth : Math.min(this.strokeWidth || 4.0, context._aliasedLineWidthRange[1]) |
| 105 | + } |
| 106 | + }) |
| 107 | + }); |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + let primitive = this._primitive; |
| 112 | + primitive.appearance.material = this.material; |
| 113 | + primitive.debugShowBoundingVolume = this.debugShowBoundingVolume; |
| 114 | + primitive.update(context, frameState, commandList); |
| 115 | + this._outlinePolygon && this._outlinePolygon.update(context, frameState, commandList); |
| 116 | + |
| 117 | + }; |
| 118 | + |
| 119 | + isDestroyed = function() { |
| 120 | + return false; |
| 121 | + }; |
| 122 | + |
| 123 | + destroy = function() { |
| 124 | + this._primitive = this._primitive && this._primitive.destroy(); |
| 125 | + return Cesium.destroyObject(this); |
| 126 | + }; |
| 127 | + |
| 128 | + setStrokeStyle = function(strokeColor, strokeWidth) { |
| 129 | + if(!this.strokeColor || !this.strokeColor.equals(strokeColor) || this.strokeWidth != strokeWidth) { |
| 130 | + this._createPrimitive = true; |
| 131 | + this.strokeColor = strokeColor; |
| 132 | + this.strokeWidth = strokeWidth; |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + return _; |
| 137 | +})(); |
0 commit comments