| | |
| | | |
| | | // 渲染面 |
| | | function renderingSurface() { |
| | | console.log(geometricSource, 11111111) |
| | | |
| | | if (!geometricSource) { |
| | | initMap() |
| | | } |
| | |
| | | const map = mapRef.value?.getMap() |
| | | if (!map?.viewer) return |
| | | viewer = map.viewer |
| | | if (!readonly.value && !leftClickBound) { |
| | | map.publicCesium?.addLeftClickEvent?.(null, LeftClickEvent) |
| | | leftClickBound = true |
| | | } |
| | | if (!geometricSource) { |
| | | geometricSource = new Cesium.CustomDataSource('geometricSource') |
| | | viewer.dataSources.add(geometricSource) |
| | | } |
| | | } |
| | | |
| | | function LeftClickEvent(click) { |
| | | const pos = click.position |
| | | // 优先使用 pickPosition 获取贴地坐标(包含地形高度) |
| | | let cartesian3 = viewer.scene.pickPosition(pos) |
| | | // 如果 pickPosition 失败,回退到 pickEllipsoid |
| | | if (!cartesian3 || !Cesium.defined(cartesian3)) { |
| | | cartesian3 = viewer.camera.pickEllipsoid(pos, viewer.scene.globe.ellipsoid) |
| | | } |
| | | if (!cartesian3) return |
| | | const carto = Cesium.Cartographic.fromCartesian(cartesian3) |
| | | const longitude = Cesium.Math.toDegrees(carto.longitude) |
| | | const latitude = Cesium.Math.toDegrees(carto.latitude) |
| | | formData.value.longitude = _.round(longitude, 6) |
| | | formData.value.latitude = _.round(latitude, 6) |
| | | setMapPoint(formData.value.longitude, formData.value.latitude) |
| | | } |
| | | |
| | | function setMapPoint(longitude, latitude) { |
| | | if (!viewer || longitude == null || latitude == null) return |
| | | if (!redPointEntity) { |
| | | redPointEntity = viewer.entities.add({ |
| | | position: Cesium.Cartesian3.fromDegrees(longitude, latitude), |
| | | billboard: { |
| | | image: commandPost, // 这里替换为你的图片路径或变量 deviceZcImg |
| | | width: 40, |
| | | height: 56, |
| | | verticalOrigin: Cesium.VerticalOrigin.BOTTOM, // 设置图片底部对齐坐标点 |
| | | heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, // 贴地 |
| | | }, |
| | | label: { |
| | | text: `${longitude.toFixed(6)}, ${latitude.toFixed(6)}`, |
| | | font: '14px', |
| | | fillColor: Cesium.Color.WHITE, |
| | | backgroundColor: Cesium.Color.BLACK.withAlpha(0.6), |
| | | backgroundPadding: new Cesium.Cartesian2(5, 5), |
| | | showBackground: true, |
| | | style: Cesium.LabelStyle.FILL_AND_OUTLINE, |
| | | horizontalOrigin: Cesium.HorizontalOrigin.CENTER, |
| | | verticalOrigin: Cesium.VerticalOrigin.BOTTOM, |
| | | outlineWidth: 1, |
| | | outlineColor: Cesium.Color.WHITE, |
| | | pixelOffset: new Cesium.Cartesian2(0, -60), |
| | | heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, // 贴地 |
| | | }, |
| | | }) |
| | | } else { |
| | | redPointEntity.position = Cesium.Cartesian3.fromDegrees(longitude, latitude) |
| | | redPointEntity.label.text = `${longitude.toFixed(6)}, ${latitude.toFixed(6)}` |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | await nextTick() |
| | | syncAreaSelection() |
| | | setMapPoint(formData.value.longitude, formData.value.latitude) |
| | | } |
| | | |
| | | onMounted(() => { |
| | | getAreaList() |
| | | }) |
| | | |
| | | defineExpose({ |
| | | open, |
| | | }) |