Geomap: Route/path visualization (#43554)

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
Alexander Zobnin
2022-06-27 19:45:09 +03:00
committed by GitHub
parent 0c0cf36ab8
commit 0e1f0dd8f5
4 changed files with 193 additions and 3 deletions

View File

@@ -1,8 +1,8 @@
import { Feature } from 'ol';
import { Geometry } from 'ol/geom';
import { Geometry, LineString, Point } from 'ol/geom';
import VectorSource from 'ol/source/Vector';
import { DataFrame } from '@grafana/data';
import { DataFrame, Field } from '@grafana/data';
import { getGeometryField, LocationFieldMatchers } from './location';
@@ -34,4 +34,26 @@ export class FrameVectorSource<T extends Geometry = Geometry> extends VectorSour
// 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;
}
const field = info.field as Field<Point>;
const geometry = new LineString(field.values.toArray().map((p) => p.getCoordinates())) as Geometry;
this.addFeatureInternal(
new Feature({
frame,
rowIndex: 0,
geometry: geometry as T,
})
);
// only call this at the end
this.changed();
}
}