MapsGL Usage
Layers Control

MapsGL Layers Control

The MapsGLLayersControl component provides an interface for managing map layer visibility and styling through integration with the MapsGL SDK. It supports both individual and grouped layer controls, with built-in functionality for layer styling.

Features

  • Layer visibility management
  • Layer style customization
  • Optional layer grouping with single/multi-select support
  • Integration with MapsGL layer system
  • Built-in style controls

Usage

The component must be used within both MapsGLMapControllerProvider and MapsGLLayersProvider. It expects a config prop that defines the layer structure and options. For detailed configuration options, see the MapsGLLayersProvider documentation.

import { 
    MapsGLLayersControl, 
    MapsGLMapControllerProvider, 
    MapsGLLayersProvider 
    } from '@xweather/map-ui-sdk';
 
const layersConfig = [{
    id: 'radar',
    title: 'Radar',
    selected: true,
    settingsOptions: [{
        name: 'opacity',
        value: 70
    }]
}, {
    title: 'Conditions',
    group: [{
        id: 'temperatures',
        title: 'Temperatures',
        settingsOptions: [{
            name: 'opacity',
            value: 80
        }]
    }]
}];
 
export default function App() {
    return (
        <MapsGLMapControllerProvider>
            <MapsGLLayersProvider>
                <MapsGLLayersControl config={layersConfig} />
            </MapsGLLayersProvider>
        </MapsGLMapControllerProvider>
    );
}

Hooks

MapsGLLayersControl uses several hooks internally to manage layer state and styling. These hooks can be used to build completely custom layer control interfaces:

useLayerControl

Hook for managing individual layer state and styling.

OptionDescriptionDefault
idType: string (required)Unique identifier for the layer
settingsOptionsType: LayerButtonOptionSetting[] ()Array of style control options

Returns:

NameTypeDescription
isActivebooleanCurrent visibility state of the layer
handleToggle() => voidFunction to toggle layer visibility
controlSettingsControlSettings[] | nullProcessed settings for ControlView
settingsStateRecord<string, any>Current state of layer style settings

useLayerGroupControl

Hook for managing grouped layer behavior.

OptionDescriptionDefault
idType: string (required)Unique identifier for the group
optionsType: LayerButtonSegmentOptions[] (required)Array of layer options in the group
multiselectType: boolean ()Whether multiple layers can be activefalse

Returns:

NameTypeDescription
isActivebooleanWhether the layer group is active (this is different than the individual layer active state)
handleToggle() => voidFunction to toggle the entire group
handleOptionClick(optionId: string) => voidFunction to toggle individual layers within the group

useLayersControl

Hook for accessing global layer state through MapsGLLayersProvider.

Returns:

NameTypeDescription
layersRecord<string, LayerState>Global state of all layers
addLayer(layerId: string) => voidFunction to add a new layer to the map
removeLayer(layerId: string) => voidFunction to remove a layer from the map
toggleLayer(layerId: string) => voidFunction to toggle layer visibility
updateLayerSetting(layerId: string, setting: ValuePayload) => voidFunction to update layer style settings
hideModal() => voidFunction to hide the settings modal

Related Components

  • MapsGLLayersProvider: Manages global layer state and MapsGL integration
  • ControlView: Renders layer style controls