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/features/geo/gazetteer/worldmap.ts

64 lines
1.6 KiB

import { PlacenameInfo, Gazetteer } from './gazetteer';
import { Point } from 'ol/geom';
import { fromLonLat } from 'ol/proj';
// 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;
},
};
}