| class Circle extends Overlay { | class Circle extends Overlay { | ||||
| constructor(center, radius) { | constructor(center, radius) { | ||||
| super() | super() | ||||
| this._delegate = new Cesium.Entity({ ellipse: {} }) | |||||
| this._delegate = new Cesium.Entity({ polygon: {} }) | |||||
| this._center = Parse.parsePosition(center) | this._center = Parse.parsePosition(center) | ||||
| this._radius = +radius || 0 | this._radius = +radius || 0 | ||||
| this._rotateAmount = 0 | this._rotateAmount = 0 | ||||
| set center(center) { | set center(center) { | ||||
| this._center = Parse.parsePosition(center) | this._center = Parse.parsePosition(center) | ||||
| this._delegate.position = Transform.transformWGS84ToCartesian(this._center) | |||||
| this._delegate.polygon.hierarchy = this._computeHierarchy() | |||||
| return this | return this | ||||
| } | } | ||||
| set radius(radius) { | set radius(radius) { | ||||
| this._radius = +radius | this._radius = +radius | ||||
| this._delegate.ellipse.semiMajorAxis = this._radius | |||||
| this._delegate.ellipse.semiMinorAxis = this._radius | |||||
| this._delegate.polygon.hierarchy = this._computeHierarchy() | |||||
| return this | return this | ||||
| } | } | ||||
| set rotateAmount(amount) { | set rotateAmount(amount) { | ||||
| this._rotateAmount = +amount | this._rotateAmount = +amount | ||||
| this._delegate.ellipse.stRotation = new Cesium.CallbackProperty(() => { | |||||
| this._delegate.polygon.stRotation = new Cesium.CallbackProperty(() => { | |||||
| this._stRotation += this._rotateAmount | this._stRotation += this._rotateAmount | ||||
| if (this._stRotation >= 360 || this._stRotation <= -360) { | if (this._stRotation >= 360 || this._stRotation <= -360) { | ||||
| this._stRotation = 0 | this._stRotation = 0 | ||||
| } | } | ||||
| return Cesium.Math.toRadians(this._stRotation) | return Cesium.Math.toRadians(this._stRotation) | ||||
| }, false) | |||||
| }) | |||||
| return this | return this | ||||
| } | } | ||||
| return this._rotateAmount | return this._rotateAmount | ||||
| } | } | ||||
| /** | |||||
| * | |||||
| * @private | |||||
| */ | |||||
| _computeHierarchy() { | |||||
| let result = new Cesium.PolygonHierarchy() | |||||
| let cep = Cesium.EllipseGeometryLibrary.computeEllipsePositions( | |||||
| { | |||||
| center: Transform.transformWGS84ToCartesian(this._center), | |||||
| semiMajorAxis: this._radius, | |||||
| semiMinorAxis: this._radius, | |||||
| rotation: 0, | |||||
| granularity: 0.005 | |||||
| }, | |||||
| false, | |||||
| true | |||||
| ) | |||||
| let pnts = Cesium.Cartesian3.unpackArray(cep.outerPositions) | |||||
| pnts.push(pnts[0]) | |||||
| result.positions = pnts | |||||
| return result | |||||
| } | |||||
| _mountedHook() { | _mountedHook() { | ||||
| /** | /** | ||||
| * set the location | * set the location | ||||
| */ | */ | ||||
| this.center = this._center | this.center = this._center | ||||
| this.radius = this._radius | |||||
| } | } | ||||
| /** | /** | ||||
| * @returns {Circle} | * @returns {Circle} | ||||
| */ | */ | ||||
| setLabel(text, textStyle) { | setLabel(text, textStyle) { | ||||
| this._delegate.position = Transform.transformWGS84ToCartesian(this._center) | |||||
| this._delegate.label = { | this._delegate.label = { | ||||
| ...textStyle, | ...textStyle, | ||||
| text: text | text: text | ||||
| if (!style || Object.keys(style).length === 0) { | if (!style || Object.keys(style).length === 0) { | ||||
| return this | return this | ||||
| } | } | ||||
| delete style['position'] && | |||||
| delete style['semiMajorAxis'] && | |||||
| delete style['semiMinorAxis'] | |||||
| delete style['positions'] | |||||
| Util.merge(this._style, style) | Util.merge(this._style, style) | ||||
| Util.merge(this._delegate.ellipse, style) | |||||
| Util.merge(this._delegate.polygon, style) | |||||
| return this | return this | ||||
| } | } | ||||
| } | } |