Skip to content

Commit

Permalink
improve the overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
cavencj committed May 8, 2022
1 parent 11a5a09 commit f5e3e46
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 32 deletions.
2 changes: 1 addition & 1 deletion modules/overlay/model/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Model extends Overlay {
Cesium.Math.toRadians(this._position.roll)
)
)
})
}, false)
return this
}

Expand Down
42 changes: 11 additions & 31 deletions modules/overlay/vector/Circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Overlay from '../Overlay'
class Circle extends Overlay {
constructor(center, radius) {
super()
this._delegate = new Cesium.Entity({ polygon: {} })
this._delegate = new Cesium.Entity({ ellipse: {} })
this._center = Parse.parsePosition(center)
this._radius = +radius || 0
this._rotateAmount = 0
Expand All @@ -27,7 +27,7 @@ class Circle extends Overlay {

set center(center) {
this._center = Parse.parsePosition(center)
this._delegate.polygon.hierarchy = this._computeHierarchy()
this._delegate.position = Transform.transformWGS84ToCartesian(this._center)
return this
}

Expand All @@ -37,7 +37,8 @@ class Circle extends Overlay {

set radius(radius) {
this._radius = +radius
this._delegate.polygon.hierarchy = this._computeHierarchy()
this._delegate.ellipse.semiMajorAxis = this._radius
this._delegate.ellipse.semiMinorAxis = this._radius
return this
}

Expand All @@ -47,48 +48,26 @@ class Circle extends Overlay {

set rotateAmount(amount) {
this._rotateAmount = +amount
this._delegate.polygon.stRotation = new Cesium.CallbackProperty(() => {
this._delegate.ellipse.stRotation = new Cesium.CallbackProperty(() => {
this._stRotation += this._rotateAmount
if (this._stRotation >= 360 || this._stRotation <= -360) {
this._stRotation = 0
}
return Cesium.Math.toRadians(this._stRotation)
})
}, false)
return this
}

get 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() {
/**
* set the location
*/
this.center = this._center
this.radius = this._radius
}

/**
Expand All @@ -98,7 +77,6 @@ class Circle extends Overlay {
* @returns {Circle}
*/
setLabel(text, textStyle) {
this._delegate.position = Transform.transformWGS84ToCartesian(this._center)
this._delegate.label = {
...textStyle,
text: text
Expand All @@ -115,9 +93,11 @@ class Circle extends Overlay {
if (!style || Object.keys(style).length === 0) {
return this
}
delete style['positions']
delete style['position'] &&
delete style['semiMajorAxis'] &&
delete style['semiMinorAxis']
Util.merge(this._style, style)
Util.merge(this._delegate.polygon, style)
Util.merge(this._delegate.ellipse, style)
return this
}
}
Expand Down

0 comments on commit f5e3e46

Please sign in to comment.