Вы находитесь на странице: 1из 34

Universidad del Cauca Maestra en Ingeniera, rea Telemtica Facultad de Ingeniera Electrnica y Telecomunicaciones

Sistemas de Informacin Geogrfica 2006

Manejo de Plantillas en MAPSERVER


Profesor: Jos Armando Ordez Crdoba

Objetivo
Conocer el concepto de plantillas de Mapserver. Y la utilidad de las mismas en el desarrollo de aplicaciones con MapServer.

Prerrequisitos
Tener instalada la distribucin binaria de MapServer para Windows, La versin utilizada fue la 2.1 (Julio 20th 2006) descargable desde: http://mapserver.gis.umn.edu/download/current/windows

1. Introduccin
Las plantillas ofrecen interactividad a las aplicaciones Web, ofreciendo a los usuarios la posibilidad de cambiar el contenido del mapa. Una plantilla HTML de mapserver es un archivo HTML con unos tags especficos de Mapserver, estos tags son las variables CGI de Mapserver, estos tags van entre brackets "[]" dentro del documento HTML. El programa CGI de Mapserver procesa la cadena de solicitud y el archivo mapfile y produce la salida necesaria. Parte de la salida necesitar estar escrita en el archivo de plantilla HTML, cuya ruta tambin va incluida en el mapfile con el atributo TEMPLATE. El programa CGI remplaza las variables en la plantilla HTML con los valores adecuados antes de devolverla al browser. Mapserver provee muchas variables para el Web Mapping (la lista completa se puede revisar en http://mapserver.gis.umn.edu/doc/cgi-reference.html ). Tambin se pueden definir variables propias.

2. Controles Pan y Zoom


Para mostrar el mapa se invoca el programa CGI "/cgi-bin/mapserv.exe? y se le pasa el path del mapfile y otros parmetros map=/ms4w/apps/tutorial/htdocs/example2-1.map &mode=browse". As que para llamar la aplicacin necesitamos invocarla con un link con los siguientes parmetros.
<a href="/cgi-bin/mapserv.exe? map=/ms4w/apps/tutorial/htdocs/ejemplo2-1.map &mode=browse&root=/tutorial&program=/cgi-bin/mapserv.exe &map_web_template=ejemplo2-1.html"> Ejemplo 2.1 </a>

Para invocar la prctica creamos un archivo HTML con el siguiente cdigo:


<html> <body> Enlace a los ejercicios: <a href="/cgibin/mapserv.exe?map=c:/ms4w/apps/tutorial/map/ejemplo2.1.map&mode=brow se&root=/tutorial&program=/cgi-bin/mapserv.exe"> Ejemplo 2.1 </a> </html> </body>

La guardamos con el nombre practicas2.html y la guardamos en /ms4w/apps/tutorial/htdocs/ modificaremos este archivo agregando los enlaces con la informacin para invocar cada practica.

Copiamos la carpeta imgenes desde el tutorial hasta la carpeta de nuestra aplicacin

Creamos un archivo con el siguiente cdigo, que ser la plantilla de nuestro mapa.
<html> <head> <title>MapServer Workshop</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-88591"> <link type="text/css" rel="stylesheet" href="/tutorial/ms35.css" /> </head> <body bgcolor="#FFFFFF" text="#000000"> <table width="601" align="center"> <tr> <td width="593"> <h3 align="center">Example 2.1: Zoom and Pan Controls</h3>

<!-- START OF MAPSERVER FORM --> <form name="mapserv" method="GET" action="/cgi-bin/mapserv.exe"> <!-- HIDDEN MAPSERVER CGI VARIABLES --> <input type="hidden" name="map" value="[map]"> <input type="hidden" name="imgext" value="[mapext]"> <input type="hidden" name="imgxy" value="199.5 149.5"> <table width="400" border="0" align="center"> <tr> <td> <table width="400" border="1"> <tr> <td> <!-- SPECIFY MAP MODE --> <div align="center">Map Mode:<br> <select name="mode"> <option value="browse">Browse</option> <option value="map">Map</option> </select> </div> </td> <td> <!-- FORM SUBMIT BUTTON --> <div align="center"> <input type="submit" name="submit" value="Refresh"> </div> </td> <td> <!-- ZOOM/PAN CONTROLS --> <div align="center">Map Control: <br> <select name="zoom"> <option value="4" [zoom_4_select]>Zoom In 4x</option> <option value="3" [zoom_3_select]>Zoom In 3x</option> <option value="2" [zoom_2_select]>Zoom In 2x</option> <option value="1" [zoom_1_select]>Recenter</option> <option value="-2" [zoom_-2_select]>Zoom Out 2x</option> <option value="-3" [zoom_-3_select]>Zoom Out 3x</option> <option value="-4" [zoom_-4_select]>Zoom Out 4x</option> </select> </div> </td> </tr> <tr> <!-- DISPLAY THE MAPSERVER-CREATED MAP IMAGE --> <td colspan="3" align="center" valign="top"> <input type="image" name="img" src="[img]" width="400" height="300" border="0"> </td> </tr> </table> </td> </tr> </table> </form> </td></tr> </table> </body> </html>

Y se guarda con el nombre template2.1.html en la carpeta /ms4w/apps/tutorial/htdocs

En la carpeta map de nuestra aplicacin tutorial, creamos el mapfile ejemplo2.1.map con el siguiente cdigo: MAP NAME EX2_ IMAGETYPE png24 EXTENT 166221 -371954 1505849 632767 # LAEA #EXTENT -97.5 41.619778 -82.122902 49.38562 # Geographic SIZE 400 300 SHAPEPATH "../data" SYMBOLSET "../symbols/symbols35.sym" FONTSET "../fonts/fonts.list" # When changing any of the mapfile parameters via the web interface, you # need to define a TEMPLATEPATTERN. This is required for security reasons. # Since the example filenames in section 2 begin with "example2" (as in # example2-1.html or example2-2.html), you can use it as the pattern. # The template pattern is a regular expression used by MapServer to match the # value of map_web_template variable against. TEMPLATEPATTERN 'example2*'

# The web object is defined at the level below the map object. All # web-related parameters (I interchange "parameters" and "keyword/value # pairs" quite frequently, sorry about that) are defined in this object. WEB TEMPLATE 'c:/ms4w/apps/tutorial/htdocs/template2.1.html' IMAGEPATH 'c:/ms4w/apps/tutorial/htdocs/tmp/ms_tmp/' IMAGEURL '/tutorial/tmp/ms_tmp/' END # Every object in MapServer must have an END.;)

# The projection object is typically used within the map and the layer # objects. You only define it once within the map object and this definition # becomes your output projection--MapServer will render your maps in this # projection. You also use the projection object within the layer object to # define your input projection. Your layers can be in different # projections--MapServer will reproject them into your output projection. # If no projection is defined within the layer object, MapServer assumes # your input projection is the same as your output projection. This is not # a required object unless you're creating a map file that supports one of # the OGC interoperability web services specifications (WMS/WFS/WCS). PROJECTION # Projection parameters can be defined in two ways... # This is the traditional Proj.4 definition of Lambert Azimuthal Equal-Area # projection for the Continental U.S. # "proj=laea" # "ellps=clrk66" # "lat_0=45" # "lon_0=-100"

# # Alternatively, you can specify an EPSG code. # This is the EPSG code for Lambert Azimuthal Equal-Area # projection for the U.S. "init=epsg:2163" END # This is the ending of the output projection # # Start of legend # LEGEND KEYSIZE 12 12 LABEL TYPE BITMAP SIZE MEDIUM COLOR 0 0 89 END STATUS ON END # The reference object is used to define a reference map for your mapping # application. This typically involves defining a small image that covers # the entire area of the map and defining a box that represents the current # view on in relation to the entire area. REFERENCE IMAGE '../images/ugl_ref1.png' # The reference image SIZE 155 105 # The size of the reference image in pixels EXTENT 201621.496941 -294488.285333 1425518.020722 498254.511514 # The extent of the reference image in map units STATUS ON MINBOXSIZE 10 # How small can the reference box be before it gets drawn as a point, in pixels MAXBOXSIZE 150 # The maximum size of the reference box, in pixels COLOR -1 -1 -1 # The reference box fill color, negative numbers mean transparent OUTLINECOLOR 128 0 0 # The reference box outline color MARKERSIZE 8 # The size of the point marker MARKER 'star' # The marker symbol END # A scalebar object is defined one level below the map object. This object # controls how a scalebar is drawn by MapServer. Scalebars can be embedded # in the map itself or can be created as a separate image. It has an # associated MapServer CGI variable called "scalebar" (or [scalebar] when # used in the HTML template). SCALEBAR IMAGECOLOR 255 255 255 LABEL COLOR 0 0 0 SIZE TINY END

STYLE 1 SIZE 100 2 COLOR 0 0 0 UNITS MILES INTERVALS 2 TRANSPARENT FALSE STATUS ON END # Scalebar object ends

# Layer objects, too, are defined beneath the map object. Be mindful of the # order of your layer objects. MapServer "stacks them" in reverse # order--that is, the last layer you define (at the bottom of the map file) # will be drawn on top and the first layer you define (right after this # comment), will be drawn at the bottom. Here's my rule: rasters and # polygons are defined first, followed by the line layers. The point and # annotation layers are defined last. You can play around with the ordering # of your layers until you're satisfied. # Start of LAYER DEFINITIONS --------------------------------------------LAYER # States polygon layer begins here NAME states DATA states_ugl STATUS DEFAULT TYPE POLYGON REQUIRES "![modis] OR ![modis_jpl]" # Here's an example of the input projection definition. # EPSG:4326 is code for geographic (latlong) projection # using the WGS84 datum PROJECTION "init=epsg:4326" END CLASSITEM "CLASS"

# The class object is defined within the layer object. You can define as # many classes as you need (well, there are limits, but it's senseless to # define more than ten on a "normal" layer. There are situations, # however, where you might have to do it.) CLASS EXPRESSION 'land' # There are styles in a class, just like there are classes in a layer, # just like there are layers in a map. STYLE SYMBOL 0 COLOR 232 232 232 END # And they all must come to an end. END # End of this class.

END # States polygon layer ends here LAYER # MODIS raster layer begins here NAME modis DATA "raster/mod09a12003161_ugl_ll_idxa.tif" STATUS OFF TYPE RASTER OFFSITE 70 74 66 #167 151 152 PROJECTION "init=epsg:4326" END END # MODIS raster layer ends here LAYER # MODIS WMS map from JPL (or from USGS) NAME modis_jpl TYPE RASTER OFFSITE 000 STATUS OFF CONNECTIONTYPE WMS CONNECTION "http://wms.jpl.nasa.gov/wms.cgi?" METADATA "wms_srs" "EPSG:4326" "wms_name" "daily_terra" #"global_mosaic" "daily_aqua" "wms_server_version" "1.1.1" "wms_format" "image/jpeg" END PROJECTION "init=epsg:4326" END END # MODIS WMS image ends here LAYER # Hydrography layer begins here NAME hydro TYPE POLYGON STATUS OFF DATA hydrop_ugl PROJECTION "init=epsg:4326" END CLASSITEM 'FEATURE' CLASS NAME 'Lakes' EXPRESSION /(^B|^C|^L|^R)./ STYLE COLOR 72 64 254

END END # CLASS CLASS NAME 'Rivers' EXPRESSION 'Stream' STYLE COLOR 136 128 255 END END # CLASS CLASS NAME 'Wetlands' EXPRESSION 'Swamp or Marsh' STYLE COLOR 195 252 255 OUTLINECOLOR 195 252 255 SYMBOL 'circle' SIZE 0 END END # CLASS END # LAYER LAYER # ROADS LAYER NAME cty_roads GROUP roads TYPE LINE STATUS OFF DATA roads_ugl MAXSCALE 750000 PROJECTION "init=epsg:4326" END CLASSITEM 'CLASS1' CLASS NAME 'Minor Arterial Roads' EXPRESSION '3' STYLE COLOR 165 165 165 END END # CLASS CLASS EXPRESSION '4' STYLE COLOR 210 210 210 END END # CLASS END # ROADS LAYER LAYER # state highways begin here

NAME state_hwy GROUP roads MAXSCALE 1500000 STATUS OFF DATA roads_ugl TYPE LINE FILTERITEM 'CLASS1' FILTER '2' CLASS NAME 'Principal Arterial Roads' STYLE COLOR 255 0 0 SIZE 1 SYMBOL 'circle' END END PROJECTION "init=epsg:4326" END END # highways LAYER # interstate highways begin here NAME interstate GROUP roads # MAXSCALE 22500000 STATUS OFF DATA roads_ugl TYPE LINE FILTERITEM 'CLASS1' FILTER '1' CLASS NAME "Interstate Hwy." STYLE COLOR 128 0 0 END END PROJECTION "init=epsg:4326" END END # highways LAYER # States line layer begins here NAME states DATA states_ugl STATUS OFF TYPE LINE

PROJECTION "init=epsg:4326" END CLASSITEM "CLASS" CLASS NAME 'State Boundary' EXPRESSION 'land' STYLE SYMBOL 'line5' COLOR 32 32 32 SIZE 1 END END END # States line layer ends here LAYER NAME roads_anno GROUP roads MAXSCALE 750000 STATUS OFF DATA roads_ugl TYPE ANNOTATION LABELITEM "SIGN" CLASSITEM "CLASS1" CLASS EXPRESSION "3" STYLE COLOR 0 0 0 # dummy color SYMBOL '../symbols/sthwy.png' END LABEL MINFEATURESIZE 50 MINDISTANCE 150 POSITION CC SIZE TINY COLOR 0 0 0 END END CLASS EXPRESSION "2" STYLE COLOR 0 0 0 # dummy color SYMBOL '../symbols/ushwy.png' END LABEL MINFEATURESIZE 50 MINDISTANCE 150 POSITION CC

SIZE TINY COLOR 0 0 0 END END PROJECTION "init=epsg:4326" END END # highway annotation LAYER NAME roads_anno1 GROUP roads STATUS OFF DATA roads_ugl TYPE ANNOTATION LABELITEM "SIGN" CLASSITEM "CLASS1" CLASS EXPRESSION "1" STYLE COLOR 0 0 0 # dummy color SYMBOL '../symbols/interstate.png' END LABEL MINFEATURESIZE 20 MINDISTANCE 150 POSITION CC SIZE TINY COLOR 255 255 255 END END PROJECTION "init=epsg:4326" END END LAYER # States label layer begins here NAME states DATA states_ugl STATUS OFF TYPE ANNOTATION PROJECTION "init=epsg:4326" END CLASSITEM "CLASS" LABELITEM "STATE" CLASS

EXPRESSION 'land' STYLE COLOR -1 -1 -1 END LABEL COLOR 132 31 31 OUTLINECOLOR 128 128 128 SHADOWCOLOR 218 218 218 SHADOWSIZE 1 1 TYPE TRUETYPE FONT arial-bold SIZE 12 ANTIALIAS TRUE POSITION CL PARTIALS FALSE MINDISTANCE 200 BUFFER 4 END # end of label END # end of class END # States label layer ends here # End of LAYER DEFINITIONS ------------------------------END # end of map file Si vamos a visitar la pgina http://localhost/tutorial/practicas2.html, encontraremos una pgina sencilla con un enlace al mapa.

Si hacemos clic nos encontraremos con un mapa interactivo que permite hacer zoom, refrescar el mapa y seleccionar entre el modo browse y el modo map de solicitud a mapserver.

Utilizamos el modo "browse" en lugar de "map" para consultas con plantillas. El modo browse dice a mapserver que cree una imagen en un directorio /tmp. La ruta de la imagen y el nombre es referenciado por MapServer con el nombre img. La pagina de referencia del Mapfile esta en http://mapserver.gis.umn.edu/doc/mapfile-reference.html y todos los parmetros de las plantillas se pueden obtener en : http://mapserver.gis.umn.edu/doc/template-reference.html

3. Control de capas
En esta parte se puede activar o desactivar capas, para lo cual se pueden utilizar radio buttons, check boxes o mens. El estado de las capas debera estar en OFF en el mapfile para activarlos por otro lado. Nuevamente El mapfile de este ejemplo. Lo guardamos en C:\ms4w\apps\tutorial\map, ejemplo2.2.map:
# The annotated map file (sort of) # Created by Pericles S. Nacionales for the MapServer tutorial # 20050623 # # Map files begin with map keyword to signify the start of the map object. # Well, the entire map file is THE map object. Enclose between MAP and END # at the very bottom of this map file, are keyword/value pairs and other # objects. MAP NAME EX2_ IMAGETYPE png24 EXTENT 166221 -371954 1505849 632767 # LAEA #EXTENT -97.5 41.619778 -82.122902 49.38562 # Geographic SIZE 400 300 SHAPEPATH "../data" SYMBOLSET "../symbols/symbols35.sym" FONTSET "../fonts/fonts.list" # When changing any of the mapfile parameters via the web interface, you # need to define a TEMPLATEPATTERN. This is required for security reasons. # Since the example filenames in section 2 begin with "example2" (as in # example2-1.html or example2-2.html), you can use it as the pattern. # The template pattern is a regular expression used by MapServer to match the # value of map_web_template variable against. TEMPLATEPATTERN 'example2*'

# The web object is defined at the level below the map object. All # web-related parameters (I interchange "parameters" and "keyword/value # pairs" quite frequently, sorry about that) are defined in this object. WEB TEMPLATE 'c:/ms4w/apps/tutorial/htdocs/template2.2.html' IMAGEPATH 'c:/ms4w/apps/tutorial/htdocs/tmp/ms_tmp/' IMAGEURL '/tutorial/tmp/ms_tmp/' END # Every object in MapServer must have an END.;)

# The projection object is typically used within the map and the layer # objects. You only define it once within the map object and this definition # becomes your output projection--MapServer will render your maps in this

# projection. You also use the projection object within the layer object to # define your input projection. Your layers can be in different # projections--MapServer will reproject them into your output projection. # If no projection is defined within the layer object, MapServer assumes # your input projection is the same as your output projection. This is not # a required object unless you're creating a map file that supports one of # the OGC interoperability web services specifications (WMS/WFS/WCS). PROJECTION # Projection parameters can be defined in two ways... # This is the traditional Proj.4 definition of Lambert Azimuthal Equal-Area # projection for the Continental U.S. # "proj=laea" # "ellps=clrk66" # "lat_0=45" # "lon_0=-100" # # Alternatively, you can specify an EPSG code. # This is the EPSG code for Lambert Azimuthal Equal-Area # projection for the U.S. "init=epsg:2163" END # This is the ending of the output projection # # Start of legend # LEGEND KEYSIZE 12 12 LABEL TYPE BITMAP SIZE MEDIUM COLOR 0 0 89 END STATUS ON END # The reference object is used to define a reference map for your mapping # application. This typically involves defining a small image that covers # the entire area of the map and defining a box that represents the current # view on in relation to the entire area. REFERENCE IMAGE '../images/ugl_ref1.png' # The reference image SIZE 155 105 # The size of the reference image in pixels EXTENT 201621.496941 -294488.285333 1425518.020722 498254.511514 # The extent of the reference image in map units STATUS ON MINBOXSIZE 10 # How small can the reference box be before it gets drawn as a point, in pixels MAXBOXSIZE 150 # The maximum size of the reference box, in pixels COLOR -1 -1 -1 # The reference box fill color, negative numbers mean transparent OUTLINECOLOR 128 0 0 # The reference box outline color MARKERSIZE 8 # The size of the point marker

MARKER 'star' # The marker symbol END # A scalebar object is defined one level below the map object. This object # controls how a scalebar is drawn by MapServer. Scalebars can be embedded # in the map itself or can be created as a separate image. It has an # associated MapServer CGI variable called "scalebar" (or [scalebar] when # used in the HTML template). SCALEBAR IMAGECOLOR 255 255 255 LABEL COLOR 0 0 0 SIZE TINY END STYLE 1 SIZE 100 2 COLOR 0 0 0 UNITS MILES INTERVALS 2 TRANSPARENT FALSE STATUS ON END # Scalebar object ends

# Layer objects, too, are defined beneath the map object. Be mindful of the # order of your layer objects. MapServer "stacks them" in reverse # order--that is, the last layer you define (at the bottom of the map file) # will be drawn on top and the first layer you define (right after this # comment), will be drawn at the bottom. Here's my rule: rasters and # polygons are defined first, followed by the line layers. The point and # annotation layers are defined last. You can play around with the ordering # of your layers until you're satisfied. # Start of LAYER DEFINITIONS -------------------------------------------LAYER # States polygon layer begins here NAME states DATA states_ugl STATUS DEFAULT TYPE POLYGON REQUIRES "![modis] OR ![modis_jpl]" # Here's an example of the input projection definition. # EPSG:4326 is code for geographic (latlong) projection # using the WGS84 datum PROJECTION "init=epsg:4326" END CLASSITEM "CLASS"

# The class object is defined within the layer object. You can define as # many classes as you need (well, there are limits, but it's senseless to # define more than ten on a "normal" layer. There are situations, # however, where you might have to do it.) CLASS EXPRESSION 'land' # There are styles in a class, just like there are classes in a layer, # just like there are layers in a map. STYLE SYMBOL 0 COLOR 232 232 232 END # And they all must come to an end. END # End of this class. END # States polygon layer ends here LAYER # MODIS raster layer begins here NAME modis DATA "raster/mod09a12003161_ugl_ll_idxa.tif" STATUS OFF TYPE RASTER OFFSITE 70 74 66 #167 151 152 PROJECTION "init=epsg:4326" END END # MODIS raster layer ends here LAYER # MODIS WMS map from JPL (or from USGS) NAME modis_jpl TYPE RASTER OFFSITE 0 0 0 STATUS OFF CONNECTIONTYPE WMS CONNECTION "http://wms.jpl.nasa.gov/wms.cgi?" METADATA "wms_srs" "EPSG:4326" "wms_name" "daily_terra" #"global_mosaic" "daily_aqua" "wms_server_version" "1.1.1" "wms_format" "image/jpeg" END PROJECTION "init=epsg:4326" END END # MODIS WMS image ends here LAYER # Hydrography layer begins here NAME hydro TYPE POLYGON STATUS OFF DATA hydrop_ugl PROJECTION "init=epsg:4326" END

CLASSITEM 'FEATURE' CLASS NAME 'Lakes' EXPRESSION /(^B|^C|^L|^R)./ STYLE COLOR 72 64 254 END END # CLASS CLASS NAME 'Rivers' EXPRESSION 'Stream' STYLE COLOR 136 128 255 END END # CLASS CLASS NAME 'Wetlands' EXPRESSION 'Swamp or Marsh' STYLE COLOR 195 252 255 OUTLINECOLOR 195 252 255 SYMBOL 'circle' SIZE 0 END END # CLASS END # LAYER LAYER # ROADS LAYER NAME cty_roads GROUP roads TYPE LINE STATUS OFF DATA roads_ugl MAXSCALE 750000 PROJECTION "init=epsg:4326" END CLASSITEM 'CLASS1' CLASS NAME 'Minor Arterial Roads' EXPRESSION '3' STYLE COLOR 165 165 165 END END # CLASS CLASS EXPRESSION '4' STYLE COLOR 210 210 210 END END # CLASS END # ROADS LAYER LAYER # state highways begin here NAME state_hwy GROUP roads MAXSCALE 1500000 STATUS OFF DATA roads_ugl

TYPE LINE FILTERITEM 'CLASS1' FILTER '2' CLASS NAME 'Principal Arterial Roads' STYLE COLOR 255 0 0 SIZE 1 SYMBOL 'circle' END END PROJECTION "init=epsg:4326" END END # highways LAYER # interstate highways begin here NAME interstate GROUP roads # MAXSCALE 22500000 STATUS OFF DATA roads_ugl TYPE LINE FILTERITEM 'CLASS1' FILTER '1' CLASS NAME "Interstate Hwy." STYLE COLOR 128 0 0 END END PROJECTION "init=epsg:4326" END END # highways LAYER # States NAME DATA STATUS TYPE line layer begins here states states_ugl OFF LINE

PROJECTION "init=epsg:4326" END CLASSITEM "CLASS" CLASS NAME 'State Boundary' EXPRESSION 'land' STYLE SYMBOL 'line5' COLOR 32 32 32 SIZE 1 END END END # States line layer ends here

LAYER NAME roads_anno GROUP roads MAXSCALE 750000 STATUS OFF DATA roads_ugl TYPE ANNOTATION LABELITEM "SIGN" CLASSITEM "CLASS1" CLASS EXPRESSION "3" STYLE COLOR 0 0 0 # dummy color SYMBOL '../symbols/sthwy.png' END LABEL MINFEATURESIZE 50 MINDISTANCE 150 POSITION CC SIZE TINY COLOR 0 0 0 END END CLASS EXPRESSION "2" STYLE COLOR 0 0 0 # dummy color SYMBOL '../symbols/ushwy.png' END LABEL MINFEATURESIZE 50 MINDISTANCE 150 POSITION CC SIZE TINY COLOR 0 0 0 END END PROJECTION "init=epsg:4326" END END # highway annotation LAYER NAME roads_anno1 GROUP roads STATUS OFF DATA roads_ugl TYPE ANNOTATION LABELITEM "SIGN" CLASSITEM "CLASS1" CLASS EXPRESSION "1" STYLE COLOR 0 0 0 # dummy color SYMBOL '../symbols/interstate.png' END LABEL MINFEATURESIZE 20 MINDISTANCE 150

POSITION CC SIZE TINY COLOR 255 255 255 END END PROJECTION "init=epsg:4326" END END LAYER # States NAME DATA STATUS TYPE label layer begins here states states_ugl OFF ANNOTATION

PROJECTION "init=epsg:4326" END CLASSITEM "CLASS" LABELITEM "STATE" CLASS EXPRESSION 'land' STYLE COLOR -1 -1 -1 END LABEL COLOR 132 31 31 OUTLINECOLOR 128 128 128 SHADOWCOLOR 218 218 218 SHADOWSIZE 1 1 TYPE TRUETYPE FONT arial-bold SIZE 12 ANTIALIAS TRUE POSITION CL PARTIALS FALSE MINDISTANCE 200 BUFFER 4 END # end of label END # end of class END # States label layer ends here # End of LAYER DEFINITIONS ------------------------------END # end of map file

El cdigo fuente del template2.2.html que guardamos en C:\ms4w\apps\tutorial\htdocs. <html> <head><title>MapServer 4.6 Tutorial</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link type="text/css" rel="stylesheet" href="/tutorial/ms35.css" /> </head> <body bgcolor="#FFFFFF" text="#000000"> <table width="600" align="center"> <tr> <td> <h3 align="center">Example 2.2: Layer Control</h3> <!-- START OF MAPSERVER FORM -->

<form name="mapserv" method="GET" action="/cgi-bin/mapserv.exe"> <!-- HIDDEN MAPSERVER CGI VARIABLES --> <input type="hidden" name="map" value="[map]"> <input type="hidden" name="imgext" value="[mapext]"> <input type="hidden" name="imgxy" value="199.5 149.5"> <table width="600" border="0" align="center"> <tr> <td> <table width="400" border="1" align="center"> <tr> <td colspan="3">Select Layers: <!-- SPECIFY VECTOR LAYERS --> <input type="checkbox" name="layer" value="states" [states_check]> State Boundaries&nbsp; <input type="checkbox" name="layer" value="hydro" [hydro_check]>Water Features &nbsp;<br> <input type="checkbox" name="layer" value="roads" [roads_check]>Roads<br> <!-- SPECIFY RASTER LAYERS --> Select Background: <select name="layer"> <option value=" " [ _select]>No Background</option> <option value="modis_jpl" [modis_jpl_select]> Daily MODIS Image</option> <option value="modis" [modis_select]> MODIS Surface Reflectance</option> </select> </td> </tr> <tr> <td> <!-- SPECIFY MAP MODE --> <div align="center">Map Mode:<br> <select name="mode"> <option value="browse">Browse</option> <option value="map">Map</option> </select> </div> </td> <td> <!-- FORM SUBMIT BUTTON --> <div align="center"> <input type="submit" name="submit" value="Refresh"> </div> </td> <td> <!-- ZOOM/PAN CONTROLS --> <div align="center">Map Control: <br> <select name="zoom"> <option value="4" [zoom_4_select]>Zoom In 4x</option> <option value="3" [zoom_3_select]>Zoom In 3x</option> <option value="2" [zoom_2_select]>Zoom In 2x</option> <option value="1" [zoom_1_select]>Recenter</option> <option value="-2" [zoom_-2_select]>Zoom Out 2x</option> <option value="-3" [zoom_-3_select]>Zoom Out 3x</option> <option value="-4" [zoom_-4_select]>Zoom Out 4x</option> </select> </div> </td> </tr> <tr> <!-- DISPLAY THE MAPSERVER-CREATED MAP IMAGE --> <td colspan="3" align="center" valign="top"> <input type="image" name="img" src="[img]" width="400" height="300" border="0"> </td> </tr> </table> </td> </tr> </table> </form> </td> </tr> </table> </body> </html> Modificamos la pgina de practicas2.html para crear un enlace a este ejemplo, agregamos un enlace a el nuevo mapfile, el archivo quedar asi:

<html> <body> Enlace a los ejercicios: <br><a href="/cgibin/mapserv.exe?map=c:/ms4w/apps/tutorial/map/ejemplo2.1.map&mode=brow se&root=/tutorial&program=/cgi-bin/mapserv.exe"> Ejemplo 2.1 </a> <br><a href="/cgibin/mapserv.exe?map=c:/ms4w/apps/tutorial/map/ejemplo2.2.map&mode=brow se&root=/tutorial&program=/cgi-bin/mapserv.exe"> Ejemplo 2.2 </a> </html> </body>

Abrimos la pgina de practicas http://localhost/tutorial/practicas2.html y damos click en el segundo link.

3. Agregar leyendas y un mapa de referencia


El archivo de configuracin de esta parte lo guardamos como ejemplo2.3.map y repetimos el procedimiento anterior:
# The annotated map file (sort of) # Created by Pericles S. Nacionales for the MapServer tutorial # 20050623 #

# Map files begin with map keyword to signify the start of the map object. # Well, the entire map file is THE map object. Enclose between MAP and END # at the very bottom of this map file, are keyword/value pairs and other # objects. MAP NAME EX2_ IMAGETYPE png24 EXTENT 166221 -371954 1505849 632767 # LAEA #EXTENT -97.5 41.619778 -82.122902 49.38562 # Geographic SIZE 400 300 SHAPEPATH "../data" SYMBOLSET "../symbols/symbols35.sym" FONTSET "../fonts/fonts.list" # When changing any of the mapfile parameters via the web interface, you # need to define a TEMPLATEPATTERN. This is required for security reasons. # Since the example filenames in section 2 begin with "example2" (as in # example2-1.html or example2-2.html), you can use it as the pattern. # The template pattern is a regular expression used by MapServer to match the # value of map_web_template variable against. TEMPLATEPATTERN 'example2*'

# The web object is defined at the level below the map object. All # web-related parameters (I interchange "parameters" and "keyword/value # pairs" quite frequently, sorry about that) are defined in this object. WEB TEMPLATE 'c:/ms4w/apps/tutorial/htdocs/template2.3.html' IMAGEPATH 'c:/ms4w/apps/tutorial/htdocs/tmp/ms_tmp/' IMAGEURL '/tutorial/tmp/ms_tmp/' END # Every object in MapServer must have an END.;)

# The projection object is typically used within the map and the layer # objects. You only define it once within the map object and this definition # becomes your output projection--MapServer will render your maps in this # projection. You also use the projection object within the layer object to # define your input projection. Your layers can be in different # projections--MapServer will reproject them into your output projection. # If no projection is defined within the layer object, MapServer assumes # your input projection is the same as your output projection. This is not # a required object unless you're creating a map file that supports one of # the OGC interoperability web services specifications (WMS/WFS/WCS). PROJECTION

# Projection parameters can be defined in two ways... # This is the traditional Proj.4 definition of Lambert Azimuthal Equal-Area # projection for the Continental U.S. # "proj=laea" # "ellps=clrk66" # "lat_0=45" # "lon_0=-100" # # Alternatively, you can specify an EPSG code. # This is the EPSG code for Lambert Azimuthal Equal-Area # projection for the U.S. "init=epsg:2163" END # This is the ending of the output projection # # Start of legend # LEGEND KEYSIZE 12 12 LABEL TYPE BITMAP SIZE MEDIUM COLOR 0 0 89 END STATUS ON END # The reference object is used to define a reference map for your mapping # application. This typically involves defining a small image that covers # the entire area of the map and defining a box that represents the current # view on in relation to the entire area. REFERENCE IMAGE '../images/ugl_ref1.png' # The reference image SIZE 155 105 # The size of the reference image in pixels EXTENT 201621.496941 -294488.285333 1425518.020722 498254.511514 # The extent of the reference image in map units STATUS ON MINBOXSIZE 10 # How small can the reference box be before it gets drawn as a point, in pixels MAXBOXSIZE 150 # The maximum size of the reference box, in pixels COLOR -1 -1 -1 # The reference box fill color, negative numbers mean transparent OUTLINECOLOR 128 0 0 # The reference box outline color MARKERSIZE 8 # The size of the point marker MARKER 'star' # The marker symbol END # A scalebar object is defined one level below the map object. This object # controls how a scalebar is drawn by MapServer. Scalebars can be embedded # in the map itself or can be created as a separate image. It has an # associated MapServer CGI variable called "scalebar" (or [scalebar] when # used in the HTML template). SCALEBAR

IMAGECOLOR 255 255 255 LABEL COLOR 0 0 0 SIZE TINY END STYLE 1 SIZE 100 2 COLOR 0 0 0 UNITS MILES INTERVALS 2 TRANSPARENT FALSE STATUS ON END # Scalebar object ends

# Layer objects, too, are defined beneath the map object. Be mindful of the # order of your layer objects. MapServer "stacks them" in reverse # order--that is, the last layer you define (at the bottom of the map file) # will be drawn on top and the first layer you define (right after this # comment), will be drawn at the bottom. Here's my rule: rasters and # polygons are defined first, followed by the line layers. The point and # annotation layers are defined last. You can play around with the ordering # of your layers until you're satisfied. # Start of LAYER DEFINITIONS -------------------------------------------LAYER # States polygon layer begins here NAME states DATA states_ugl STATUS DEFAULT TYPE POLYGON REQUIRES "![modis] OR ![modis_jpl]" # Here's an example of the input projection definition. # EPSG:4326 is code for geographic (latlong) projection # using the WGS84 datum PROJECTION "init=epsg:4326" END CLASSITEM "CLASS"

# The class object is defined within the layer object. You can define as # many classes as you need (well, there are limits, but it's senseless to # define more than ten on a "normal" layer. There are situations, # however, where you might have to do it.) CLASS EXPRESSION 'land' # There are styles in a class, just like there are classes in a layer, # just like there are layers in a map. STYLE

SYMBOL 0 COLOR 232 232 232 END # And they all must come to an end. END # End of this class. END # States polygon layer ends here LAYER # MODIS raster layer begins here NAME modis DATA "raster/mod09a12003161_ugl_ll_idxa.tif" STATUS OFF TYPE RASTER OFFSITE 70 74 66 #167 151 152 PROJECTION "init=epsg:4326" END END # MODIS raster layer ends here LAYER # MODIS WMS map from JPL (or from USGS) NAME modis_jpl TYPE RASTER OFFSITE 0 0 0 STATUS OFF CONNECTIONTYPE WMS CONNECTION "http://wms.jpl.nasa.gov/wms.cgi?" METADATA "wms_srs" "EPSG:4326" "wms_name" "daily_terra" #"global_mosaic" "daily_aqua" "wms_server_version" "1.1.1" "wms_format" "image/jpeg" END PROJECTION "init=epsg:4326" END END # MODIS WMS image ends here LAYER # Hydrography layer begins here NAME hydro TYPE POLYGON STATUS OFF DATA hydrop_ugl PROJECTION "init=epsg:4326" END CLASSITEM 'FEATURE' CLASS NAME 'Lakes' EXPRESSION /(^B|^C|^L|^R)./ STYLE COLOR 72 64 254 END END # CLASS CLASS NAME 'Rivers' EXPRESSION 'Stream' STYLE COLOR 136 128 255

END END # CLASS CLASS NAME 'Wetlands' EXPRESSION 'Swamp or Marsh' STYLE COLOR 195 252 255 OUTLINECOLOR 195 252 255 SYMBOL 'circle' SIZE 0 END END # CLASS END # LAYER LAYER # ROADS LAYER NAME cty_roads GROUP roads TYPE LINE STATUS OFF DATA roads_ugl MAXSCALE 750000 PROJECTION "init=epsg:4326" END CLASSITEM 'CLASS1' CLASS NAME 'Minor Arterial Roads' EXPRESSION '3' STYLE COLOR 165 165 165 END END # CLASS CLASS EXPRESSION '4' STYLE COLOR 210 210 210 END END # CLASS END # ROADS LAYER LAYER # state highways begin here NAME state_hwy GROUP roads MAXSCALE 1500000 STATUS OFF DATA roads_ugl TYPE LINE FILTERITEM 'CLASS1' FILTER '2' CLASS NAME 'Principal Arterial Roads' STYLE COLOR 255 0 0 SIZE 1 SYMBOL 'circle' END END

PROJECTION "init=epsg:4326" END END # highways LAYER # interstate highways begin here NAME interstate GROUP roads # MAXSCALE 22500000 STATUS OFF DATA roads_ugl TYPE LINE FILTERITEM 'CLASS1' FILTER '1' CLASS NAME "Interstate Hwy." STYLE COLOR 128 0 0 END END PROJECTION "init=epsg:4326" END END # highways LAYER # States NAME DATA STATUS TYPE line layer begins here states states_ugl OFF LINE

PROJECTION "init=epsg:4326" END CLASSITEM "CLASS" CLASS NAME 'State Boundary' EXPRESSION 'land' STYLE SYMBOL 'line5' COLOR 32 32 32 SIZE 1 END END END # States line layer ends here LAYER NAME roads_anno GROUP roads MAXSCALE 750000 STATUS OFF DATA roads_ugl TYPE ANNOTATION LABELITEM "SIGN" CLASSITEM "CLASS1" CLASS EXPRESSION "3" STYLE

COLOR 0 0 0 # dummy color SYMBOL '../symbols/sthwy.png' END LABEL MINFEATURESIZE 50 MINDISTANCE 150 POSITION CC SIZE TINY COLOR 0 0 0 END END CLASS EXPRESSION "2" STYLE COLOR 0 0 0 # dummy color SYMBOL '../symbols/ushwy.png' END LABEL MINFEATURESIZE 50 MINDISTANCE 150 POSITION CC SIZE TINY COLOR 0 0 0 END END PROJECTION "init=epsg:4326" END END # highway annotation LAYER NAME roads_anno1 GROUP roads STATUS OFF DATA roads_ugl TYPE ANNOTATION LABELITEM "SIGN" CLASSITEM "CLASS1" CLASS EXPRESSION "1" STYLE COLOR 0 0 0 # dummy color SYMBOL '../symbols/interstate.png' END LABEL MINFEATURESIZE 20 MINDISTANCE 150 POSITION CC SIZE TINY COLOR 255 255 255 END END PROJECTION "init=epsg:4326" END END LAYER # States label layer begins here NAME states

DATA STATUS TYPE

states_ugl OFF ANNOTATION

PROJECTION "init=epsg:4326" END CLASSITEM "CLASS" LABELITEM "STATE" CLASS EXPRESSION 'land' STYLE COLOR -1 -1 -1 END LABEL COLOR 132 31 31 OUTLINECOLOR 128 128 128 SHADOWCOLOR 218 218 218 SHADOWSIZE 1 1 TYPE TRUETYPE FONT arial-bold SIZE 12 ANTIALIAS TRUE POSITION CL PARTIALS FALSE MINDISTANCE 200 BUFFER 4 END # end of label END # end of class END # States label layer ends here # End of LAYER DEFINITIONS ------------------------------END # end of map file

Y el cdigo HTML de la plantilla template2.3.html es: <html> <head> <title>MapServer 4.6 Tutorial</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link type="text/css" rel="stylesheet" href="/tutorial/ms35.css" /> </head> <body bgcolor="#FFFFFF" text="#000000"> <table align="center" border="0"><tr> <td> <h3 align="center">Ejemplo 2.5: Adding a Legend</h3> <!-- START OF MAPSERVER FORM --> <form name="mapserv" method="GET" action="/cgi-bin/mapserv.exe"> <!-- HIDDEN MAPSERVER CGI VARIABLES --> <input type="hidden" name="map" value="[map]"> <input type="hidden" name="imgext" value="[mapext]"> <input type="hidden" name="imgxy" value="199.5 149.5"> <table width="600" border="0" align="center"> <tr> <td> <table width="400" border="1" align="center"> <tr> <td colspan="4">Select Layers: <!-- SPECIFY VECTOR LAYERS -->

<input type="checkbox" name="layer" value="states" [states_check] checked> State Boundaries&nbsp; <input type="checkbox" name="layer" value="hydro" [hydro_check]> Water Features&nbsp; <input type="checkbox" name="layer" value="roads" [roads_check]> Roads<br> <!-- SPECIFY RASTER LAYERS --> Select Background: <select name="layer"> <option value=" " [ _select]>No Background</option> <option value="modis_jpl" [modis_jpl_select]> Daily MODIS Image</option> <option value="modis" [modis_select]> MODIS Surface Reflectance</option> </select> </td> </tr> <tr> <td> <!-- SPECIFY MAP MODE --> <div align="center">Map Mode:<br> <select name="mode"> <option value="browse" [browse_select]>Browse</option> </select> </div> </td> <td> <!-- FORM SUBMIT BUTTON --> <div align="center"> <input type="submit" name="submit" value="Refresh"> </div> </td> <td> <!-ZOOM/PAN CONTROLS --> <div align="center">Map Control: <br> <select name="zoom"> <option value="4" [zoom_4_select]>Zoom In 4x</option> <option value="3" [zoom_3_select]>Zoom In 3x</option> <option value="2" [zoom_2_select]>Zoom In 2x</option> <option value="1" [zoom_1_select]>Recenter</option> <option value="-2" [zoom_-2_select]>Zoom Out 2x</option> <option value="-3" [zoom_-3_select]>Zoom Out 3x</option> <option value="-4" [zoom_-4_select]>Zoom Out 4x</option> </select> </div> </td> <!-- REFERENCE AND LEGEND COLUMN --> <td rowspan="2" valign="top"> <p>Reference:<br> <img name="ref" src="[ref]"></p> <p>Legend:<br> <img name="legend" src="[legend]"></p> </td> </tr> <tr> <!-- DISPLAY THE MAPSERVER-CREATED MAP IMAGE --> <td colspan="3" align="center" valign="top"> <input type="image" name="img" src="[img]" width="400" height="300" border="0"> </td> </tr> </table> </td> </tr> </table> </form> </body> </html>

Modificamos la pgina de practicas2.html para crear un enlace a este ejemplo, agregamos un enlace a el nuevo mapfile, el archivo quedar asi:
<html> <body> Enlace a los ejercicios: <br><a href="/cgibin/mapserv.exe?map=c:/ms4w/apps/tutorial/map/ejemplo2.1.map&mode=brow se&root=/tutorial&program=/cgi-bin/mapserv.exe"> Ejemplo 2.1 </a> <br><a href="/cgibin/mapserv.exe?map=c:/ms4w/apps/tutorial/map/ejemplo2.2.map&mode=brow se&root=/tutorial&program=/cgi-bin/mapserv.exe"> Ejemplo 2.2 </a> <br><a href="/cgibin/mapserv.exe?map=c:/ms4w/apps/tutorial/map/ejemplo2.3.map&mode=brow se&root=/tutorial&program=/cgi-bin/mapserv.exe"> Ejemplo 2.3 </a> </html> </body>

Abrimos la pgina de practicas http://localhost/tutorial/practicas2.html y damos click en el segundo link.

Вам также может понравиться