The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/plugins/panel/geomap/utils/getLayersExtent.ts

33 lines
936 B

import { Collection } from 'ol';
import { createEmpty, extend, Extent } from 'ol/extent';
import BaseLayer from 'ol/layer/Base';
import LayerGroup from 'ol/layer/Group';
import VectorLayer from 'ol/layer/Vector';
export function getLayersExtent(layers: Collection<BaseLayer>): Extent {
return layers
.getArray()
.filter((l) => l instanceof VectorLayer || l instanceof LayerGroup)
.flatMap((l) => {
if (l instanceof LayerGroup) {
return getLayerGroupExtent(l);
} else if (l instanceof VectorLayer) {
return l.getSource().getExtent() ?? [];
}
})
.reduce(extend, createEmpty());
}
export function getLayerGroupExtent(lg: LayerGroup) {
return lg
.getLayers()
.getArray()
.filter((l) => l instanceof VectorLayer)
.map((l) => {
if (l instanceof VectorLayer) {
return l.getSource().getExtent() ?? [];
} else {
return [];
}
});
}