Next Previous Contents

5. Building your Web Mapping Application

5.1 Getting Started

It is somewhat hard to keep this generic, when everyone does things differently. I will assume a base RPM install of apache on Red Hat Linux. If your environment is different, you should know how it is different!

Assuming that your web directory root is /var/www/htdocs and that your CGI-BIN directory is /var/www/cgi-bin, you will want to issue the following commands as a privileged user to these directories.


$ cd /tmp
$ wget https://mesonet.agron.iastate.edu/docs/radmapserver/radmapserver-files.tar.gz
$ cd /var/www/htdocs
$ mkdir mstmp
$ chown apache mstmp
$ tar -xzvf /tmp/radmapserver-files.tar.gz 

The mstmp directory is needed by mapserver to write temporary files to. The radmapserver directory is where we will build our application interface at.

5.2 The Mapserver .map file

Fundamental to the Mapserver application, is a .map configuration file. For our demo, we will build a simple map file called radmapserver.map in our /var/www/htdocs/radmapserver directory. The file is as follows.


# Start of Mapfile (radmapserver.map)
NAME radmapserver
STATUS ON
SIZE 450 350
EXTENT -104 37 -87 49
UNITS DD
IMAGETYPE PNG

# Map projection definition
PROJECTION
  "proj=epsg:4326"
END


# Map interface definition
WEB
  LOG "/var/www/htdocs/mstmp/radmapserver.log"
  TEMPLATE radmapserver.html
  IMAGEPATH "/var/www/htdocs/mstmp/"
  IMAGEURL "/mstmp/"
END

# Our Geo-referenced RADAR layer
LAYER
  TYPE RASTER
  STATUS ON
  NAME radar
  DATA "/var/www/htdocs/radmapserver/gisdata/radar.tif"
  PROJECTION
   "proj=epsg:4326"
  END
  # For Mapserver 3.x, we would use
  # OFFSITE 0
  OFFSITE 0 0 0
END

# Our states shapefile, just to get some political boundaries
LAYER
  TYPE POLYGON
  STATUS ON
  NAME states
  DATA "/var/www/htdocs/radmapserver/gisdata/states.shp"
  PROJECTION
    "proj=epsg:4326"
  END
  CLASS
    OUTLINECOLOR 255 0 0
  END
END

END # End of mapfile radmapserver.map

In the Web definition of our mapfile, we referenced a file called radmapserver.html. This file is a HTML template mapserver uses to generate an interface. Our example radmapserver.html file is as follows.


<html>
<head>
  <title>RadMapserver Test</title>
</head>

<form method="GET" action="/cgi-bin/mapserv" name="mapserv">
<input type="hidden" value="[mapext]" name="imgext">
<!-- imgxy is set to half of your display image size -->
<input type="hidden" value="225 175" name="imgxy">
<input type="hidden" value="[map]" name="map">
<input type="hidden" value="browse" name="mode">

<table border="1">
<tr><td>

<input name="img" type="image" src="[img]" border="0">

</td><td>

<p> <b> Select layers to display </b> 
<br><input type="checkbox" value="radar" name="layer" [radar_check] > RADAR layer
<br><input type="checkbox" value="states" name="layer" [states_check] > States layer

<p>  Set your zoom option:
<br>  
<select name="zoom" size="1">  
  <option value="4" [zoom_4_select]> Zoom in 4 times 
  <option value="3" [zoom_3_select]> Zoom in 3 times 
  <option value="2" [zoom_2_select]> Zoom in 2 times 
  <option value="1" [zoom_1_select]> Recenter Map 
  <option value="-2" [zoom_-2_select]> Zoom out 2 times 
  <option value="-3" [zoom_-3_select]> Zoom out 3 times 
  <option value="-4" [zoom_-4_select]> Zoom out 4 times 
</select>

<p>
<input type="submit" value="Make Map!">
<form>
</td></tr></table>

<html>

Believe it or not, we are ready to rock and roll! Get your favorite Open Source web browser loaded up and point it at your website with the following URL


http://your.web.site/cgi-bin/mapserv?map=/var/www/htdocs/radmapserver/radmapserver.map&layers=states


Next Previous Contents