[Mapserver-users] map positioning -- help needed
Eric Bridger
eric at gomoos.org
Wed Nov 5 03:11:01 PST 2003
Here is a Perl mapscript example, very similiar to the Javascript, but
perhaps easier to translate to PHP. In fact I stole/adapted this from
someone's (I think Steve Limes') javascript example.
This assumes a form variable named pandir containing 'n', 'nw', 'ne'
's', 'e', 'w', etc.
# you would use $x and $y as the mouse click image coordinates and use a
# zoom direction of 0. E.g. $my_point->setXY($x, $y); then call
$myMap->zoomPoint(..)
($x, $y) = pan_to_map($map, $q->param('pandir'));
sub pan_to_map {
my ($map, $direction) = @_;
my $pansize = .50;
my ($x, $y) = (0,0);
my $width = $map->{width};
my $height = $map->{height};
if($direction eq 'n') {
$x = ($width-1)/2.0;
$y = 0 - ($height * $pansize)/2.0;
} elsif($direction eq 'nw') {
$x = 0 - ($width * $pansize)/2.0;
$y = 0 - ($height * $pansize)/2.0;
} elsif($direction eq 'ne') {
$x = ($width-1) + ($width * $pansize)/2.0;
$y = 0 - ($height * $pansize)/2.0;
} elsif($direction eq 's') {
$x = ($width-1)/2.0;
$y = ($height-1) + ($height * $pansize)/2.0;
} elsif($direction eq 'sw') {
$x = 0 - ($width * $pansize)/2.0;
$y = ($height-1) + ($height * $pansize)/2.0;
} elsif($direction eq 'se') {
$x = ($width-1) + ($width * $pansize)/2.0;
$y = ($height-1) + ($height * $pansize)/2.0;
} elsif($direction eq 'e') {
$x = ($width-1) + ($width * $pansize)/2.0;
$y = ($height-1)/2.0;
} elsif($direction eq 'w') {
$x = 0 - ($width * $pansize)/2.0;
$y = ($height-1)/2.0;
}
$x = int($x);
$y = int($y);
return($x, $y);
}
On Wed, 2003-11-05 at 13:49, Murat Isik wrote:
> Hello,
>
> I have the following code at my hand and I am supposed to add map positioning property to it. It's like there will be more four buttons, right, left, up, down. When user presses any of them the map will move slightly to selected direction without changing the zoom factor. How do I add this to the code? Any ideas? Please, I urgently need help...
>
> Thanks in advance..
>
> Murat Isik
>
>
> <HEAD>
> <TITLE>MEGATEK</TITLE>
> </HEAD>
> <CENTER>
> <FORM METHOD=POST ACTION=<?php echo $PHP_SELF?>>
> <H1>TEST SERVER</H1>
> <IMG SRC="yeni_ust.gif">
> <P>
> <?php
> dl("php_mapscript.so");
>
> mysql_connect("213.74.112.162","root","sqlpass") or
> die ("Could not connect to database");
>
> mysql_select_db("gpstrack") or
> die("Could not select database");
>
> $val_zsize=3;
> $check_pan="CHECKED";
>
> $shpFname = "target1";
> $shpFile = ms_newShapeFileObj($shpFname, MS_SHP_POINT);
>
> $shpFname1 = "target2";
> $shpFile1 = ms_newShapeFileObj($shpFname1, MS_SHP_POINT);
>
> $pt = ms_newPointObj();
>
> $i = 0;
>
> $result = mysql_query("select * from track3") or
> die (mysql_error());
>
>
> $x[0]=0;
> $y[0]=0;
>
> while ($row = mysql_fetch_array($result))
> {
> ++$i;
> $test_x[$i] = $row["lodegrees"]+$row["lominutes"]/60;
> $test_y[$i] = $row["ldegrees"]+$row["lminutes"]/60;
> file://echo $row["lominutes"];
> file://echo "<br>\n";
>
>
> if($test_x[$i]==$x[$i-1] || $test_y[$i]==$y[$i-1])
> {
> --$i;
> }else
> {
>
> $x[$i] = $test_x[$i];
> $y[$i] = $test_y[$i];
>
> }
>
> }
> mysql_free_result($result);
>
>
> for($k=1;$k<=$i-1;++$k)
> {
> $pt->setXY($x[$k], $y[$k]);
> $shpFile->addPoint($pt);
> };
>
> $pt->setXY($x[$i], $y[$i]);
> $shpFile1->addPoint($pt);
>
>
> $shpFile->free();
> $shpFile1->free();
>
> $def =array(array("UNIQID", "C", 13),array("NOM", "C", 128));
> $dbfFile = dbase_create($shpFname.".dbf", $def);
> dbase_add_record($dbfFile, array("1","TEST"));
>
> $def =array(array("UNIQID", "C", 13),array("NOM", "C", 128));
> $dbfFile = dbase_create($shpFname1.".dbf", $def);
> dbase_add_record($dbfFile, array("1","TEST"));
>
> $myMap = ms_newMapObj("demo_try.map");
>
> #$myLayer = $myMap->getLayerByName("target1");
> #$myLayer->set("data", $shpFname);
> #$myLayer->set('status', MS_ON);
>
>
> if ( isset($HTTP_POST_VARS["mapa_x"]) && isset($HTTP_POST_VARS["mapa_y"])
> && !isset($HTTP_POST_VARS["full"]) ) {
>
> // $extent_to_set = explode(" ",$HTTP_POST_VARS["extent"]);
>
>
> $extent_to_set[0] = 29.057;
> $extent_to_set[1] = 40.954;
> $extent_to_set[2] = 29.143;
> $extent_to_set[3] = 40.999;
>
>
> $myMap->setextent($extent_to_set[0],$extent_to_set[1],
> $extent_to_set[2],$extent_to_set[3]);
>
> $my_point = ms_newpointObj();
> $my_point->setXY($HTTP_POST_VARS["mapa_x"],$HTTP_POST_VARS["mapa_y"]);
>
> $my_extent = ms_newrectObj();
>
> $my_extent->setextent($extent_to_set[0],$extent_to_set[1],
> $extent_to_set[2],$extent_to_set[3]);
>
> $zoom_factor = $HTTP_POST_VARS["zoom"]*$HTTP_POST_VARS["zsize"];
> if ($zoom_factor == 0) {
> $zoom_factor = 1;
> $check_pan = "CHECKED";
> $check_zout = "";
> $check_zin = "";
> } else if ($zoom_factor < 0) {
> $check_pan = "";
> $check_zout = "CHECKED";
> $check_zin = "";
> } else {
> $check_pan = "";
> $check_zout = "";
> $check_zin = "CHECKED";
> }
>
> $val_zsize = abs($zoom_factor);
>
> $myMap->zoompoint($zoom_factor,$my_point,$myMap->width,$myMap->height,
> $my_extent);
>
> }
> $img = $myMap->draw();
> $image_url = $img->saveWebImage(GIF,1,1,0);
>
> ?>
> <BODY>
> <center>
> <table border=0 cellspacing=0 cellpadding=4 bgcolor="#FFFFFF">
> <tr>
> <td valign="top" align=center>
> <table cellpadding="0" cellspacing="5" border="5">
> <tr><td colspan="2"><INPUT NAME="mapa" TYPE="image" SRC="<?php echo $image_url; ?>" width=600 height=600 border=0></td></tr>
> <tr>
> <TR>
> <TD>
> Pan
> </TD>
> <TD>
> <INPUT TYPE=RADIO NAME="zoom" VALUE=0 <?php echo $check_pan?>>
> </TD>
> </TR>
> <TR>
> <TD>
> Zoom In
> </TD>
> <TD>
> <INPUT TYPE=RADIO NAME="zoom" VALUE=1 <?php echo $check_zin?>>
> </TD>
> </TR>
> <TR>
> <TD>
> Zoom Out
> </TD>
> <TD>
> <INPUT TYPE=RADIO NAME="zoom" VALUE=-1 <?php echo $check_zout?>>
> </TD>
> </TR>
> <TR>
> <TD>
> Zoom Size
> </TD>
> <TD>
> <INPUT TYPE=TEXT NAME="zsize" VALUE="<?php echo $val_zsize?>"
> SIZE=2>
> </TD>
> </TR>
> <TR>
> <TD>
> Full Extent
> </TD>
> <TD>
> <INPUT TYPE=SUBMIT NAME="full" VALUE="Go"
> SIZE=2>
> </TD>
> </TABLE>
> <INPUT TYPE=HIDDEN NAME="extent" VALUE="<?php echo $extent_to_html?>">
> </FORM>
> </CENTER>
>
> </BODY>
> </HTML>
>
More information about the MapServer-users
mailing list