2.5. Static map with two layers#
In this example, the image is generated to the source of the URL
Most traditional MapServer examples are shown in this way.
This example is slightly different from the previous one, where the color of the polygon has been modified.
First take a look at the MapFile that this example uses
This Mapfile defines two layers:
1MAP 2 IMAGETYPE "PNG" 3 EXTENT -180 -90 180 90 4 SIZE 600 300 5 SHAPEPATH "/gdata" 6 IMAGECOLOR 255 255 255 7 LAYER 8 NAME "world-country" 9 DATA "wcountry.shp" 10 STATUS OFF 11 TYPE POLYGON 12 CLASS 13 NAME "States" 14 STYLE 15 COLOR 232 232 232 16 END 17 END 18 END 19 LAYER 20 NAME "country-line" 21 DATA "wcountry.shp" 22 STATUS OFF 23 TYPE LINE 24 CLASS 25 NAME "State Boundary" 26 STYLE 27 COLOR 132 132 32 28 END 29 END 30 END 31END
It’s important to remember that MapServer’s render layers are in the order they are specified in the mapfile. The last layer in the Mapfile is the top layer of the map rendering result, building the map on top of all the previous layers. This means that details shown earlier in the Mapfile (ie, lower layers in the map image) may be obscured. This is most important when rendering polygon layers, since polygons can be filled with a specified color. If the map server renders a point layer (that is, for example, the location of a city), then the render state represents a polygon layer, and the city will not be visible unless the specified polygon layer color is transparent.
This problem is easily remedied by defining the polygon layer in front.
Polygons can also be rendered as a series of lines (ie, a line layer).
Since a line is one-dimensional, there is no area to fill, so the
details of the layers below are still visible. When there is no fill
color, the specified color is:
-1,-1,-1, which can also achieve the
effect of transparency.
The structure of MapFile looks like this:
MAP LAYER CLASS STYLE LAYER CLASS STYLE
Compared to the previous Mapfile, the changes are as follows:
Open the file:diff_mfa2_mfa1.html
Here, the original layer is divided into two layers. The first layer is
still a polygon layer, but there is no
OUTLINECOLOR attribute in the
style anymore. The
TYPE of the second layer is
LINE and the
color value is different from the
OUTLINECOLOR in the first example.
This produces a slightly different image from the first example.
Here is an explanation of why this is done. If we continue to add layers on top of the state layer, the contours are most likely to be masked by these layers. To be able to see the borders and add other layers, we have to separate the borders layer from the state polygon layer and place it on top of the other other layers. There is an order in how to define/add layers, which will be explained later. Here you just need to remember according to “Later on top” (layers defined later will be displayed on the top).