OpenLayers 3 Beginner’s Guide

Changing layer properties

Open sample in a new windows

<!doctype html>
<html>
  <head>
    <title>Simple example</title>
    <link rel="stylesheet" href="../assets/ol3/css/ol.css" type="text/css" />
    <link rel="stylesheet" href="../assets/css/samples.css" type="text/css" />
  </head>
  <body>
    <div id="map" class="map"></div>
    <script src="../assets/ol3/js/ol.js"></script>
    <script>
        var osmLayer = new ol.layer.Tile({
          source: new ol.source.OSM(),
          opacity: 0.6,
          brightness: 0.2
        });

        var view = new ol.View({
          center: ol.proj.transform([-1.8118500054456526, 52.4431409750608], 'EPSG:4326', 'EPSG:3857'),
          zoom: 6
        });

        var map = new ol.Map({
          target: 'map'
        });

        map.addLayer(osmLayer);
        map.setView(view);
        /*
        console.log(osmLayer.getSource());
        osmLayer.setProperties({opacity: 0.4, contrast:0.6});
        console.log(osmLayer.get('contrast'));
        console.log(osmLayer.get('opacity'));
        osmLayer.setProperties({opacity: 0.7, contrast:0.3});
        console.log(osmLayer.getOpacity());
        console.log(osmLayer.getContrast());
        osmLayer.set('opacity',1);
        osmLayer.setContrast(1);
        osmLayer.setBrightness(0);
        osmLayer.set('myId', 'myUnique');
        console.log(osmLayer.get('myId'));
        */
    </script>
  </body>
</html>