mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
GeomapPanel: Add base types to data layer options (#50053)
* GeomapPanel: Add base types to data layer options Removed isBaseMap check from data layer filter, which used to remove base layer types from data layer options. For layer editor, slider to control opacity is added. * GeomapPanel: Reorder data layer options For data layer selection, present user with data layer types first, before base map layer types. Refactored to consolidate layer options into a single exported function in registry with a base map boolean. * GeomapPanel: Add descriptions to base map types * GeomapPanel: add hideOpacity and apply to markers * GeomapPanel: update descriptions for map types Closes #47812
This commit is contained in:
@@ -24,7 +24,8 @@ export const defaultCartoConfig: CartoConfig = {
|
||||
|
||||
export const carto: MapLayerRegistryItem<CartoConfig> = {
|
||||
id: 'carto',
|
||||
name: 'CARTO reference map',
|
||||
name: 'CARTO basemap',
|
||||
description: 'Add layer CARTO Raster basemaps',
|
||||
isBaseMap: true,
|
||||
defaultOptions: defaultCartoConfig,
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ export interface ESRIXYZConfig extends XYZConfig {
|
||||
export const esriXYZTiles: MapLayerRegistryItem<ESRIXYZConfig> = {
|
||||
id: 'esri-xyz',
|
||||
name: 'ArcGIS MapServer',
|
||||
description: 'Add layer from an ESRI ArcGIS MapServer',
|
||||
isBaseMap: true,
|
||||
|
||||
create: async (map: Map, options: MapLayerOptions<ESRIXYZConfig>, theme: GrafanaTheme2) => {
|
||||
|
||||
@@ -20,6 +20,7 @@ export const defaultXYZConfig: XYZConfig = {
|
||||
export const xyzTiles: MapLayerRegistryItem<XYZConfig> = {
|
||||
id: 'xyz',
|
||||
name: 'XYZ Tile layer',
|
||||
description: 'Add map from a generic tile layer',
|
||||
isBaseMap: true,
|
||||
|
||||
create: async (map: Map, options: MapLayerOptions<XYZConfig>, theme: GrafanaTheme2) => ({
|
||||
|
||||
@@ -7,6 +7,7 @@ import { MapLayerRegistryItem, MapLayerOptions } from '@grafana/data';
|
||||
export const standard: MapLayerRegistryItem = {
|
||||
id: 'osm-standard',
|
||||
name: 'Open Street Map',
|
||||
description: 'Add map from a collaborative free geographic world database',
|
||||
isBaseMap: true,
|
||||
|
||||
/**
|
||||
|
||||
@@ -53,6 +53,7 @@ export const markersLayer: MapLayerRegistryItem<MarkersConfig> = {
|
||||
description: 'Use markers to render each data point',
|
||||
isBaseMap: false,
|
||||
showLocation: true,
|
||||
hideOpacity: true,
|
||||
|
||||
/**
|
||||
* Function that configures transformation and returns a transformer
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
import Map from 'ol/Map';
|
||||
|
||||
import { MapLayerRegistryItem, Registry, MapLayerOptions, GrafanaTheme2 } from '@grafana/data';
|
||||
import { config } from 'app/core/config';
|
||||
import {
|
||||
MapLayerRegistryItem,
|
||||
Registry,
|
||||
MapLayerOptions,
|
||||
GrafanaTheme2,
|
||||
SelectableValue,
|
||||
PluginState,
|
||||
} from '@grafana/data';
|
||||
import { config, hasAlphaPanels } from 'app/core/config';
|
||||
|
||||
import { basemapLayers } from './basemaps';
|
||||
import { carto } from './basemaps/carto';
|
||||
@@ -42,3 +49,30 @@ export const geomapLayerRegistry = new Registry<MapLayerRegistryItem<any>>(() =>
|
||||
...basemapLayers, // simple basemaps
|
||||
...dataLayers, // Layers with update functions
|
||||
]);
|
||||
|
||||
interface RegistrySelectInfo {
|
||||
options: Array<SelectableValue<string>>;
|
||||
current: Array<SelectableValue<string>>;
|
||||
}
|
||||
|
||||
function getLayersSelection(items: Array<MapLayerRegistryItem<any>>, current?: string): RegistrySelectInfo {
|
||||
const res: RegistrySelectInfo = { options: [], current: [] };
|
||||
for (const layer of items) {
|
||||
if (layer.state === PluginState.alpha && !hasAlphaPanels) {
|
||||
continue;
|
||||
}
|
||||
const opt = { label: layer.name, value: layer.id, description: layer.description };
|
||||
res.options.push(opt);
|
||||
if (layer.id === current) {
|
||||
res.current.push(opt);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
export function getLayersOptions(basemap: boolean, current?: string): RegistrySelectInfo {
|
||||
if (basemap) {
|
||||
return getLayersSelection([defaultBaseLayer, ...basemapLayers], current);
|
||||
}
|
||||
return getLayersSelection([...dataLayers, ...basemapLayers], current);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user