Use the WMS function of geoserver to publish a map (multiple layers)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.