frameVectorSource.ts 887 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { Feature } from 'ol';
  2. import { Geometry } from 'ol/geom';
  3. import VectorSource from 'ol/source/Vector';
  4. import { DataFrame } from '@grafana/data';
  5. import { getGeometryField, LocationFieldMatchers } from './location';
  6. export interface FrameVectorSourceOptions {}
  7. export class FrameVectorSource<T extends Geometry = Geometry> extends VectorSource<T> {
  8. constructor(private location: LocationFieldMatchers) {
  9. super({});
  10. }
  11. update(frame: DataFrame) {
  12. this.clear(true);
  13. const info = getGeometryField(frame, this.location);
  14. if (!info.field) {
  15. this.changed();
  16. return;
  17. }
  18. for (let i = 0; i < frame.length; i++) {
  19. this.addFeatureInternal(
  20. new Feature({
  21. frame,
  22. rowIndex: i,
  23. geometry: info.field.values.get(i) as T,
  24. })
  25. );
  26. }
  27. // only call this at the end
  28. this.changed();
  29. }
  30. }