Layer group name: laytest (can be started as needed)
Topp: bou2 and Topp: The Map Data (two layers) retrieved by the geoserver connected to the MySQL database)
After submission, you can view the map on the mapbuiler client.
1. Use JavaCodeCall a MAP released using WMS (layers are selectable)
Page code:
Code
<! Doctype HTML public " -// W3C // dtd html 4.01 transitional // en " >
< Html >
< Head >
< Title > Call the layer released by geoserver (you can select a layer) </ Title >
< Style Type = " Text/CSS " >
# Map {
Width: 800px;
Height: pixel PX;
Border: 1px solid black;
}
</ Style >
< Script SRC = " Http: // localhost: 8080/geoserver/openlayers. js "
Type = " Text/JavaScript " >
</ Script >
< Script Type = " Text/JavaScript " >
VaR map;
Function Init (){
Map = New Openlayers. Map ( ' Map ' );
VaR options = {Numzoomlevels: 3 };
VaR graphic = New Openlayers. layer. WMS ( " Layer 1 " ,
" HTTP: /localhost: 8080/geoserver/WMS " ,
{Layers: " Topp: bou2 " }, Options );
VaR jpl_wms = New Openlayers. layer. WMS ( " Layer 2 " ,
" HTTP: /localhost: 8080/geoserver/WMS " ,
{Layers: " Topp: bou2p " }, Options );
Map. addlayers ([graphic, jpl_wms]);
Map. addcontrol ( New Openlayers. Control. layerswitcher ());
Map. zoomtomaxextent ();
}
</ Script >
</ Head >
< Body onload = " Init () " >
< Div ID = " Map " > </ Div >
</ Body >
</ Html >
2. Use Java code to call a MAP released using WMS (no layer is selected)
Code
<! Doctype HTML public " -// W3C // dtd html 4.01 transitional // en " >
< Html >
< Head >
< Title > Call the layer released by geoserver </ Title >
< Style Type = " Text/CSS " >
# Map {
Width: 800px;
Height: pixel PX;
Border: 1px solid black;
}
</ Style >
< Script SRC = " Http: // localhost: 8080/geoserver/openlayers. js "
Type = " Text/JavaScript " >
</ Script >
< Script Type = " Text/JavaScript " >
VaR map;
Function Init (){
Map = New Openlayers. Map ( ' Map ' , Options );
VaR options = {
Controls :[ New Openlayers. Control. keyboarddefaults ()]
};
VaR WMS = New Openlayers. layer. WMS ( " Layer " ,
" HTTP: /localhost: 8080/geoserver/WMS " ,
{Layers: " Laytest " }, Options );
Map. addlayer (WMS );
Map. zoomtomaxextent ();
}
</ Script >
</ Head >
< Body onload = " Init () " >
< Div ID = " Map " > </ Div >
</ Body >
</ Html >
The following is an example of calling Google map and calling geoserver to use WMS to publish a map.
/Files/ycsfwhh/openlayertest.rar