Files
Josh Hunt 3c6e0e8ef8 Chore: ESlint import order (#44959)
* Add and configure eslint-plugin-import

* Fix the lint:ts npm command

* Autofix + prettier all the files

* Manually fix remaining files

* Move jquery code in jest-setup to external file to safely reorder imports

* Resolve issue caused by circular dependencies within Prometheus

* Update .betterer.results

* Fix missing // @ts-ignore

* ignore iconBundle.ts

* Fix missing // @ts-ignore
2022-04-22 14:33:13 +01:00

63 lines
1.5 KiB
TypeScript

import { FeatureLike } from 'ol/Feature';
import { SelectableValue } from '@grafana/data';
import { GeometryTypeId } from '../style/types';
export interface LayerContentInfo {
geometryType: GeometryTypeId;
propertes: Array<SelectableValue<string>>;
}
export function getLayerPropertyInfo(features: FeatureLike[]): LayerContentInfo {
const types = new Set<string>();
const props = new Set<string>();
features.some((feature, idx) => {
for (const key of Object.keys(feature.getProperties())) {
if (key === 'geometry') {
continue;
}
props.add(key);
const g = feature.getGeometry();
if (g) {
types.add(g.getType());
}
}
return idx > 10; // first 10 items
});
let geometryType = GeometryTypeId.Any;
if (types.size === 1) {
switch (types.values().next().value) {
case 'Point':
case 'MultiPoint':
geometryType = GeometryTypeId.Point;
break;
case 'Line':
case 'MultiLine':
geometryType = GeometryTypeId.Line;
break;
case 'Polygon':
geometryType = GeometryTypeId.Polygon;
}
}
return {
geometryType,
propertes: Array.from(props.keys()).map((v) => ({ label: v, value: v })),
};
}
export function getUniqueFeatureValues(features: FeatureLike[], key: string): string[] {
const unique = new Set<string>();
for (const feature of features) {
const v = feature.get(key);
if (v != null) {
unique.add(`${v}`); // always string
}
}
const buffer = Array.from(unique);
buffer.sort();
return buffer;
}