Geomaps: Add default base layer (#37043)

This commit is contained in:
Eunice Kim 2021-07-21 10:20:30 -07:00 committed by GitHub
parent 3b0d7fc00b
commit 02b5a18da2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 15 deletions

View File

@ -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';

View 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);
},
};

View File

@ -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',
};

View File

@ -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,

View File

@ -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'],