import * as Cesium from 'cesium' import DialogPropertyGrid from '../DialogPropertyGrid'; import { setPropertyData } from '../DialogPropertyGrid/property'; import FeatureGroundPrimitive from '@/components/CesiumMap/FeatureGroundPrimitive'; import { getArea, getBoundingCenterCoordinate } from '@/components/CesiumMap/mixins/useMeasureTool'; import fireWarehouseIcon from '@/assets/icons/fire_warehouse.png'; // 绘制水源地(面) const drawWatersource = (options) => { const { drawTool, measureTool, viewer, primitiveList } = options; if(!drawTool) { console.error('绘制工具未初始化'); return; } drawTool.abort(); measureTool.abort(); drawTool.drawPolygon().then((positions) => { // 计算中心点坐标 const center = getBoundingCenterCoordinate(positions); // // 添加水源地实体 // const entity = toolbarLayer?.entities.add({ // // polyline: { // // positions:[...positions, positions[0]], // 闭合多边形 // // width: 2, // // material: Cesium.Color.BLUE, // // }, // polygon: { // hierarchy: positions, // material: riverMaterial, // // material: Cesium.Color.BLUE.withAlpha(0.5), // }, // properties: { // __type: 'watersource', // name: '', // area: getArea(positions).toFixed(2), // 面积 // longitude: center[0].toFixed(6), // latitude: center[1].toFixed(6), // volume: 0 // 储水量,默认0 // } // }); const waterMaterial = new Cesium.Material({ fabric: { type: 'Water', uniforms: { normalMap: Cesium.buildModuleUrl('Assets/Textures/waterNormals.jpg'), baseWaterColor: new Cesium.Color( 64 / 255.0, 157 / 255.0, 253 / 255.0, 0.6 ), // blendColor: new Cesium.Color(0.0, 0.5, 1.0, 1.0), // frequency: 10.0, // animationSpeed: 0.05, // amplitude: 10, // specularIntensity: 0.5, // alpha: 0.1 frequency: 1000.0, animationSpeed: 0.1, amplitude: 10, specularIntensity: 1.5, } } }); const waterPrimitive = new FeatureGroundPrimitive({ geometryInstances: new Cesium.GeometryInstance({ geometry: new Cesium.PolygonGeometry({ polygonHierarchy: new Cesium.PolygonHierarchy(positions), vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT, }) }), appearance: new Cesium.EllipsoidSurfaceAppearance({ material: waterMaterial, }) }, { __type: 'watersource', name: '', area: getArea(positions).toFixed(2), // 面积 longitude: center[0].toFixed(6), latitude: center[1].toFixed(6), volume: 0 // 储水量,默认0 }); // 将 Primitive 添加到场景中 viewer.scene.primitives.add(waterPrimitive); primitiveList.push(waterPrimitive); // 编辑属性 DialogPropertyGrid.show(waterPrimitive, (data) => { // 更新实体属性 setPropertyData(data, waterPrimitive); // 调用接口 }); }); }; // 绘制仓库(点) const drawWarehouse = (options) => { const { drawTool, measureTool, toolbarLayer } = options; if(!drawTool) { console.error('绘制工具未初始化'); return; } drawTool.abort(); measureTool.abort(); drawTool.drawPoint().then((position) => { // 计算中心点坐标 const center = Cesium.Cartographic.fromCartesian(position); const entity = toolbarLayer?.entities.add({ position, billboard: { image: fireWarehouseIcon, verticalOrigin: Cesium.VerticalOrigin.BOTTOM, pixelOffset: new Cesium.Cartesian2(0, 18), // 可选偏移 }, properties: { __type: 'warehouse', name: '', longitude: Cesium.Math.toDegrees(center.longitude).toFixed(6), latitude: Cesium.Math.toDegrees(center.latitude).toFixed(6), } }); // 编辑属性 DialogPropertyGrid.show(entity, (data) => { // 更新实体属性 setPropertyData(data, entity); // 调用接口 }); }); }; export { drawWatersource, drawWarehouse }