| | |
| | | import * as Cesium from 'cesium' |
| | | import { MapTooltip } from '@ztzf/utils' |
| | | import { ToolBase } from '../ToolBase' |
| | | import { buildEllipsePositions, cartesianToLocal } from '../shapeUtils' |
| | | import { |
| | | buildEllipsePositions, |
| | | cartesianToLocal, |
| | | formatBufferRadius, |
| | | getBufferRadiusLabelStyle, |
| | | getBufferRadiusPoint, |
| | | } from '../shapeUtils' |
| | | |
| | | const normalizePoints = points => |
| | | (points || []).map(point => ({ |
| | |
| | | this.radiusLevel1Entity = null |
| | | this.radiusLevel2Entity = null |
| | | this.radiusLevel3Entity = null |
| | | this.radiusLevel1LabelEntity = null |
| | | this.radiusLevel2LabelEntity = null |
| | | this.radiusLevel3LabelEntity = null |
| | | } |
| | | |
| | | start(data = []) { |
| | |
| | | this.handler.setInputAction(evt => this.handleLeftDown(evt), Cesium.ScreenSpaceEventType.LEFT_DOWN) |
| | | this.handler.setInputAction(evt => this.handleMouseMove(evt), Cesium.ScreenSpaceEventType.MOUSE_MOVE) |
| | | this.handler.setInputAction(() => this.handleLeftUp(), Cesium.ScreenSpaceEventType.LEFT_UP) |
| | | this.tooltip.show('拖动控制点编辑', { x: 0, y: 0 }) |
| | | this.tooltip.hide() |
| | | } |
| | | |
| | | handleLeftDown(evt) { |
| | |
| | | } |
| | | |
| | | handleMouseMove(evt) { |
| | | this.tooltip.move(evt.endPosition) |
| | | if (!this.tooltip?.isVisible) { |
| | | this.tooltip.show('拖动控制点编辑', evt.endPosition) |
| | | } else { |
| | | this.tooltip.show('拖动控制点编辑') |
| | | this.tooltip.move(evt.endPosition) |
| | | } |
| | | if (!this.dragType) return |
| | | const position = this.getPositionFromScreen(evt.endPosition) |
| | | if (!position) return |
| | |
| | | }, |
| | | customType: 'circle-radius-3', |
| | | }) |
| | | |
| | | this.radiusLevel1LabelEntity = this.createRadiusLabelEntity(() => this.radiusLevel1) |
| | | this.radiusLevel2LabelEntity = this.createRadiusLabelEntity(() => this.radiusLevel2) |
| | | this.radiusLevel3LabelEntity = this.createRadiusLabelEntity(() => this.radiusLevel3) |
| | | } |
| | | |
| | | updateRadiusPoints() { |
| | |
| | | } |
| | | |
| | | getRadiusPoint(radius) { |
| | | const frame = Cesium.Transforms.eastNorthUpToFixedFrame(this.centerCartesian) |
| | | const local = new Cesium.Cartesian3(radius, 0, 0) |
| | | return Cesium.Matrix4.multiplyByPoint(frame, local, new Cesium.Cartesian3()) |
| | | return getBufferRadiusPoint(this.centerCartesian, radius) |
| | | } |
| | | |
| | | createRadiusLabelEntity(getRadius) { |
| | | return this.dataSource.entities.add({ |
| | | position: new Cesium.CallbackProperty( |
| | | () => getBufferRadiusPoint(this.centerCartesian, getRadius()), |
| | | false |
| | | ), |
| | | label: { |
| | | ...getBufferRadiusLabelStyle(), |
| | | text: new Cesium.CallbackProperty(() => formatBufferRadius(getRadius()), false), |
| | | }, |
| | | }) |
| | | } |
| | | |
| | | getPositionFromScreen(screenPosition) { |
| | | const scene = this.viewer.scene |
| | | const cartesian = scene.pickPosition(screenPosition) |
| | | const ray = scene.camera.getPickRay(screenPosition) |
| | | const cartesian = ray ? scene.globe.pick(ray, scene) : null |
| | | if (cartesian) return cartesian |
| | | return scene.camera.pickEllipsoid(screenPosition, scene.globe.ellipsoid) |
| | | } |
| | |
| | | this.circleLevel1OutlineEntity = null |
| | | this.circleLevel2OutlineEntity = null |
| | | this.circleLevel3OutlineEntity = null |
| | | this.radiusLevel1LabelEntity = null |
| | | this.radiusLevel2LabelEntity = null |
| | | this.radiusLevel3LabelEntity = null |
| | | this.dragType = null |
| | | } |
| | | } |