I am trying to use checkboxes for DEM, roads, streams in GeoServer. I want to turn off/on these layers using checkboxes in JavaScript. How can I do that?
<html>
<head>
<script>
var x1=589980.0;
var y1=4913700.0;
var x2=609000.0;
var y2=4928010.0;
var newx1=x1;
var newy1=y1;
var newx2=x2;
var newy2=y2;
var mapFirstPart = "http://localhost:8080/geoserver/wms?service=WMS&version=1.1.0&request=GetMap&layers=";
var mapLayers = "sf:sfdem," + "sf:roads," + "sf:streams";
var mapBBOX = "&bbox=" + newx1 + "," + newy1 + "," + newx2 + "," + newy2;
var mapSecondPart = "&width=700&height=500&srs=EPSG:26713&format=image/jpeg";
var mapString = mapFirstPart + mapLayers + mapBBOX + mapSecondPart;
var layers=[mapLayers];
function onLOAD()
{
imgMap.src = mapString;
}
function zoom_e(){
newx1=x1;
newy1=y1;
newx2=x2;
newy2=y2;
mapBBOX = "&bbox=" + newx1 + "," + newy1 + "," + newx2 + "," + newy2;
mapString = mapFirstPart + mapLayers + mapBBOX + mapSecondPart;
imgMap.src = mapString;
}
function zoom_in(){
newx1=newx1+((newx2-newx1)/4);
newy1=newy1+((newy2-newy1)/4);
newx2=newx2-((newx2-newx1)/4);
newy2=newy2-((newy2-newy1)/4);
mapBBOX = "&bbox=" + newx1 + "," + newy1 + "," + newx2 + "," + newy2;
mapString = mapFirstPart + mapLayers + mapBBOX + mapSecondPart;
imgMap.src = mapString;
}
function zoom_out(){
newx1=newx1-((newx2-newx1)/4);
newy1=newy1-((newy2-newy1)/4);
newx2=newx2+((newx2-newx1)/4);
newy2=newy2+((newy2-newy1)/4);
mapBBOX = "&bbox=" + newx1 + "," + newy1 + "," + newx2 + "," + newy2;
mapString = mapFirstPart + mapLayers + mapBBOX + mapSecondPart;
imgMap.src = mapString;
}
function pan_l(){
newx1=newx1+((newx2-newx1)/4);
newx2=newx2+((newx2-newx1)/4);
mapBBOX = "&bbox=" + newx1 + "," + newy1 + "," + newx2 + "," + newy2;
mapString = mapFirstPart + mapLayers + mapBBOX + mapSecondPart;
imgMap.src = mapString;
}
function pan_r(){
newx1=newx1-((newx2-newx1)/4);
newx2=newx2-((newx2-newx1)/4);
mapBBOX = "&bbox=" + newx1 + "," + newy1 + "," + newx2 + "," + newy2;
mapString = mapFirstPart + mapLayers + mapBBOX + mapSecondPart;
imgMap.src = mapString;
}
function pan_u(){
newy1=newy1-((newy2-newy1)/4);
newy2=newy2-((newy2-newy1)/4);
mapBBOX = "&bbox=" + newx1 + "," + newy1 + "," + newx2 + "," + newy2;
mapString = mapFirstPart + mapLayers + mapBBOX + mapSecondPart;
imgMap.src = mapString;
}
function pan_d(){
newy1=newy1+((newy2-newy1)/4);
newy2=newy2+((newy2-newy1)/4);
mapBBOX = "&bbox=" + newx1 + "," + newy1 + "," + newx2 + "," + newy2;
mapString = mapFirstPart + mapLayers + mapBBOX + mapSecondPart;
imgMap.src = mapString;
}
function is_checked(){
if (document.getElementById("dem").checked == true) {
mapLayers='sf:sfdem';
console.log("DEM Loaded!") }
else{
mapLayers='sf:roads,'+'sf:streams,'
}
if (document.getElementById("roads").checked == true) {
mapLayers='sf:roads,';
console.log("Roads Loaded!")
}
else{
mapLayers='sf:sfdem,'+'sf:streams,';
}
if (document.getElementById("streams").checked == true) {
mapLayers='sf:streams,';
console.log("Streams Loaded!") }
else{
mapLayers='sf:sfdem,'+'sf:roads,';
}
return mapLayers;
}
function refresh(){
location.reload();
}
function help(){
window.open(help.html);
}
</script>
</head>
<body onLoad="onLOAD();">
<table>
<tr align='center'>
<td width="130px"> </td>
<td> <img src="icons\zoom_extent.jpg" id="zoom_e" onclick="zoom_e()">
<img src="icons\zoom_in.jpg" id="zoom_in" onclick="zoom_in()">
<img src="icons\zoom_out.jpg" id="zoom_out" onclick="zoom_out()">
<img src="icons\pan_left.jpg" id="Pan_Left" onClick="pan_l();">
<img src="icons\pan_right.jpg" id="Pan_right" onClick="pan_r();">
<img src="icons\pan_up.jpg" id="Pan_up" onClick="pan_u();">
<img src="icons\pan_down.jpg" id="Pan_down" onClick="pan_d();">
<img src="icons\help.jpg" id="help" onclick="help();">
</td>
</tr>
<tr>
<td width="130px">
<div class="col-sm-4">
<div class="row">
<div class="span2">
<div id="info_check" style="height:400px"><label>Layers</label></div>
<input type="checkbox" id="dem" value="dem" onclick="is_checked()">DEM
<input type="checkbox" id="roads" value="roads" onclick="is_checked()">Roads
<input type="checkbox" id="streams" value="streams" onclick="is_checked()">Streams
</div>
</div>
</div>
<br><input type="button" name="Refresh" value="Refresh" onclick="refresh()">
</td>
<td width = "800px"><img name='imgMap' src ='' /> </td>
</tr>
</TABLE>
</body>
</html>