Example 1.2

Static Map with Two Layers

https://demo.mapserver.org/cgi-bin/mapserv?map=/mapserver/apps/tutorial/htdocs/example1-2.map&layer=states_poly&layer=states_line&mode=map

As in the first example, this image was generated by linking the source of the <img> tag to this URL: https://demo.mapserver.org/cgi-bin/mapserv?map=/mapserver/apps/tutorial/htdocs/example1-2.map&layer=states_poly&layer=states_line&mode=map. This is how most of the examples in this section work.

Anyway, you'll notice that the map here is the same as the first example. Yes, but the mapfile is different. Have a look.

This is what the mapfile looks like: Example1-2.map

MapFile Structure

The mapfile structure, by objects, looks like this:

           MAP
      LAYER-|-LAYER
   CLASS-|     |-CLASS
STYLE-|           |-STYLE

Here we split the original layer into two layers. The first layer is still a polygon layer but the STYLE object no longer has OUTLINECOLOR, such as:

LAYER
  ...
  TYPE         POLYGON
  ...
  CLASS
    NAME       "States"
    STYLE
      COLOR    232 232 232
    END
  END
END

The second layer is similar to the first except that the TYPE is changed to LINE and the COLOR in the STYLE is changed to the same color as the OUTLINECOLOR in the first example. This produces the same image as the first one.

LAYER
  ...
  TYPE         LINE
  CLASS
    NAME       "State Boundary"
    STYLE
      COLOR    32 32 32
    END
  END
END

So, why do it this way?

If we continue to add layers on top of the states layer, the outline will most likely be covered up by these other layers. To still see the state boundaries after we add these other layers, we have to separate the states boundary line layer from the states polygon layer and put it on top of the other other layers. There is order in how we define/add layers and you'll see it clearly as we proceed in this section.


Back to Example 1.1 | Proceed to Example 1.3