Changes between Initial Version and Version 1 of PerlMapScriptExamples35ex16


Ignore:
Timestamp:
Jan 29, 2009, 7:08:52 AM (13 years ago)
Author:
jmckenna
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PerlMapScriptExamples35ex16

    v1 v1  
     1= Fetchmap.pl =
     2
     3Fetchmap.pl 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.
     4
     5Here are a couple of URL examples:
     6
     7Miami, FL - http://www.siliconmapping.com/mapper/cgi-bin/fetchmap.pl?lat=25.561&lon=-80.462&mapsize=300+210&mapext=1642750+2865665+1816633+2987024 with URL specifying lat/lon, size and extents
     8
     9Default US Map - http://www.siliconmapping.com/mapper/cgi-bin/fetchmap.pl with default lat/lon, size and extents
     10----
     11{{{
     12#!perl
     13#!/usr/bin/perl
     14
     15use CGI;   # prerequisite package/module
     16use mapscript;
     17
     18$ENV{MS_ERRORFILE}="/var/log/mapserver";
     19$mapfile = $query->param('map') or $mapfile = "/home/httpd/html/mapper/tiger35.map";
     20
     21# create new CGI object
     22$query = new CGI;
     23
     24@extent = split(' ', $query->param('mapext')) or
     25        @extent = split('\,',"-3300000,2200000,3400000,7200000"); # the default
     26
     27die $mapscript::ms_error->{code}.": ".$mapscript::ms_error->{message} unless $map = new mapObj($mapfile);
     28
     29if (defined($query->param(mapsize))) {
     30   ($map->{width},$map->{height}) = split(' ', $query->param('mapsize'));
     31} else {
     32   $map->{width} = 640; $map->{height} = 480;  # default size
     33}
     34
     35
     36$map->{extent}->{minx} = $extent[0];
     37$map->{extent}->{miny} = $extent[1];
     38$map->{extent}->{maxx} = $extent[2];
     39$map->{extent}->{maxy} = $extent[3];
     40
     41
     42$img = $map->draw() or LogDie "Unable to render map.", $mapscript::ms_error->{message};
     43
     44
     45print $query->header('image/gif');
     46
     47# mapserv 3.2 method
     48# mapscript::msSaveImage($img, undef, 0,0);
     49
     50# mapserv 3.5 method
     51mapscript::msSaveImage($img,undef,$mapscript::MS_GIF,$map->{transparent},$map->{interlace},undef);
     52
     53
     54#  LogDie is a routine that appends a user define "MyErrorMessage"
     55#  to the tail end of the mapserver log
     56#
     57sub LogDie {
     58   $msg = shift(@_);
     59   open(LOG,$ENV{MS_ERRORLOG});
     60   print LOG $msg;
     61   close(LOG);
     62   exit;
     63
     64}
     65}}}
     66----
     67back to PerlMapScript