mirror of
https://github.com/grafana/grafana.git
synced 2025-01-26 16:27:02 -06:00
Geomaps: Add default base layer (#37043)
This commit is contained in:
parent
3b0d7fc00b
commit
02b5a18da2
@ -8,6 +8,7 @@ import {
|
||||
GrafanaTheme,
|
||||
GrafanaTheme2,
|
||||
LicenseInfo,
|
||||
MapLayerOptions,
|
||||
PanelPluginMeta,
|
||||
systemDateFormats,
|
||||
SystemDateFormatSettings,
|
||||
@ -87,6 +88,8 @@ export class GrafanaBootConfig implements GrafanaConfig {
|
||||
caching = {
|
||||
enabled: false,
|
||||
};
|
||||
geomapDefaultBaseLayer?: MapLayerOptions;
|
||||
geomapDisableCustomBaseLayer?: boolean;
|
||||
|
||||
constructor(options: GrafanaBootConfig) {
|
||||
const mode = options.bootData.user.lightTheme ? 'light' : 'dark';
|
||||
|
30
public/app/plugins/panel/geomap/layers/basemaps/default.ts
Normal file
30
public/app/plugins/panel/geomap/layers/basemaps/default.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { MapLayerRegistryItem, MapLayerOptions, GrafanaTheme2 } from '@grafana/data';
|
||||
import Map from 'ol/Map';
|
||||
import { carto } from './carto';
|
||||
import { esriXYZTiles } from './esri';
|
||||
import { xyzTiles } from './generic';
|
||||
import { standard } from './osm';
|
||||
import { config } from 'app/core/config';
|
||||
|
||||
// Array of base map options to search through
|
||||
const baseLayers = [carto, esriXYZTiles, xyzTiles, standard];
|
||||
|
||||
// Default base layer depending on the server setting
|
||||
export const defaultBaseLayer: MapLayerRegistryItem = {
|
||||
id: 'default',
|
||||
name: 'Default base layer',
|
||||
isBaseMap: true,
|
||||
|
||||
create: (map: Map, options: MapLayerOptions, theme: GrafanaTheme2) => {
|
||||
// Use Carto as the default base layer if not set from server
|
||||
let layer: any = carto;
|
||||
if (config.geomapDefaultBaseLayer && config.geomapDefaultBaseLayer.type) {
|
||||
options = config.geomapDefaultBaseLayer; // options from server
|
||||
layer = baseLayers.find((baseLayer) => baseLayer.id === options.type);
|
||||
if (!layer) {
|
||||
throw new Error('Invalid default base map type');
|
||||
}
|
||||
}
|
||||
return layer.create(map, options, theme);
|
||||
},
|
||||
};
|
@ -1,11 +1,11 @@
|
||||
import { cartoLayers, carto } from './carto';
|
||||
import { cartoLayers } from './carto';
|
||||
import { esriLayers } from './esri';
|
||||
import { genericLayers } from './generic';
|
||||
import { osmLayers } from './osm';
|
||||
import { defaultBaseLayer } from './default';
|
||||
|
||||
// For now just use carto
|
||||
export const defaultGrafanaThemedMap = {
|
||||
...carto,
|
||||
...defaultBaseLayer,
|
||||
id: 'default',
|
||||
name: 'Default base layer',
|
||||
};
|
||||
|
@ -3,7 +3,7 @@ import Map from 'ol/Map';
|
||||
import OSM from 'ol/source/OSM';
|
||||
import TileLayer from 'ol/layer/Tile';
|
||||
|
||||
const standard: MapLayerRegistryItem = {
|
||||
export const standard: MapLayerRegistryItem = {
|
||||
id: 'osm-standard',
|
||||
name: 'Open Street Map',
|
||||
isBaseMap: true,
|
||||
|
@ -7,6 +7,7 @@ import { defaultView, GeomapPanelOptions } from './types';
|
||||
import { mapPanelChangedHandler } from './migrations';
|
||||
import { defaultGrafanaThemedMap } from './layers/basemaps';
|
||||
import { defaultMarkersConfig } from './layers/data/markersLayer';
|
||||
import { config } from 'app/core/config';
|
||||
|
||||
export const plugin = new PanelPlugin<GeomapPanelOptions>(GeomapPanel)
|
||||
.setNoPadding()
|
||||
@ -33,17 +34,19 @@ export const plugin = new PanelPlugin<GeomapPanelOptions>(GeomapPanel)
|
||||
});
|
||||
|
||||
// Nested
|
||||
builder.addCustomEditor({
|
||||
category: ['Base Layer'],
|
||||
id: 'basemap',
|
||||
path: 'basemap',
|
||||
name: 'Base Layer',
|
||||
editor: BaseLayerEditor,
|
||||
defaultValue: {
|
||||
type: defaultGrafanaThemedMap.id,
|
||||
config: defaultGrafanaThemedMap.defaultOptions,
|
||||
},
|
||||
});
|
||||
if (!config.geomapDisableCustomBaseLayer) {
|
||||
builder.addCustomEditor({
|
||||
category: ['Base Layer'],
|
||||
id: 'basemap',
|
||||
path: 'basemap',
|
||||
name: 'Base Layer',
|
||||
editor: BaseLayerEditor,
|
||||
defaultValue: {
|
||||
type: defaultGrafanaThemedMap.id,
|
||||
config: defaultGrafanaThemedMap.defaultOptions,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
builder.addCustomEditor({
|
||||
category: ['Data Layer'],
|
||||
|
Loading…
Reference in New Issue
Block a user