diff --git a/conf/defaults.ini b/conf/defaults.ini index 6a837319248..02cf623ec45 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -1011,3 +1011,10 @@ default_timezone = browser [expressions] # Enable or disable the expressions functionality. enabled = true + +[geomap] +# Set the default base layer in GeoMaps plugin +default_baselayer = + +# Enable or disable loading other base map layers +disable_custom_baselayers = false diff --git a/conf/sample.ini b/conf/sample.ini index 0cb73f926f8..ca48ae27a99 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -991,3 +991,10 @@ [expressions] # Enable or disable the expressions functionality. ;enabled = true + +[geomap] +# Set the default base layer in GeoMaps plugin +;default_baselayer = + +# Enable or disable loading other base map layers +;disable_custom_baselayers = false diff --git a/docs/sources/administration/configuration.md b/docs/sources/administration/configuration.md index 0b4184ec620..9b9ab0b9452 100644 --- a/docs/sources/administration/configuration.md +++ b/docs/sources/administration/configuration.md @@ -1672,3 +1672,26 @@ Used as the default time zone for user preferences. Can be either `browser` for ### enabled Set this to `false` to disable expressions and hide them in the Grafana UI. Default is `true`. + +## [geomap] + +This section controls the defaults settings for Geomap Plugin. + +### default_baselayer + +The json config used to define the default base map. Four base map options to choose from are `carto`, `esriXYZTiles`, `xyzTiles`, `standard`. +For example, to set cartoDB light as the default base layer: + +```ini +geomap_default_baselayer = `{ + "type": "carto", + "config": { + "theme": "light", + "showLabels": true + } + }` +``` + +### disable_custom_baselayers + +Set this to `true` to disable loading other custom base maps and hide them in the Grafana UI. Default is `false`. \ No newline at end of file diff --git a/packages/grafana-data/src/types/config.ts b/packages/grafana-data/src/types/config.ts index bf8601b445f..e28bd2455da 100644 --- a/packages/grafana-data/src/types/config.ts +++ b/packages/grafana-data/src/types/config.ts @@ -3,6 +3,7 @@ import { PanelPluginMeta } from './panel'; import { GrafanaTheme } from './theme'; import { SystemDateFormatSettings } from '../datetime'; import { GrafanaTheme2 } from '../themes'; +import { MapLayerOptions } from '../geo/layer'; /** * Describes the build information that will be available via the Grafana configuration. @@ -125,4 +126,6 @@ export interface GrafanaConfig { dateFormats?: SystemDateFormatSettings; sentry: SentryConfig; customTheme?: any; + geomapDefaultBaseLayer?: MapLayerOptions; + geomapDisableCustomBaseLayer?: boolean; } diff --git a/pkg/api/frontendsettings.go b/pkg/api/frontendsettings.go index c2d68b25a7b..084fc567843 100644 --- a/pkg/api/frontendsettings.go +++ b/pkg/api/frontendsettings.go @@ -259,6 +259,8 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *models.ReqContext) (map[string]i "caching": map[string]bool{ "enabled": hs.Cfg.SectionWithEnvOverrides("caching").Key("enabled").MustBool(true), }, + "geomapDefaultBaseLayer": hs.Cfg.DefaultBaseLayer, + "geomapDisableCustomBaseLayer": hs.Cfg.DisableCustomBaseLayers, } return jsonObj, nil diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index af268d0d728..13cce7cba71 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -5,6 +5,7 @@ package setting import ( "bytes" + "encoding/json" "errors" "fmt" "net/http" @@ -400,6 +401,10 @@ type Cfg struct { // Grafana.com URL GrafanaComURL string + + // Geomap plugin tile server + DefaultBaseLayer map[string]interface{} + DisableCustomBaseLayers bool } // IsLiveConfigEnabled returns true if live should be able to save configs to SQL tables @@ -966,6 +971,18 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error { ConnStr: connStr, } + geomapSection := iniFile.Section("geomap") + basemapJSON := valueAsString(geomapSection, "default_baselayer", "") + cfg.DefaultBaseLayer = make(map[string]interface{}) + if basemapJSON != "" { + err = json.Unmarshal([]byte(basemapJSON), &cfg.DefaultBaseLayer) + if err != nil { + cfg.Logger.Error(fmt.Sprintf("Error parsing JSON string: %s", err)) + cfg.DefaultBaseLayer = nil + } + } + cfg.DisableCustomBaseLayers = geomapSection.Key("disable_custom_baselayers").MustBool(false) + cfg.readDateFormats() cfg.readSentryConfig()