Build a map with multiple layers

MapServer builds maps by stacking layers together. On every render, it is placed at the top of the stack. Each layer displays features selected from a single dataset. Features to display can be selected using Unix regular expressions, string comparisons and logical expressions. You can think of layers as topics due to the similarity of data and the similarity of style parameters such as scale, color, and labels. The display of layers is under interactive control, allowing the user to select which layers to render. While it is not possible to generate layers dynamically, it is possible to populate empty layers with dynamic data and manipulate them via URL.

View examples

To make the map richer, continue adding new data (river data) using a new LAYER object. The definitions of each layer are relatively independent and have nothing to do with each other.

Here is the map file(mfml2.map):

01 MAP
02     IMAGETYPE "PNG"
03     EXTENT -180 -90 180 90
04     SIZE 600 300
05     SHAPEPATH "/gdata"
06     IMAGECOLOR 255 255 255
07     FONTSET "../fonts/fonts.list"
08     LAYER
09         NAME "states_poly"
10         DATA "wcountry.shp"
11         STATUS OFF
12         TYPE POLYGON
13         LABELITEM "NAME"
14         CLASS
15             NAME "States"
16             STYLE
17                 COLOR 232 232 232
18             END
19         END
20     END
21     LAYER
22         NAME "states_line"
23         DATA "wcountry.shp"
24         STATUS OFF
25         TYPE LINE
26         CLASS
27             NAME "State Boundary"
28             STYLE
29                 COLOR 132 132 32
30             END
31         END
32     END
33     LAYER
34         NAME "wroads"
35         DATA "wroads.shp"
36         STATUS OFF
37         TYPE LINE
38         CLASS
39             NAME "World Road"
40             STYLE
41                 COLOR 100 200 100
42             END
43         END
44     END
45     LAYER
46         NAME "wriver"
47         DATA "wriver.shp"
48         STATUS OFF
49         TYPE LINE
50         CLASS
51             NAME "World River"
52             STYLE
53                 COLOR 0 0 255
54             END
55         END
56     END
57 END

The roads layer map ( wroads ) is also defined in the Mapfile above and this layer is further added to the map below.

Order of layers

Pay attention to the order of the layers. In this map, the river layer is above the road, which is inconsistent with the usual mapping principles. Usually, the road layer is placed above the river layer.

Swap the position when passing parameters, the effect is as follows, you can see that it is the same as the map above. The order of the layers defined in the Mapfile cannot be changed by passing parameters to the URL.

If you want to modify the order of layers, you can only modify it in the Mapfile:

01 MAP
02     IMAGETYPE "PNG"
03     EXTENT -180 -90 180 90
04     SIZE 600 300
05     SHAPEPATH "/gdata"
06     IMAGECOLOR 255 255 255
07     FONTSET "../fonts/fonts.list"
08     LAYER
09         NAME "states_poly"
10         DATA "wcountry.shp"
11         STATUS OFF
12         TYPE POLYGON
13         LABELITEM "NAME"
14         CLASS
15             NAME "States"
16             STYLE
17                 COLOR 232 232 232
18             END
19         END
20     END
21     LAYER
22         NAME "states_line"
23         DATA "wcountry.shp"
24         STATUS OFF
25         TYPE LINE
26         CLASS
27             NAME "State Boundary"
28             STYLE
29                 COLOR 132 132 32
30             END
31         END
32     END
33     LAYER
34         NAME "wriver"
35         DATA "wriver.shp"
36         STATUS OFF
37         TYPE LINE
38         CLASS
39             NAME "World River"
40             STYLE
41                 COLOR 0 0 255
42             END
43         END
44     END
45     LAYER
46         NAME "wroads"
47         DATA "wroads.shp"
48         STATUS OFF
49         TYPE LINE
50         CLASS
51             NAME "World Road"
52             STYLE
53                 COLOR 100 200 100
54             END
55         END
56     END
57 END

You can see that although it is not obvious, the river layer is below the road layer.