MapServer6.4.1教程学习--包含二个图层的静态地图(1-2)

来源:互联网 发布:徐州共享网络 编辑:程序博客网 时间:2024/05/22 07:54

包含二个图层的静态地图

(http://www.mapserver.org/tutorial/example1-2.html#example1-2)


在-第一个例子中,是通过将img标签链接到 http://demo.mapserver.org/cgi-bin/mapserv?map=/osgeo/mapserver/tutorial/htdocs/example1-2.map&layer=states_poly&layer=states_line&mode=map生成的。这也是本章节绝大多数例子的工作方式。

不管怎么说,你会注意到这幅地图和第一个例子是一样的。是的,但是mapfile文件是不一样的。让我们来看一看。

# The annotated mapfile (sort of)

# Created byPericles S. Nacionales for the MapServer tutorial

# 20050408

#

# MapServer mapfile uses the pound sign (#) to denote the start of a line

# comment--eachline that needs to be commented has to be prepended with a "#".

#

# Map files beginwith MAP keyword to signify the start of the map object.

# Well, the entiremap file is THE map object.  Enclosedbetween MAP and END

# at the verybottom of this map file, are keyword/value pairs and other

# objects.

MAP

  IMAGETYPE     PNG

  EXTENT        -97.238976 41.619778 -82.122902 49.385620

  SIZE          400 300

  SHAPEPATH     "/ms4w/apps/tutorial/data"

  IMAGECOLOR    255 255 255

 

  # Layerobjects are defined beneath the map object. You need at least one

  # layer defined in your map file before youcan display a map...  You can

  # define as many layers as you'd likealthough a limit is typically hard-coded

  # in map.h in the MapServer source.  The default limit is set at 100.  You'd

  # have to have a very specialized applicationto need more than 100 layers in

  # your application.

 

  # Start of LAYER DEFINITIONS---------------------------------------------

  LAYER # States polygon layer begins here

    NAME        states_poly

    DATA        states_ugl

    STATUS      OFF

    TYPE        POLYGON

 

    # The class object is defined within thelayer object.  You can define as

    # many classes as you need (well, there arelimits as with layers, but it's

    # senseless to define more than ten on a"normal" layer.  There are

    # situations, however, where you might haveto do it.)

    CLASS

      NAME      "States"

 

      # There are styles in a class, just likethere are classes in a layer,

      # just like there are layers in amap.  You can define multiple styles in

      # a class just as you can define multipleclasses in a layer and multiple

      # layers in a map.

      STYLE

        COLOR   232 232 232

      END

    END

  END # States polygon layer ends here

 

  LAYER # States line layer begins here

    NAME        states_line

    DATA        states_ugl

    STATUS      OFF

    TYPE        LINE

 

    CLASS

      NAME      "State Boundary"

      STYLE

        COLOR   32 32 32

      END

    END

  END # States line layer ends here

  # End of LAYER DEFINITIONS-------------------------------

 

END # All map filesmust come to an end just as all other things must come to...

 

MapFile结构

如下是mapfile的对象结构:

这次我们将原始图层拆分成二个图层。第一层仍是多边形层,但是样式(STYLE)对象不再有轮廓线颜色(OUTINECOLOR),就像如下所示:

LAYER

  ...

  TYPE         POLYGON

  ...

  CLASS

    NAME       "States"

    STYLE

      COLOR    232 232 232

    END

  END

END

第二层类似于第一层,但它的类型(TYPE)变成了线(LINE),样式(STYLE)里面的颜色(COLOR)与第一个例子中的轮廓线颜色(OUTLINECOLOR)一样。这就会产生和第一个例子一样的图像。

LAYER

  ...

  TYPE        LINE

  CLASS

    NAME      "State Boundary"

    STYLE

      COLOR   32 32 32

    END

  END

END

 

那么,为什么要这么做?

如果我们在states层上继续叠加其他层,轮廓线就很可能被这些层覆盖。为了能够在叠加这些层之后还能看到州界,我们就必须要把州界线从州多边形中分离出来,并把它放在其他层之上。这就是我们定义和叠加图层的顺序,这我们本章节接下来的过程中你会更加清楚这一点。

 

PS:中文版权为asswclw所有,请尊重劳动成果,转载将注明出处。

0 0
原创粉丝点击