Submit
Path:
~
/
/
usr
/
share
/
grafana
/
public
/
app
/
features
/
geo
/
utils
/
File Content:
frameVectorSource.ts
import { Feature } from 'ol'; import { Geometry, LineString, Point } from 'ol/geom'; import VectorSource from 'ol/source/Vector'; import { DataFrame, Field } from '@grafana/data'; import { getGeometryField, LocationFieldMatchers } from './location'; export interface FrameVectorSourceOptions {} export class FrameVectorSource<T extends Geometry = Geometry> extends VectorSource<T> { constructor(public 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, geometry: info.field.values[i] as T, }) ); } // only call this at the end this.changed(); } updateLineString(frame: DataFrame) { this.clear(true); const info = getGeometryField(frame, this.location); if (!info.field) { this.changed(); return; } //eslint-disable-next-line const field = info.field as unknown as Field<Point>; const geometry: Geometry = new LineString(field.values.map((p) => p.getCoordinates())); this.addFeatureInternal( new Feature({ frame, rowIndex: 0, geometry: geometry as T, }) ); // only call this at the end this.changed(); } }
Submit
FILE
FOLDER
INFO
Name
Size
Permission
Action
frameVectorSource.ts
1465 bytes
0644
location.test.ts
2936 bytes
0644
location.ts
6729 bytes
0644
N4ST4R_ID | Naxtarrr