mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 10:03:33 -06:00
* 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
66 lines
1.6 KiB
TypeScript
66 lines
1.6 KiB
TypeScript
import { Point } from 'ol/geom';
|
|
import { fromLonLat } from 'ol/proj';
|
|
|
|
import { PlacenameInfo, Gazetteer } from './gazetteer';
|
|
|
|
// https://github.com/grafana/worldmap-panel/blob/master/src/data/countries.json
|
|
export interface WorldmapPoint {
|
|
key?: string;
|
|
keys?: string[]; // new in grafana 8.1+
|
|
latitude: number;
|
|
longitude: number;
|
|
name?: string;
|
|
}
|
|
|
|
export function loadWorldmapPoints(path: string, data: WorldmapPoint[]): Gazetteer {
|
|
let count = 0;
|
|
const values = new Map<string, PlacenameInfo>();
|
|
for (const v of data) {
|
|
const point = new Point(fromLonLat([v.longitude, v.latitude]));
|
|
const info: PlacenameInfo = {
|
|
point: () => point,
|
|
geometry: () => point,
|
|
};
|
|
if (v.name) {
|
|
values.set(v.name, info);
|
|
values.set(v.name.toUpperCase(), info);
|
|
}
|
|
if (v.key) {
|
|
values.set(v.key, info);
|
|
values.set(v.key.toUpperCase(), info);
|
|
}
|
|
if (v.keys) {
|
|
for (const key of v.keys) {
|
|
values.set(key, info);
|
|
values.set(key.toUpperCase(), info);
|
|
}
|
|
}
|
|
count++;
|
|
}
|
|
return {
|
|
path,
|
|
find: (k) => {
|
|
let v = values.get(k);
|
|
if (!v && typeof k === 'string') {
|
|
v = values.get(k.toUpperCase());
|
|
}
|
|
return v;
|
|
},
|
|
count,
|
|
examples: (count) => {
|
|
const first: string[] = [];
|
|
if (values.size < 1) {
|
|
first.push('no values found');
|
|
} else {
|
|
for (const key of values.keys()) {
|
|
first.push(key);
|
|
if (first.length >= count) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return first;
|
|
},
|
|
};
|
|
}
|