1 <html xmlns="http://www.w3.org/1999/xhtml">
3 <title>OpenLayers Layer Opacity Example</title>
4 <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
5 <link rel="stylesheet" href="style.css" type="text/css" />
6 <style type="text/css">
8 font-family: sans-serif;
14 text-decoration: none;
23 font-family: sans-serif;
24 background: transparent;
33 <script src="../lib/OpenLayers.js"></script>
34 <script type="text/javascript">
39 function changeOpacity(byOpacity) {
40 var newOpacity = (parseFloat(OpenLayers.Util.getElement('opacity').value) + byOpacity).toFixed(1);
41 newOpacity = Math.min(maxOpacity,
42 Math.max(minOpacity, newOpacity));
43 OpenLayers.Util.getElement('opacity').value = newOpacity;
44 shade.setOpacity(newOpacity);
48 maxExtent: new OpenLayers.Bounds(-110.994, 45.885, -110.950, 45.929),
51 map = new OpenLayers.Map('map', options);
52 var drg = new OpenLayers.Layer.WMS("Topo Maps",
53 "http://terraservice.net/ogcmap.ashx",
55 shade = new OpenLayers.Layer.WMS("Shaded Relief",
56 "http://gisdata.usgs.gov/wmsconnector/com.esri.wms.Esrimap?ServiceName=USGS_EDC_Elev_NED_3",
57 {layers: "HR-NED.IMAGE", reaspect: "false", transparent: 'true'},
58 {isBaseLayer: false, opacity: 0.3});
59 map.addLayers([drg, shade]);
60 map.addControl(new OpenLayers.Control.LayerSwitcher());
61 map.zoomToMaxExtent();
65 <body onload="init()">
66 <h1 id="title">Layer Opacity Example</h1>
71 Demonstrate a change in the opacity for an overlay layer.
74 <div id="map" class="smallmap"></div>
78 Note that if you also have the setOpacity method defined on the Layer
79 class, you can tweak the layer opacity after it has been added to the map.
82 <a title="decrease opacity" href="javascript: changeOpacity(-0.1);"><<</a>
83 <input id="opacity" type="text" value="0.3" size="3" disabled="true" />
84 <a title="increase opacity" href="javascript: changeOpacity(0.1);">>></a>
86 <p class="note">IE users: Wait until the shade layer has finished loading to try this.</p>