[Mapserver-users] map positioning -- help needed
Eric Bridger
eric at gomoos.org
Thu Nov 6 01:42:06 PST 2003
You must keep straight the difference between map image coordinates and
map lat/lon coordinates.
I'm not sure what your form variables $mapa_x and $mapa_y contain (I
thought these were image coordinates).
But $a and $b are image coordinates and must be converted to lat/long
before calling $point->setXY() and passing $point to zoomPoint().
Here's some Perl code to do that, where $click_x == $a and $click_y ==
$b.
$x_pct = ($click_x / $map->{width});
$y_pct = 1 - ($click_y / $map->{height});
$x_map = $current_extent[0] + ( ($current_extent[2] -
$current_extent[0]) * $x_pct);
$y_map = $current_extent[1] + ( ($current_extent[3] -
$current_extent[1]) * $y_pct);
$x_map is now latitude and $y_map is now longitude.
On Thu, 2003-11-06 at 11:12, Murat Isik wrote:
> Thank you:)
> This looked a lot simple, so I tried to implement it into my code, just
> trying "north". However it gave an error. Since I am a mapserver/mapscript
> newbei, I could not understand the problem. Can you tell me what's wrong
> here? Please. I am desperate....
>
> Error:
>
> Fatal error: zoomPoint failed : incorrect parameters in
> /var/www/html/mapserver/itasca/map_move_try.php on line 119
>
> current php-code:
>
> <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;
> file://$check_pan="CHECKED";
> $pandir = 0;
>
> $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);
>
>
>
> $direction = $HTTP_POST_VARS["pandir"];
>
>
> $my_point = ms_newpointObj();
>
> if($direction!=0)
> {
> if($direction == 1) {
>
> $pansize = .50;
> $a = 0;
> $b = 0;
> $width = $myMap->width;
> $height = $myMap->height;
> $a = ($width-1)/2.0;
> $b = 0 - ($height * $pansize)/2.0;
> }
> $zoom_factor = 0;
> $my_point->setXY($a, $b);
> $extent_to_set[0] = 29.057;
> $extent_to_set[1] = 40.954;
> $extent_to_set[2] = 29.143;
> $extent_to_set[3] = 40.999;
> $my_extent = ms_newrectObj();
> $my_extent->setextent($extent_to_set[0],$extent_to_set[1],
> $extent_to_set[2],$extent_to_set[3]);
> $myMap->zoompoint($zoom_factor,$my_point,$myMap->width,$myMap->height,
> $my_extent);
>
> }elseif ( 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->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>
> NULL
> </TD>
> <TD>
> <INPUT TYPE=RADIO NAME="pandir" VALUE=0 >
> </TD>
> </TR>
> <TR>
> <TD>
> North
> </TD>
> <TD>
> <INPUT TYPE=RADIO NAME="pandir" VALUE=1 >
> </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>
>
> Have a nice day
>
> Murat Isik
>
> _______________________________________________
> Mapserver-users mailing list
> Mapserver-users at lists.gis.umn.edu
> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
>
More information about the MapServer-users
mailing list