萤石摄像头

This commit is contained in:
Teo
2025-06-17 09:49:15 +08:00
parent d6c0d6319f
commit 2638a32495
17 changed files with 1614 additions and 85 deletions

View File

@ -5,25 +5,26 @@
* 用于将大量数据分批发送到后端,避免单次请求数据过大导致失败。
* 支持设置每批数据大小、批次间延迟、上传函数和完成回调。
*/
/**
* BatchUploader 批量上传工具类(安全简洁版)
* 用于将大量数据分批上传,避免一次性请求数据过大导致失败。
*/
export class BatchUploader<T> {
private dataList: T[]; // 需要上传的数据列表
private chunkSize: number; // 每批上传的条数
private delay: number; // 每批上传之间的延迟时间(单位:毫秒)
private uploadFunc: (chunk: T[], batchIndex: number, totalBatches: number) => Promise<void>; // 每一批次的上传函数
private onComplete?: () => void; // 所有批次完成后的回调函数(可选)
private dataList: T[];
private chunkSize: number;
private delay: number;
private uploadFunc: (chunk: T[], batchIndex: number, totalBatches: number) => Promise<void>;
private onComplete?: () => void;
/**
* 构造函数,初始化批量上传器
* @param options 配置参数
*/
constructor(options: {
dataList: T[]; // 待上传的数据
chunkSize?: number; // 每批数据大小(默认 8000
delay?: number; // 每批之间的延迟(默认 200ms
uploadFunc: (chunk: T[], batchIndex: number, totalBatches: number) => Promise<void>; // 上传逻辑函数
onComplete?: () => void; // 所有批次完成后的回调函数(可选)
dataList: T[]; // 统一使用一维数组类型
chunkSize?: number;
delay?: number;
uploadFunc: (chunk: T[], batchIndex: number, totalBatches: number) => Promise<void>;
onComplete?: () => void;
}) {
const { dataList, chunkSize = 8000, delay = 200, uploadFunc, onComplete } = options;
this.dataList = dataList;
this.chunkSize = chunkSize;
this.delay = delay;
@ -31,32 +32,25 @@ export class BatchUploader<T> {
this.onComplete = onComplete;
}
/**
* 启动批量上传任务
*/
public async start() {
const total = Math.ceil(this.dataList.length / this.chunkSize); // 计算总批次数
const total = Math.ceil(this.dataList.length / this.chunkSize);
// 循环执行每一批上传任务
for (let i = 0; i < total; i++) {
// 截取当前批次的数据
const chunk = this.dataList.slice(i * this.chunkSize, (i + 1) * this.chunkSize);
// 调用传入的上传函数处理该批次数据
console.log(`正在上传第 ${i + 1}/${total}chunk 大小: ${chunk.length}`);
await this.uploadFunc(chunk, i + 1, total);
// 如果不是最后一批,添加延迟
if (this.delay > 0 && i + 1 < total) {
await new Promise((res) => setTimeout(res, this.delay));
}
}
// 所有批次上传完成后,执行完成回调(如果有的话)
this.onComplete?.();
}
}
//使用示例
// const uploader = new BatchUploader({
// dataList: features,
@ -70,4 +64,4 @@ export class BatchUploader<T> {
// }
// });
// await uploader.start();
// await uploader.start();

View File

@ -24,11 +24,7 @@ export class LassoSelector {
private dragPanInteraction: DragPan | null = null;
private mouseWheelZoomInteraction: MouseWheelZoom | null = null;
constructor(
map: OLMap,
targetSource: VectorSource,
onSelect: (selected: Feature[], isInvert?: boolean) => void
) {
constructor(map: OLMap, targetSource: VectorSource, onSelect: (selected: Feature[], isInvert?: boolean) => void) {
this.map = map;
this.targetSource = targetSource;
this.onSelectCallback = onSelect;
@ -50,9 +46,9 @@ export class LassoSelector {
style: new Style({
stroke: new Stroke({
color: '#ff0000',
width: 2,
}),
}),
width: 2
})
})
});
this.map.addLayer(this.drawLayer);
@ -62,12 +58,12 @@ export class LassoSelector {
style: new Style({
stroke: new Stroke({
color: 'rgba(255, 0, 0, 0.8)',
width: 2,
width: 2
}),
fill: new Fill({
color: 'rgba(255, 0, 0, 0.3)',
}),
}),
color: 'rgba(255, 0, 0, 0.3)'
})
})
});
this.map.addLayer(this.overlayLayer);
@ -177,13 +173,10 @@ export class LassoSelector {
const geomObj = geojson.writeGeometryObject(geom, {
featureProjection: 'EPSG:3857',
dataProjection: 'EPSG:4326',
dataProjection: 'EPSG:4326'
}) as any;
if (
(geomObj.type === 'Polygon' || geomObj.type === 'MultiPolygon') &&
booleanIntersects(turfPoly, geomObj)
) {
if ((geomObj.type === 'Polygon' || geomObj.type === 'MultiPolygon') && booleanIntersects(turfPoly, geomObj)) {
selected.push(feature);
}
});