2022-01-14 09:15:31 +08:00
|
|
|
import { DataFrame } from '@grafana/data';
|
|
|
|
import { Feature } from 'ol';
|
|
|
|
import { Geometry } from 'ol/geom';
|
|
|
|
import VectorSource from 'ol/source/Vector';
|
|
|
|
import { getGeometryField, LocationFieldMatchers } from './location';
|
|
|
|
|
|
|
|
export interface FrameVectorSourceOptions {}
|
|
|
|
|
2022-03-03 16:45:33 +08:00
|
|
|
export class FrameVectorSource<T extends Geometry = Geometry> extends VectorSource<T> {
|
2022-01-14 09:15:31 +08:00
|
|
|
constructor(private location: LocationFieldMatchers) {
|
|
|
|
super({});
|
|
|
|
}
|
|
|
|
|
|
|
|
update(frame: DataFrame) {
|
|
|
|
this.clear(true);
|
|
|
|
const info = getGeometryField(frame, this.location);
|
|
|
|
if (!info.field) {
|
|
|
|
this.changed();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < frame.length; i++) {
|
|
|
|
this.addFeatureInternal(
|
|
|
|
new Feature({
|
|
|
|
frame,
|
|
|
|
rowIndex: i,
|
2022-03-03 16:45:33 +08:00
|
|
|
geometry: info.field.values.get(i) as T,
|
2022-01-14 09:15:31 +08:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// only call this at the end
|
|
|
|
this.changed();
|
|
|
|
}
|
|
|
|
}
|