How to zoom to place names

Joel Schlagel joel at crrel.usace.army.mil
Thu May 11 08:05:07 PDT 2000


doug ..

i use these few lines to set map extent to a point + a buffer.  "fname" and
"zoom" are passed as cgi variables.

joel


$sql = "select * from a_table where featureID = '". $fname . "'";
$dbh = DBI->connect("DBI:mysql:$database", $user, $passwd);

$sth = $dbh->prepare($sql) or die $dbh->errstr();
$sth->execute() or die $sth->errstr();

$data = $sth->fetchrow_hashref;

$map = '';
$map = new mapObj($mapfile) or die('Unable to open mapfile.');

$point = new pointObj();
$point->{y} = $data->{'LAT_DD'};
$point->{x} = $data->{'LON_DD'};

$map->{extent}->{minx} = $point->{x} -  $zoom;
$map->{extent}->{miny} = $point->{y} -  $zoom;
$map->{extent}->{maxx} = $point->{x} +  $zoom;
$map->{extent}->{maxy} = $point->{y} +  $zoom;

$img = $map->draw() or die('Unable to draw map');
$layer = $map->getLayerByName('alayer');
$point->draw($map, $layer, $img, 0, $fname);
$map->drawLabelCache($img);

mapscript::msSaveImage($img, $image_path.$image_id, $map->{interlace},
$map->{transparent});

$dbh->disconnect(  );




More information about the MapServer-users mailing list