Publish a vector layer

Defining a vector layer in a Mapfile

http://webgis.cn/cgi-bin/mapserv?map=/owg/xmfa1.map&layer=world-country&mode=map

Mapserver can create an image and save it to a local directory or directly to the required web browser (as in this example). Note the map above, which is generated by the WebGIS server in the background of the server and then transmitted to the client. The code behind the page is:

<img alt="" border="1"
    src="//drr.ikcest.org/webgis/cgi-bin/mapserv?map=/oswebgis/xmfa1.map&layer=world-country&mode=map"
/>

You can browse it in the HTML page, just enter this URL:

//drr.ikcest.org/webgis/cgi-bin/mapserv?map=/oswebgis/example1-1.map&layer=states&mode=map

(Remember to replace the hostname or IP address; for example, use the local hostname localhost, Or use an IP address directly, such as "127.0.0.1")

01 MAP
02     IMAGETYPE "PNG"
03     EXTENT -180 -90 180 90
04     SIZE 600 300
05     SHAPEPATH "/gdata"
06     IMAGECOLOR 255 255 255
07     LAYER
08         NAME "world-country"
09         DATA "wcountry.shp"
10         STATUS OFF
11         TYPE POLYGON
12         CLASS
13             NAME "The Upper Great Lakes States"
14             STYLE
15                 COLOR 232 232 232
16                 OUTLINECOLOR 32 32 32
17             END
18         END
19     END
20 END

First Mapfile

URL Parameter Description

This URL can be broken down into three parts:

The first part, //drr.ikcest.org/webgis/cgi-bin/mapserv?, calls the CGI program of MapServer. On different systems, it may be mapserv or mapserv.exe, or it may be another name. If you directly call the above URL, you will get this message:

No query information to decode. QUERY_STRING is set, but empty.

To get the right information, you need to add extra parameters.

The next three parts are the query string. The query string contains CGI parameters (variables and their values), each of which is separated by a symbol (&).

Now let's take a look at the query string. The first argument map has a value: /oswebgis/xmfa1.map

This tells MapServer's CGI program to process/parse the map file. Of course the path here is the path on the server.

The next parameter, layer=states, tells mapserv to use the states layer. We named the layer object states in the Mapfile.

The last parameter, mode=map , tells mapserv what to do to output MapFile in mode. In this case, it tells mapserv to dump the image directly to the web browser ( client) without first creating a temporary image on the server.

The value of TYPE can be: 'chart', 'circle', 'line', 'point', 'polygon', 'raster', 'query', 'annotation'.

Map range

In the Mapfile, you need to set the correct scope to display the data. For example, China-wide data, the scope of the setting is: EXTENT 73 8 136 53, The effect is as follows:

The complete Mapfile is:

01 MAP
02     IMAGETYPE "PNG"
03     EXTENT 73 3 136 54
04     SIZE 400 300
05     SHAPEPATH "/gdata"
06     IMAGECOLOR 255 255 255
07     LAYER
08         NAME "china"
09         DATA "China4326"
10         STATUS OFF
11         TYPE POLYGON
12         CLASS
13             NAME "The whole of China"
14             STYLE
15                 COLOR 232 232 232
16                 OUTLINECOLOR 32 32 32
17             END
18         END
19     END
20 END

MapServer View different modes

Notice the mode = map above, which is the view mode supported by MapServer. The CGI variable of MapServer's model can use values other than map. In addition to map mode, there is also browse mode. For example, if you use map = browse , MapServer will dump the image to a temporary directory on the server. Using browse mode, you need to specify template parameters. Generally, we need to define a template file first. Without the template file, the browse mode can not work properly. This will be explained later. In MapServer 6.x, the template parameter allows the use of OpenLayers keywords, and OpenLayers can be used to view the results of MapServer.

The default configuration of OpenLayers is used directly to view the map. Note that you want to call the OpenLayers class library on the MapServer website, so it will be slower for the first time.

//drr.ikcest.org/webgis/cgi-bin/mapserv?map=/oswebgis/xmfa1.map&layer=world-country&mode=browse&template=OpenLayers

For the OpenLayers mode, you can view:

Https://mapserver.org/uk/cgi/openlayers.html .

You can try to modify the value of the keyword in MapFile and see the result. These experiments will help you understand these keywords.