| File was renamed from applications/drone-command/src/views/areaManage/partition/shapeTools/edit/EditEllipseTool.js |
| | |
| | | lat: point.lat ?? point.latitude, |
| | | })) |
| | | |
| | | const resolveLngLat = point => { |
| | | if (!point) return null |
| | | const lng = point.lng ?? point.longitude |
| | | const lat = point.lat ?? point.latitude |
| | | if (Number.isFinite(lng) && Number.isFinite(lat)) { |
| | | return { lng: Number(lng), lat: Number(lat), height: Number(point.height) || 0 } |
| | | } |
| | | return null |
| | | } |
| | | |
| | | const resolveCartesian = point => { |
| | | if (!point) return null |
| | | if (Number.isFinite(point.x) && Number.isFinite(point.y) && Number.isFinite(point.z)) { |
| | | return new Cesium.Cartesian3(point.x, point.y, point.z) |
| | | } |
| | | const lngLat = resolveLngLat(point) |
| | | if (!lngLat) return null |
| | | return Cesium.Cartesian3.fromDegrees(lngLat.lng, lngLat.lat, lngLat.height || 0) |
| | | } |
| | | |
| | | const resolveCartographic = point => { |
| | | if (!point) return null |
| | | if (Number.isFinite(point.x) && Number.isFinite(point.y) && Number.isFinite(point.z)) { |
| | | return Cesium.Cartographic.fromCartesian(point) |
| | | } |
| | | const lngLat = resolveLngLat(point) |
| | | if (!lngLat) return null |
| | | return Cesium.Cartographic.fromDegrees(lngLat.lng, lngLat.lat, lngLat.height || 0) |
| | | } |
| | | |
| | | export class EditEllipseTool extends ToolBase { |
| | | constructor(viewer, options = {}) { |
| | | super(viewer) |
| | |
| | | this.style = resolveStyle(options?.style) |
| | | } |
| | | |
| | | start(points = []) { |
| | | const normalized = normalizePoints(points) |
| | | const bounds = getBoundsFromLngLats(normalized) |
| | | const center = getCenterFromBounds(bounds) |
| | | if (!center) return |
| | | this.centerCartesian = Cesium.Cartesian3.fromRadians(center.longitude, center.latitude) |
| | | const eastWest = getMetersBetween( |
| | | new Cesium.Cartographic(bounds.west, center.latitude), |
| | | new Cesium.Cartographic(bounds.east, center.latitude) |
| | | ) |
| | | const northSouth = getMetersBetween( |
| | | new Cesium.Cartographic(center.longitude, bounds.south), |
| | | new Cesium.Cartographic(center.longitude, bounds.north) |
| | | ) |
| | | this.semiMajor = Math.max(1, eastWest / 2) |
| | | this.semiMinor = Math.max(1, northSouth / 2) |
| | | start(data = []) { |
| | | const inputPoints = Array.isArray(data?.points) ? data.points : data |
| | | const meta = data?.meta || null |
| | | const metaCenter = resolveCartesian(meta?.center) |
| | | if (metaCenter) { |
| | | this.centerCartesian = metaCenter |
| | | const centerCarto = Cesium.Cartographic.fromCartesian(metaCenter) |
| | | const majorFromMeta = Number.isFinite(meta?.semiMajor) ? Number(meta.semiMajor) : 0 |
| | | const minorFromMeta = Number.isFinite(meta?.semiMinor) ? Number(meta.semiMinor) : 0 |
| | | const majorPoint = resolveCartographic(meta?.majorPoint) |
| | | const minorPoint = resolveCartographic(meta?.minorPoint) |
| | | const majorDistance = |
| | | majorFromMeta || (majorPoint ? getMetersBetween(centerCarto, majorPoint) : 0) |
| | | const minorDistance = |
| | | minorFromMeta || (minorPoint ? getMetersBetween(centerCarto, minorPoint) : 0) |
| | | if (majorDistance > 0) this.semiMajor = Math.max(1, majorDistance) |
| | | if (minorDistance > 0) this.semiMinor = Math.max(1, minorDistance) |
| | | if (this.semiMinor > this.semiMajor) this.semiMinor = this.semiMajor |
| | | } |
| | | |
| | | if (!this.centerCartesian || !this.semiMajor || !this.semiMinor) { |
| | | const normalized = normalizePoints(inputPoints) |
| | | const bounds = getBoundsFromLngLats(normalized) |
| | | const center = getCenterFromBounds(bounds) |
| | | if (!center) return |
| | | this.centerCartesian = Cesium.Cartesian3.fromRadians(center.longitude, center.latitude) |
| | | const eastWest = getMetersBetween( |
| | | new Cesium.Cartographic(bounds.west, center.latitude), |
| | | new Cesium.Cartographic(bounds.east, center.latitude) |
| | | ) |
| | | const northSouth = getMetersBetween( |
| | | new Cesium.Cartographic(center.longitude, bounds.south), |
| | | new Cesium.Cartographic(center.longitude, bounds.north) |
| | | ) |
| | | this.semiMajor = Math.max(1, eastWest / 2) |
| | | this.semiMinor = Math.max(1, northSouth / 2) |
| | | } |
| | | |
| | | this.dataSource = new Cesium.CustomDataSource('edit-ellipse') |
| | | this.viewer.dataSources.add(this.dataSource) |
| | |
| | | this.dragType = null |
| | | this.enableMapControl() |
| | | const positions = buildEllipsePositions(this.centerCartesian, this.semiMajor, this.semiMinor) |
| | | this.notify('getPolygonPositions', positions) |
| | | this.notify('getPolygonPositions', { |
| | | positions, |
| | | meta: { |
| | | center: this.centerCartesian, |
| | | majorPoint: this.getAxisPoint(this.semiMajor, 0), |
| | | minorPoint: this.getAxisPoint(0, this.semiMinor), |
| | | semiMajor: this.semiMajor, |
| | | semiMinor: this.semiMinor, |
| | | }, |
| | | }) |
| | | } |
| | | |
| | | createEntities() { |
| | |
| | | |
| | | getPositions() { |
| | | if (!this.centerCartesian) return [] |
| | | return buildEllipsePositions(this.centerCartesian, this.semiMajor, this.semiMinor) |
| | | return { |
| | | positions: buildEllipsePositions(this.centerCartesian, this.semiMajor, this.semiMinor), |
| | | meta: { |
| | | center: this.centerCartesian, |
| | | majorPoint: this.getAxisPoint(this.semiMajor, 0), |
| | | minorPoint: this.getAxisPoint(0, this.semiMinor), |
| | | semiMajor: this.semiMajor, |
| | | semiMinor: this.semiMinor, |
| | | }, |
| | | } |
| | | } |
| | | |
| | | getAxisPoint(eastMeters, northMeters) { |