|
|
|
@ -1,4 +1,4 @@ |
|
|
|
|
import { MapLayerRegistryItem, MapLayerOptions, MapLayerHandler, PanelData, GrafanaTheme2 } from '@grafana/data'; |
|
|
|
|
import { MapLayerRegistryItem, MapLayerOptions, MapLayerHandler, PanelData, GrafanaTheme2, FrameGeometrySourceMode } from '@grafana/data'; |
|
|
|
|
import Map from 'ol/Map'; |
|
|
|
|
import Feature from 'ol/Feature'; |
|
|
|
|
import * as layer from 'ol/layer'; |
|
|
|
@ -23,8 +23,8 @@ export interface MarkersConfig { |
|
|
|
|
const defaultOptions: MarkersConfig = { |
|
|
|
|
size: { |
|
|
|
|
fixed: 5, |
|
|
|
|
min: 5, |
|
|
|
|
max: 10, |
|
|
|
|
min: 2, |
|
|
|
|
max: 15, |
|
|
|
|
}, |
|
|
|
|
color: { |
|
|
|
|
fixed: '#f00',
|
|
|
|
@ -34,6 +34,15 @@ const defaultOptions: MarkersConfig = { |
|
|
|
|
|
|
|
|
|
export const MARKERS_LAYER_ID = "markers"; |
|
|
|
|
|
|
|
|
|
// Used by default when nothing is configured
|
|
|
|
|
export const defaultMarkersConfig:MapLayerOptions<MarkersConfig> = { |
|
|
|
|
type: MARKERS_LAYER_ID, |
|
|
|
|
config: defaultOptions, |
|
|
|
|
location: { |
|
|
|
|
mode: FrameGeometrySourceMode.Auto, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Map layer configuration for circle overlay |
|
|
|
|
*/ |
|
|
|
@ -51,13 +60,18 @@ export const markersLayer: MapLayerRegistryItem<MarkersConfig> = { |
|
|
|
|
create: (map: Map, options: MapLayerOptions<MarkersConfig>, theme: GrafanaTheme2): MapLayerHandler => { |
|
|
|
|
const matchers = getLocationMatchers(options.location); |
|
|
|
|
const vectorLayer = new layer.Vector({}); |
|
|
|
|
// Assert default values
|
|
|
|
|
const config = { |
|
|
|
|
...defaultOptions, |
|
|
|
|
...options?.config, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
init: () => vectorLayer, |
|
|
|
|
update: (data: PanelData) => { |
|
|
|
|
if(!data.series?.length) { |
|
|
|
|
return; // ignore empty
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const frame = data.series[0]; |
|
|
|
|
const info = dataFrameToPoints(frame, matchers); |
|
|
|
|
if(info.warning) { |
|
|
|
@ -65,11 +79,6 @@ export const markersLayer: MapLayerRegistryItem<MarkersConfig> = { |
|
|
|
|
return; // ???
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Assert default values
|
|
|
|
|
const config = { |
|
|
|
|
...defaultOptions, |
|
|
|
|
...options?.config, |
|
|
|
|
}; |
|
|
|
|
const colorDim = getColorDimension(frame, config.color, theme); |
|
|
|
|
const sizeDim = getScaledDimension(frame, config.size); |
|
|
|
|
const opacity = options.config?.fillOpacity ?? defaultOptions.fillOpacity; |
|
|
|
@ -152,6 +161,7 @@ export const markersLayer: MapLayerRegistryItem<MarkersConfig> = { |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// fill in the default values
|
|
|
|
|
defaultOptions, |
|
|
|
|
}; |
|
|
|
|