# GeoExt

### Navigation

- GeoExt »
- API Reference »
- Widgets »
- `GeoExt.LayerOpacitySlider`

# `GeoExt.LayerOpacitySlider`

Extends
  - Ext.slider.SingleSlider
xtype
  `gx_opacityslider`

class `GeoExt.``LayerOpacitySlider`(config)
  Create a slider for controlling a layer’s opacity.

## Example Use

Sample code to render a slider outside the map viewport:

    var slider = new GeoExt.LayerOpacitySlider({
        renderTo: document.body,
        width: 200,
        layer: layer
    });

Sample code to add a slider to a map panel:

    var layer = new OpenLayers.Layer.WMS(
        "Global Imagery",
        "http://maps.opengeo.org/geowebcache/service/wms",
        {layers: "bluemarble"}
    );
    var panel = new GeoExt.MapPanel({
        renderTo: document.body,
        height: 300,
        width: 400,
        map: {
            controls: [new OpenLayers.Control.Navigation()]
        },
        layers: [layer],
        extent: [-5, 35, 15, 55],
        items: [{
            xtype: "gx_opacityslider",
            layer: layer,
            aggressive: true,
            vertical: true,
            height: 100,
            x: 10,
            y: 20
        }]
    });

## Config Options

Configuration properties in addition to those listed for Ext.slider.SingleSlider.

`aggressive`
  `Boolean` If set to true, the opacity is changed as soon as the thumb is moved. Otherwise when the thumb is released (default).

`changeVisibility`
  `Boolean` If set to true, the layer’s visibility is handled by the slider, the slider makes the layer invisible when its value is changed to the min value, and makes the layer visible again when its value goes from the min value to some other value. The layer passed to the constructor must be visible, as its visibility is fully handled by the slider. Defaults to false.

`changeVisibilityDelay`
  `Number` Time in milliseconds before changing the layer’s visibility. If the value changes again within that time, the layer’s visibility change does not occur. Only applicable if changeVisibility is true. Defaults to 5.

`complementaryLayer`
  `OpenLayers.Layer` or `GeoExt.data.LayerRecord` If provided, a layer that will be made invisible (its visibility is set to false) when the slider value is set to its max value. If this slider is used to fade visibility between to layers, setting `complementaryLayer` and `changeVisibility` will make sure that only visible tiles are loaded when the slider is set to its min or max value. (optional)

`delay`
  `Number` Time in milliseconds before setting the opacity value to the layer. If the value change again within that time, the original value is not set. Only applicable if aggressive is true.

`inverse`
  `Boolean` If true, we will work with transparency instead of with opacity. Defaults to false.

`layer`
  `OpenLayers.Layer` or `GeoExt.data.LayerRecord` The layer this slider changes the opacity of. (required)

`value`
  `Number` The value to initialize the slider with. This value is taken into account only if the layer’s opacity is null. If the layer’s opacity is null and this value is not defined in the config object then the slider initializes it to the max value.

## Public Methods

Public methods in addition to those listed for Ext.slider.SingleSlider.

`LayerOpacitySlider.``setLayer`()

  Parameter: | layer – `OpenLayers.Layer` or `GeoExt.data.LayerRecord`

  Bind a new layer to the opacity slider.

### Navigation

- index
- modules |
- next |
- previous |
- GeoExt »
- API Reference »
- Widgets »
- `GeoExt.LayerOpacitySlider`