@ -1,14 +1,13 @@
import { get as lodashGet , isEqual } from 'lodash' ;
import { get as lodashGet , isEqual } from 'lodash' ;
import { FrameGeometrySourceMode , MapLayerOptions , MapLayerRegistryItem , PluginState } from '@grafana/data' ;
import { FrameGeometrySourceMode , MapLayerOptions } from '@grafana/data' ;
import { NestedPanelOptions , NestedValueAccess } from '@grafana/data/src/utils/OptionsUIBuilders' ;
import { NestedPanelOptions , NestedValueAccess } from '@grafana/data/src/utils/OptionsUIBuilders' ;
import { hasAlphaPanels } from 'app/core/config' ;
import { setOptionImmutably } from 'app/features/dashboard/components/PanelEditor/utils' ;
import { setOptionImmutably } from 'app/features/dashboard/components/PanelEditor/utils' ;
import { addLocationFields } from 'app/features/geo/editor/locationEditor' ;
import { addLocationFields } from 'app/features/geo/editor/locationEditor' ;
import { FrameSelectionEditor } from '../layers/data/FrameSelectionEditor' ;
import { FrameSelectionEditor } from '../layers/data/FrameSelectionEditor' ;
import { defaultMarkersConfig } from '../layers/data/markersLayer' ;
import { defaultMarkersConfig } from '../layers/data/markersLayer' ;
import { DEFAULT_BASEMAP_CONFIG , geomapLayerRegistry } from '../layers/registry' ;
import { DEFAULT_BASEMAP_CONFIG , geomapLayerRegistry , getLayersOptions } from '../layers/registry' ;
import { MapLayerState } from '../types' ;
import { MapLayerState } from '../types' ;
export interface LayerEditorOptions {
export interface LayerEditorOptions {
@ -62,11 +61,11 @@ export function getLayerEditor(opts: LayerEditorOptions): NestedPanelOptions<Map
const { handler , options } = opts . state ;
const { handler , options } = opts . state ;
const layer = geomapLayerRegistry . getIfExists ( options ? . type ) ;
const layer = geomapLayerRegistry . getIfExists ( options ? . type ) ;
const layerTypes = geomapLayerRegistry . selectOptions (
const layerTypes = getLayersOptions (
opts . basemaps ,
options ? . type // the selected value
options ? . type // the selected value
? [ options . type ] // as an array
? options . type
: [ DEFAULT_BASEMAP_CONFIG . type ] ,
: DEFAULT_BASEMAP_CONFIG . type
opts . basemaps ? baseMapFilter : dataLayerFilter
) ;
) ;
builder . addSelect ( {
builder . addSelect ( {
@ -103,11 +102,19 @@ export function getLayerEditor(opts: LayerEditorOptions): NestedPanelOptions<Map
if ( handler . registerOptionsUI ) {
if ( handler . registerOptionsUI ) {
handler . registerOptionsUI ( builder ) ;
handler . registerOptionsUI ( builder ) ;
}
}
if ( layer . showOpacity ) {
// TODO -- add opacity check
}
if ( ! isEqual ( opts . category , [ 'Base layer' ] ) ) {
if ( ! isEqual ( opts . category , [ 'Base layer' ] ) ) {
if ( ! layer . hideOpacity ) {
builder . addSliderInput ( {
path : 'opacity' ,
name : 'Opacity' ,
defaultValue : 1 ,
settings : {
min : 0 ,
max : 1 ,
step : 0.1 ,
} ,
} ) ;
}
builder . addBooleanSwitch ( {
builder . addBooleanSwitch ( {
path : 'tooltip' ,
path : 'tooltip' ,
name : 'Display tooltip' ,
name : 'Display tooltip' ,
@ -118,23 +125,3 @@ export function getLayerEditor(opts: LayerEditorOptions): NestedPanelOptions<Map
} ,
} ,
} ;
} ;
}
}
function baseMapFilter ( layer : MapLayerRegistryItem ) : boolean {
if ( ! layer . isBaseMap ) {
return false ;
}
if ( layer . state === PluginState . alpha ) {
return hasAlphaPanels ;
}
return true ;
}
export function dataLayerFilter ( layer : MapLayerRegistryItem ) : boolean {
if ( layer . isBaseMap ) {
return false ;
}
if ( layer . state === PluginState . alpha ) {
return hasAlphaPanels ;
}
return true ;
}