[Mapserver-users] map navigation problem
Murat Isik
muratisik at megatek.com.tr
Fri Nov 7 03:49:50 PST 2003
This is a multi-part message in MIME format.
------=_NextPart_000_0166_01C3A536.03631CF0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hello,
I am working on gpstracking project and since I am a newbei to php and =
mapscript, I am rather outiing some sample codes together than writing =
my own :(
I have succeeded in printing the static layers with dynamic points =
printed on them, I also borrowed zoom-pzn code from mapserver site but =
now it has come to navigating the map and I am stuck. There should be 4 =
buttons, left-right-up-down and when user chooses one of them, even if =
the map is already zoomed, it must be regenrated according to the =
movement wanted by the user. I have tried some code sniplets but I could =
not get it to work. Can anyone give me an idea what's wrong here and how =
I can fix it?
Have a nice day:)
Murat Isik
<HEAD>
<TITLE>TEST</TITLE>
</HEAD>
<CENTER>
<FORM METHOD=3DPOST ACTION=3D<?php echo $PHP_SELF?>>
<H1>TEST SERVER</H1>
<P>
<?php
dl("php_mapscript.so");
mysql_connect("localhost","root","test") or
die ("Could not connect to database");
mysql_select_db("pointtrack") or
die("Could not select database");
$val_zsize=3D3;
file://$check_pan=3D"CHECKED";
$shpFname =3D "target1";
$shpFile =3D ms_newShapeFileObj($shpFname, MS_SHP_POINT);
$shpFname1 =3D "target2";
$shpFile1 =3D ms_newShapeFileObj($shpFname1, MS_SHP_POINT);
$pt =3D ms_newPointObj();
$i =3D 0;
$result =3D mysql_query("select * from track3") or
die (mysql_error());
$x[0]=3D0;
$y[0]=3D0;
while ($row =3D mysql_fetch_array($result))
{
++$i;
$test_x[$i] =3D $row["lodegrees"]+$row["lominutes"]/60;
$test_y[$i] =3D $row["ldegrees"]+$row["lminutes"]/60;
file://echo $row["lominutes"];
file://echo "<br>\n";
if($test_x[$i]=3D=3D$x[$i-1] || $test_y[$i]=3D=3D$y[$i-1])
{
--$i;
}else
{
$x[$i] =3D $test_x[$i];
$y[$i] =3D $test_y[$i];
}
}
mysql_free_result($result);
for($k=3D1;$k<=3D$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 =3Darray(array("UNIQID", "C", 13),array("NOM", "C", 128));
$dbfFile =3D dbase_create($shpFname.".dbf", $def);
dbase_add_record($dbfFile, array("1","TEST"));
$def =3Darray(array("UNIQID", "C", 13),array("NOM", "C", 128));
$dbfFile =3D dbase_create($shpFname1.".dbf", $def);
dbase_add_record($dbfFile, array("1","TEST"));
$myMap =3D ms_newMapObj("demo_try.map");
#$myLayer =3D $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"])&& =
isset($HTTP_POST_VARS["zoom"]) ) {
// $extent_to_set =3D explode(" ",$HTTP_POST_VARS["extent"]);
$extent_to_set[0] =3D 29.057;
$extent_to_set[1] =3D 40.954;
$extent_to_set[2] =3D 29.143;
$extent_to_set[3] =3D 40.999;
$myMap->setextent($extent_to_set[0],$extent_to_set[1],
$extent_to_set[2],$extent_to_set[3]);
$my_point =3D ms_newpointObj();
=
$my_point->setXY($HTTP_POST_VARS["mapa_x"],$HTTP_POST_VARS["mapa_y"]);
//mapa_x and mapa_y are mouse click coordinates
$my_extent =3D ms_newrectObj();
$my_extent->setextent($extent_to_set[0],$extent_to_set[1],
$extent_to_set[2],$extent_to_set[3]);
if($HTTP_POST_VARS["zoom"] =3D=3D 0 && $HTTP_POST_VARS["zoom"] =3D=3D 1 =
&& $HTTP_POST_VARS["zoom"] =3D=3D -1)
{
$zoom_factor =3D $HTTP_POST_VARS["zoom"]*$HTTP_POST_VARS["zsize"];
if ($zoom_factor =3D=3D 0) {
$zoom_factor =3D 1;
$check_pan =3D "CHECKED";
$check_zout =3D "";
$check_zin =3D "";
} else if ($zoom_factor < 0) {
$check_pan =3D "";
$check_zout =3D "CHECKED";
$check_zin =3D "";
} else {
$check_pan =3D "";
$check_zout =3D "";
$check_zin =3D "CHECKED";
}
$val_zsize =3D abs($zoom_factor);
=
$myMap->zoompoint($zoom_factor,$my_point,$myMap->width,$myMap->height,
$my_extent);
}elseif($HTTP_POST_VARS["zoom"] =3D=3D 2)
{
$xmax =3D $myMap->extent->{xmax};
$xmin =3D $myMap->extent->{xmin};
$xinc =3D ($xmax - $xmin ) / 2;
$myMap->setextent( ($xmin + $xinc), $ymin, ($xmax + $xinc), =
$ymax);
}
}
$img =3D $myMap->draw();
$image_url =3D $img->saveWebImage(GIF,1,1,0);
//$extent_to_html =3D $map->extent->minx." ".$map->extent->miny." "
// .$map->extent->maxx." ".$map->extent->maxy;
?>
<BODY>
<center>
<table border=3D0 cellspacing=3D0 cellpadding=3D4 bgcolor=3D"#FFFFFF">
<tr>
<td valign=3D"top" align=3Dcenter>
<table cellpadding=3D"0" cellspacing=3D"5" border=3D"5">
<tr><td colspan=3D"2"><INPUT NAME=3D"mapa" TYPE=3D"image" =
SRC=3D"<?php echo $image_url; ?>" width=3D600 height=3D600 =
border=3D0></td></tr>
<tr>
<TR>
<TD>
Pan
</TD>
<TD>
<INPUT TYPE=3DRADIO NAME=3D"zoom" VALUE=3D0 <?php echo =
$check_pan?>>
</TD>
</TR>
<TR>
<TD>
Zoom In
</TD>
<TD>
<INPUT TYPE=3DRADIO NAME=3D"zoom" VALUE=3D1 <?php echo =
$check_zin?>>
</TD>
</TR>
<TR>
<TD>
Zoom Out
</TD>
<TD>
<INPUT TYPE=3DRADIO NAME=3D"zoom" VALUE=3D-1 <?php echo =
$check_zout?>>
</TD>
</TR>
<TR>
<TD>
Move the map to the right
</TD>
<TD>
<INPUT TYPE=3DRADIO NAME=3D"zoom" VALUE=3D2 <?php echo =
$check_zout?>>
</TD>
</TR>
<TR>
<TD>
Zoom Size
</TD>
<TD>
<INPUT TYPE=3DTEXT NAME=3D"zsize" VALUE=3D"<?php echo =
$val_zsize?>"
SIZE=3D2>
</TD>
</TR>
<TR>
<TD>
Full Extent
</TD>
<TD>
<INPUT TYPE=3DSUBMIT NAME=3D"full" VALUE=3D"Go"
SIZE=3D2>
</TD>
</TABLE>
<INPUT TYPE=3DHIDDEN NAME=3D"extent" VALUE=3D"<?php echo =
$extent_to_html?>">
</FORM>
</CENTER>
</BODY>
</HTML>
------=_NextPart_000_0166_01C3A536.03631CF0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.3700.6699" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hello,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I am working on gpstracking project and =
since I am=20
a newbei to php and mapscript, I am rather outiing some sample codes =
together=20
than writing my own :(</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I have succeeded in printing the static =
layers with=20
dynamic points printed on them, I also borrowed zoom-pzn code from =
mapserver=20
site but now it has come to navigating the map and I am stuck. There =
should=20
be 4 buttons, left-right-up-down and when user chooses one of them, =
even if=20
the map is already zoomed, it must be regenrated according to the =
movement=20
wanted by the user. I have tried some code sniplets but I could not get =
it to=20
work. Can anyone give me an idea what's wrong here and how I can fix=20
it?</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Have a nice day:)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Murat Isik</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial=20
size=3D2><HEAD><BR><TITLE>TEST</TITLE><BR></HEAD>=
<BR><CENTER><BR><FORM=20
METHOD=3DPOST ACTION=3D<?php echo =
$PHP_SELF?>><BR><H1>TEST=20
SERVER</H1><BR><P><BR><?php<BR>dl("php_mapscript.so");</FO=
NT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial =
size=3D2>mysql_connect("localhost","root","test")=20
or<BR> die ("Could not connect =
to=20
database");</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>mysql_select_db("pointtrack")=20
or<BR> die("Could not select=20
database");</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>$val_zsize=3D3;<BR><A=20
href=3D'file://$check_pan=3D"CHECKED"'>file://$check_pan=3D"CHECKED"</A>;=
</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>$shpFname =3D "target1";<BR>$shpFile =
=3D=20
ms_newShapeFileObj($shpFname, MS_SHP_POINT);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>$shpFname1 =3D "target2";<BR>$shpFile1 =
=3D=20
ms_newShapeFileObj($shpFname1, MS_SHP_POINT);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>$pt =3D ms_newPointObj();</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>$i =3D 0;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>$result =3D mysql_query("select * from =
track3")=20
or<BR> die=20
(mysql_error());</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial =
size=3D2><BR>$x[0]=3D0;<BR>$y[0]=3D0;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>while ($row =3D=20
mysql_fetch_array($result))<BR>{<BR>++$i;<BR>$test_x[$i] =3D=20
$row["lodegrees"]+$row["lominutes"]/60;<BR>$test_y[$i] =3D=20
$row["ldegrees"]+$row["lminutes"]/60;<BR><A =
href=3D"file://echo">file://echo</A>=20
$row["lominutes"];<BR><A href=3D"file://echo">file://echo</A>=20
"<br>\n";</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2><BR>if($test_x[$i]=3D=3D$x[$i-1] ||=20
$test_y[$i]=3D=3D$y[$i-1])<BR>{<BR>--$i;<BR>}else<BR>{</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>$x[$i] =3D $test_x[$i];<BR>$y[$i] =3D=20
$test_y[$i];</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>}</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial =
size=3D2>}<BR>mysql_free_result($result);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial=20
size=3D2><BR>for($k=3D1;$k<=3D$i-1;++$k)<BR>{<BR>$pt->setXY($x[$k],=
=20
$y[$k]);<BR>$shpFile->addPoint($pt);<BR>};</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>$pt->setXY($x[$i],=20
$y[$i]);<BR>$shpFile1->addPoint($pt);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial=20
size=3D2><BR>$shpFile->free();<BR>$shpFile1->free();</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>$def =3Darray(array("UNIQID", "C", =
13),array("NOM",=20
"C", 128));<BR>$dbfFile =3D dbase_create($shpFname.".dbf",=20
$def);<BR>dbase_add_record($dbfFile, array("1","TEST"));</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>$def =3Darray(array("UNIQID", "C", =
13),array("NOM",=20
"C", 128));<BR>$dbfFile =3D dbase_create($shpFname1.".dbf",=20
$def);<BR>dbase_add_record($dbfFile, array("1","TEST"));</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>$myMap =3D =
ms_newMapObj("demo_try.map");</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>#$myLayer =3D=20
$myMap->getLayerByName("target1");<BR>#$myLayer->set("data",=20
$shpFname);<BR>#$myLayer->set('status', MS_ON);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>if ( isset($HTTP_POST_VARS["mapa_x"]) =
&&=20
isset($HTTP_POST_VARS["mapa_y"])<BR> =
&&=20
!isset($HTTP_POST_VARS["full"])&& isset($HTTP_POST_VARS["zoom"]) =
)=20
{</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>// =
$extent_to_set =3D=20
explode(" ",$HTTP_POST_VARS["extent"]);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2><BR>$extent_to_set[0] =3D=20
29.057;<BR>$extent_to_set[1] =3D 40.954;<BR>$extent_to_set[2] =3D=20
29.143;<BR>$extent_to_set[3] =3D 40.999;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2><BR> =20
$myMap->setextent($extent_to_set[0],$extent_to_set[1],<BR> =
&=
nbsp; =20
$extent_to_set[2],$extent_to_set[3]);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> =
$my_point =3D=20
ms_newpointObj();<BR> =20
$my_point->setXY($HTTP_POST_VARS["mapa_x"],$HTTP_POST_VARS["mapa_y"]);=
</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbs=
p; =20
<A href=3D"file://mapa_x">//mapa_x</A> and mapa_y are mouse click=20
coordinates</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> =
$my_extent =3D=20
ms_newrectObj();</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> =20
$my_extent->setextent($extent_to_set[0],$extent_to_set[1],<BR> &n=
bsp; &nb=
sp; &nbs=
p; =20
$extent_to_set[2],$extent_to_set[3]);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2><BR>if($HTTP_POST_VARS["zoom"] =3D=3D 0 =
&&=20
$HTTP_POST_VARS["zoom"] =3D=3D 1 && $HTTP_POST_VARS["zoom"] =
=3D=3D=20
-1)<BR>{<BR>$zoom_factor =3D=20
$HTTP_POST_VARS["zoom"]*$HTTP_POST_VARS["zsize"];<BR> &n=
bsp; =20
if ($zoom_factor =3D=3D 0)=20
{<BR> &n=
bsp; =20
$zoom_factor =3D=20
1;<BR> &=
nbsp; =20
$check_pan =3D=20
"CHECKED";<BR>  =
; =20
$check_zout =3D=20
"";<BR> =
=20
$check_zin =3D "";<BR> } else if =
($zoom_factor <=20
0)=20
{<BR> &n=
bsp; =20
$check_pan =3D=20
"";<BR> =
=20
$check_zout =3D=20
"CHECKED";<BR>  =
; =20
$check_zin =3D "";<BR> } else=20
{<BR> &n=
bsp; =20
$check_pan =3D=20
"";<BR> =
=20
$check_zout =3D=20
"";<BR> =
=20
$check_zin =3D "CHECKED";<BR> =
}</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> =
$val_zsize =3D=20
abs($zoom_factor);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> =20
$myMap->zoompoint($zoom_factor,$my_point,$myMap->width,$myMap->h=
eight,<BR> &nb=
sp; =20
$my_extent);<BR>}elseif($HTTP_POST_VARS["zoom"] =3D=3D=20
2)<BR>{<BR> $xmax =3D=20
$myMap->extent->{xmax};<BR> &nbs=
p;=20
$xmin =3D=20
$myMap->extent->{xmin};<BR> &nbs=
p;=20
$xinc =3D ($xmax - $xmin ) / =
2;<BR> =20
$myMap->setextent( ($xmin + $xinc), $ymin, ($xmax + $xinc),=20
$ymax);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>}<BR>}<BR>$img =3D =
$myMap->draw();<BR>$image_url =3D=20
$img->saveWebImage(GIF,1,1,0);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2><A=20
href=3D"file://$extent_to_html">//$extent_to_html</A> =3D =
$map->extent->minx."=20
".$map->extent->miny."=20
"<BR>// =
=20
.$map->extent->maxx." ".$map->extent->maxy;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial=20
size=3D2>?><BR><BODY><BR><center><BR><table border=3D0 =
cellspacing=3D0 cellpadding=3D4 =
bgcolor=3D"#FFFFFF"><BR><tr><BR><td=20
valign=3D"top" align=3Dcenter><BR> <table cellpadding=3D"0"=20
cellspacing=3D"5" border=3D"5"><BR> =
<tr><td=20
colspan=3D"2"><INPUT NAME=3D"mapa" TYPE=3D"image" SRC=3D"<?php =
echo $image_url;=20
?>" width=3D600 height=3D600=20
border=3D0></td></tr><BR> =20
<tr><BR> <TR><BR> =20
<TD><BR>  =
; =20
Pan<BR> =20
</TD><BR> =20
<TD><BR>  =
; =20
<INPUT TYPE=3DRADIO NAME=3D"zoom" VALUE=3D0 <?php echo=20
$check_pan?>><BR> =20
</TD><BR> </TR><BR> <TR><BR>  =
; =20
<TD><BR>  =
; =20
Zoom In<BR> =20
</TD><BR> =20
<TD><BR>  =
; =20
<INPUT TYPE=3DRADIO NAME=3D"zoom" VALUE=3D1 <?php echo=20
$check_zin?>><BR> =20
</TD><BR> </TR><BR> <TR><BR>  =
; =20
<TD><BR>  =
; =20
Zoom Out<BR> =20
</TD><BR> =20
<TD><BR>  =
; =20
<INPUT TYPE=3DRADIO NAME=3D"zoom" VALUE=3D-1 <?php echo=20
$check_zout?>><BR> =20
</TD><BR> </TR><BR> <TR><BR>  =
; =20
<TD><BR>  =
; =20
Move the map to the right<BR> =20
</TD><BR> =20
<TD><BR>  =
; =20
<INPUT TYPE=3DRADIO NAME=3D"zoom" VALUE=3D2 <?php echo=20
$check_zout?>><BR> =20
</TD><BR> </TR></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial =
size=3D2> <TR><BR> =20
<TD><BR>  =
; =20
Zoom Size<BR> =20
</TD><BR> =20
<TD><BR>  =
; =20
<INPUT TYPE=3DTEXT NAME=3D"zsize" VALUE=3D"<?php echo=20
$val_zsize?>"<BR>  =
; =20
SIZE=3D2><BR> =20
</TD><BR> </TR><BR> <TR><BR>  =
; =20
<TD><BR>  =
; =20
Full Extent<BR> =20
</TD><BR> =20
<TD><BR>  =
; =20
<INPUT TYPE=3DSUBMIT NAME=3D"full"=20
VALUE=3D"Go"<BR> &nb=
sp; =20
SIZE=3D2><BR> =20
</TD><BR></TABLE><BR><INPUT TYPE=3DHIDDEN NAME=3D"extent" =
VALUE=3D"<?php echo=20
$extent_to_html?>"><BR></FORM><BR></CENTER></FONT></DIV=
>
<DIV> </DIV>
<DIV><FONT face=3DArial=20
size=3D2></BODY><BR></HTML></FONT></DIV></BODY></HTML>
------=_NextPart_000_0166_01C3A536.03631CF0--
More information about the MapServer-users
mailing list