| | |
| | | import { ToolBase } from '../ToolBase' |
| | | import { buildEllipsePositions } from '../shapeUtils' |
| | | |
| | | const DEFAULT_STYLE = { |
| | | fill: Cesium.Color.fromBytes(45, 140, 240, 99), |
| | | outline: Cesium.Color.fromBytes(45, 140, 240, 255), |
| | | } |
| | | const resolveStyle = style => ({ |
| | | fill: style?.fill || DEFAULT_STYLE.fill, |
| | | outline: style?.outline || DEFAULT_STYLE.outline, |
| | | }) |
| | | |
| | | export class DrawEllipseTool extends ToolBase { |
| | | constructor(viewer) { |
| | | constructor(viewer, options = {}) { |
| | | super(viewer) |
| | | this.tooltip = new MapTooltip(viewer) |
| | | this.dataSource = null |
| | |
| | | this.semiMinor = 0 |
| | | this.isDrawing = false |
| | | this.drawStep = 0 |
| | | this.style = resolveStyle(options?.style) |
| | | } |
| | | |
| | | start() { |
| | |
| | | ellipse: { |
| | | semiMajorAxis: new Cesium.CallbackProperty(() => this.semiMajor, false), |
| | | semiMinorAxis: new Cesium.CallbackProperty(() => this.semiMinor, false), |
| | | material: Cesium.Color.fromBytes(45, 140, 240, 99), |
| | | material: this.style.fill, |
| | | outline: true, |
| | | outlineColor: Cesium.Color.fromBytes(45, 140, 240, 255), |
| | | outlineColor: this.style.outline, |
| | | outlineWidth: 2, |
| | | heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, |
| | | }, |
| | |
| | | return scene.camera.pickEllipsoid(screenPosition, scene.globe.ellipsoid) |
| | | } |
| | | |
| | | setStyle(style) { |
| | | this.style = resolveStyle(style) |
| | | if (this.ellipseEntity?.ellipse) { |
| | | this.ellipseEntity.ellipse.material = this.style.fill |
| | | this.ellipseEntity.ellipse.outlineColor = this.style.outline |
| | | } |
| | | } |
| | | |
| | | destroy() { |
| | | if (this.dataSource) { |
| | | this.dataSource.entities.removeAll() |