[mapserver-users] Zooming with Mapscript

Lowell Filak lfilak at medinaco.org
Wed Apr 10 11:36:01 EDT 2002


This is a perl example as you would expect most of the variables are taken from the cgi call to start with:
Lowell F.

Cut...............................
my $zmdir = 0;
my $zmsize = 5;
my $imgszx = 1;
my $imgszy = 1;
my $minx = 1;
my $miny = 1;
my $maxx = 2;
my $maxy = 2;
my $dx = 1;
my $dy = 1;
my $pickx = 1;
my $picky = 1;
my $ndx = 1;
my $ndy = 1;
my $nminx = 1;
my $nminy = 1;
my $nmaxx = 2;
my $nmaxy = 2;
#
# Pull in values passed to cgi.
..
#
# Find the delta distances.
$dx = $maxx - $minx;
$dy = $maxy - $miny;
#
# Find real world coordinate for picked point.
#
# Open map using map file.
my $map = new mapObj('map.map') or die('Unable to Open Default MapFile!');
#
# Subtract one pixel.
$imgx = $map->{width} - 1;
$imgy = $map->{height} - 1;
#
# Divide delta x & y by pixel extents to find factor x & y.
$fctrx = $dx / $imgx;
$fctry = $dy / $imgy;
#
# Adjust to real world coordinates.
$pickx = $pickx * $fctrx;
$picky = $picky * $fctry;
$pickx = $pickx + $minx;
$picky = $maxy - $picky;
#
# Is this zoom in, out, or pan.
if ($zmdir == 1) {
  $ndx = ($dx / $zmsize) / 2;
  $ndy = ($dy / $zmsize) / 2;
  $nminx = $pickx - $ndx;
  $nminy = $picky - $ndy;
  $nmaxx = $pickx + $ndx;
  $nmaxy = $picky + $ndy;
}
elsif ($zmdir == -1) {
  $ndx = ($dx * $zmsize) / 2;
  $ndy = ($dy * $zmsize) / 2;
  $nminx = $pickx - $ndx;
  $nminy = $picky - $ndy;
  $nmaxx = $pickx + $ndx;
  $nmaxy = $picky + $ndy;
}
elsif ($zmdir == 0) {
  $ndx = $dx / 2;
  $ndy = $dy / 2;
  $nminx = $pickx - $ndx;
  $nminy = $picky - $ndy;
  $nmaxx = $pickx + $ndx;
  $nmaxy = $picky + $ndy;
}
#
# Create image of map.
$map->{extent}->{minx} = $nminx;
$map->{extent}->{miny} = $nminy;
$map->{extent}->{maxx} = $nmaxx;
$map->{extent}->{maxy} = $nmaxy;
$img = $map->draw();
mapscript::msSaveImage($img,"../html/tmp/$image_name",$mapscript::MS_PNG,$map->{transparent},$map->{interlace},0);


The following message was sent by Nicolas Boretos <nicolasb at maich.gr> on Wed, 10 Apr 2002 14:11:18 +0300.

> Hello,
> 
> I am a new user to mapserver as well as this list. I am using the tcl 
> mapscript interface to play with maps. I am able to draw a map...
> 
> My question, as I am trying to wade through the mapscript methods is how 
> to pan and zoom a map..
> The following draws a map.. (from the msworkbench code..)
> 
> set mapFile kaz_34.map
> set map [mapscript::mapObj -args $mapFile]
> set img [$map prepareImage]
> for {set i 0} {$i < [$map cget -numlayers]} {incr i} {
> 	set layer [$map getLayer $i]
> 	mapscript::layerObjRef $layer draw $map $img
> }
> $map drawLabelCache $img
> mapscript::labelCacheObjRef [$map cget -labelcache] freeCache
> mapscript::msSaveImage $img  "$mapFile.gif" 1 1
> mapscript::msFreeImage $img
> 
> I assume that the mapobject has to be re-configured (zoomed/panned) and 
> re-drawn...
> 
> I could probbaly cross ref a perl example...
> 
> Sincerely,
> nicolas boretos
> 




More information about the mapserver-users mailing list