Patch from #674, approved by SDE, plus an example.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@3285 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
46
examples/layerswitcher.html
Normal file
46
examples/layerswitcher.html
Normal file
@@ -0,0 +1,46 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<style type="text/css">
|
||||
#map {
|
||||
width: 512px;
|
||||
height: 512px;
|
||||
border: 1px solid black;
|
||||
}
|
||||
</style>
|
||||
<script src="../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
function init(){
|
||||
var map = new OpenLayers.Map('map', { controls: [] });
|
||||
|
||||
map.addControl(new OpenLayers.Control.LayerSwitcher({'div':OpenLayers.Util.getElement('layerswitcher')}));
|
||||
|
||||
var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
|
||||
"http://labs.metacarta.com/wms/vmap0",
|
||||
{layers: 'basic'} );
|
||||
|
||||
var jpl_wms = new OpenLayers.Layer.WMS( "NASA Global Mosaic",
|
||||
"http://wms.jpl.nasa.gov/wms.cgi",
|
||||
{layers: "modis,global_mosaic"});
|
||||
|
||||
var dm_wms = new OpenLayers.Layer.WMS( "DM Solutions Demo",
|
||||
"http://www2.dmsolutions.ca/cgi-bin/mswms_gmap",
|
||||
{layers: "bathymetry,land_fn,park,drain_fn,drainage," +
|
||||
"prov_bound,fedlimit,rail,road,popplace",
|
||||
transparent: "true", format: "image/png" });
|
||||
|
||||
jpl_wms.setVisibility(false);
|
||||
dm_wms.setVisibility(false);
|
||||
|
||||
map.addLayers([ol_wms, jpl_wms, dm_wms]);
|
||||
if (!map.getCenter()) map.zoomToMaxExtent();
|
||||
}
|
||||
// -->
|
||||
</script>
|
||||
</head>
|
||||
<body onload="init()">
|
||||
<h1>OpenLayers Example</h1>
|
||||
<div id="layerswitcher" style="float:right; width: 20em;"></div>
|
||||
<div id="map"></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -99,8 +99,10 @@ OpenLayers.Control.LayerSwitcher.prototype =
|
||||
this.loadContents();
|
||||
|
||||
// set mode to minimize
|
||||
this.minimizeControl();
|
||||
|
||||
if(!this.outsideViewport) {
|
||||
this.minimizeControl();
|
||||
}
|
||||
|
||||
// populate div with current info
|
||||
this.redraw();
|
||||
|
||||
|
||||
@@ -22,6 +22,18 @@
|
||||
t.ok( control.div != null, "draw makes a div" );
|
||||
t.ok( div != null, "draw returns its div" );
|
||||
}
|
||||
function test_Control_LayerSwitcher_outsideViewport (t) {
|
||||
t.plan( 2 );
|
||||
|
||||
map = new OpenLayers.Map('map');
|
||||
control = new OpenLayers.Control.LayerSwitcher({'div':OpenLayers.Util.getElement('layerswitcher')});
|
||||
map.addControl(control);
|
||||
console.log(control.outsideViewport);
|
||||
t.eq(control.div.style.width, "250px", "Div is not minimized when added.");
|
||||
control = new OpenLayers.Control.LayerSwitcher();
|
||||
map.addControl(control);
|
||||
t.eq(control.div.style.width, "0px", "Div is minimized when added.");
|
||||
}
|
||||
|
||||
function test_03_Control_LayerSwitcher_loadContents(t) {
|
||||
|
||||
@@ -110,5 +122,6 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="map" style="width: 1024px; height: 512px;"/>
|
||||
<div id="layerswitcher" style="width:250px; height:256px;" />
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user