Version 1 (modified by jmckenna, 14 years ago) ( diff )

-- is CGI backend wrapper interface that uses mapscript. This example will accept the following inputs: LAT/LON, mapfile, mapext (extents), mapsize input arguments via URL and generates map images. Demonstrates mapserv error handling, establishing and overriding parameter defaults, URL/CGI inputs and showing a few old methods for different version of mapserv. This example shows some simplistic functionality of perl mapscript in a CGI setting. These wese designed to emulate a few inputs of the Tiger Map Server.

Here are a couple of URL examples:

Miami, FL - with URL specifying lat/lon, size and extents

Default US Map - with default lat/lon, size and extents


use CGI;   # prerequisite package/module
use mapscript;

$mapfile = $query->param('map') or $mapfile = "/home/httpd/html/mapper/";

# create new CGI object
$query = new CGI;

@extent = split(' ', $query->param('mapext')) or
        @extent = split('\,',"-3300000,2200000,3400000,7200000"); # the default

die $mapscript::ms_error->{code}.": ".$mapscript::ms_error->{message} unless $map = new mapObj($mapfile);

if (defined($query->param(mapsize))) {
   ($map->{width},$map->{height}) = split(' ', $query->param('mapsize'));
} else {
   $map->{width} = 640; $map->{height} = 480;  # default size

$map->{extent}->{minx} = $extent[0];
$map->{extent}->{miny} = $extent[1];
$map->{extent}->{maxx} = $extent[2];
$map->{extent}->{maxy} = $extent[3];

$img = $map->draw() or LogDie "Unable to render map.", $mapscript::ms_error->{message};

print $query->header('image/gif');

# mapserv 3.2 method
# mapscript::msSaveImage($img, undef, 0,0);

# mapserv 3.5 method

#  LogDie is a routine that appends a user define "MyErrorMessage"
#  to the tail end of the mapserver log
sub LogDie {
   $msg = shift(@_);
   print LOG $msg;


back to PerlMapScript

Note: See TracWiki for help on using the wiki.