// /src/utils/OrthoImageryManager.js export default class OrthoImageryManager { constructor(viewer, Cesium, options = {}) { this.viewer = viewer; this.Cesium = Cesium; this.layerMap = new Map(); // key -> layer this.layerQueue = []; // 先进先出控制数量 this.maxLayers = options.maxLayers || 400; // 全局亮度与透明度 this.globalBrightness = options.brightness ?? 1.0; this.globalAlpha = options.alpha ?? 1.0; } /** * 添加或更新新推送的图片 */ add(data) { const key = `${data.jobId}-${data.uavId}~${data.fileId}`; // 已存在则跳过 if (this.layerMap.has(key)) return; const rectangle = this.Cesium.Rectangle.fromDegrees( Math.min(data.left1Lon, data.right2Lon), Math.min(data.left1Lat, data.right2Lat), Math.max(data.left1Lon, data.right2Lon), Math.max(data.left1Lat, data.right2Lat) ); const provider = new this.Cesium.SingleTileImageryProvider({ url: window.config.imagePath + data.relativePath, rectangle }); const layer = this.viewer.cesiumViewer.imageryLayers.addImageryProvider(provider); // ✅ 使用全局亮度和透明度,保证新图生效 layer.brightness = this.globalBrightness; layer.alpha = this.globalAlpha; this.layerMap.set(key, layer); this.layerQueue.push(key); this._checkLimit(); } /** * 设置全局亮度,影响所有已有图片和未来新推送的图片 */ setBrightness(value) { this.globalBrightness = value; this.layerMap.forEach(layer => { layer.brightness = value; }); } /** * 设置全局透明度 */ setAlphaAll(value) { this.globalAlpha = value; this.layerMap.forEach(layer => { layer.alpha = value; }); } /** * 对单张图片单独设置亮度(不影响全局) */ setBrightnessForFile(fileId, value) { const key = [...this.layerMap.keys()].find(k => k.includes(fileId)); if (!key) return; const layer = this.layerMap.get(key); if (layer) { layer.brightness = value; } } /** * 对单张图片单独设置透明度 */ setAlphaForFile(fileId, value) { const key = [...this.layerMap.keys()].find(k => k.includes(fileId)); if (!key) return; const layer = this.layerMap.get(key); if (layer) { layer.alpha = value; } } /** * 清理超过最大图层数 */ _checkLimit() { while (this.layerQueue.length > this.maxLayers) { const oldestKey = this.layerQueue.shift(); const layer = this.layerMap.get(oldestKey); if (layer) { this.viewer.imageryLayers.remove(layer); this.layerMap.delete(oldestKey); } } } /** * 删除单张图片 */ remove(fileId) { const key = [...this.layerMap.keys()].find(k => k.includes(fileId)); if (!key) return; const layer = this.layerMap.get(key); if (layer) { this.viewer.imageryLayers.remove(layer); this.layerMap.delete(key); // 也从队列里移除 const index = this.layerQueue.indexOf(key); if (index > -1) this.layerQueue.splice(index, 1); } } /** * 清空所有图片 */ clearAll() { this.layerMap.forEach(layer => { this.viewer.cesiumViewer.imageryLayers.remove(layer); }); this.layerMap.clear(); this.layerQueue = []; } }