[mapserver-users] PHP mapscript: Custom rectangles overlay

mani2604 mani2604 at gmail.com
Tue Oct 19 04:47:08 EDT 2010

Hi there: 
                Well as u cud see in the image below... we wer trying to
have a custom rectangles overlay the base map... When we provided the
bounding box coordinates directly in the form  of multidimensional array;
sort of like hard-coded them... everything is well and cool..

          Now We r trying to assign check boxes to every array sort of like
user can select/deselect his choice of rectangles..So all we did was to
change the " GetRect() Function "...   Although both the old & new edited
functions yield the same output when I var_dump ($qresult); bt somehow this
time the rectangles doesnt appear.. I tweaked the code but no success yet..

        hoping sumone cud have a look & point out the error...!!@

CheckBox php Code :- 

// GetRect - returns array containing store table
$script_name = "index3.php";
$table =  array(
array('id','state','lat_hi','long_hi','lat_low','long_low'),  //field names
							array(2,'AP',     19.87,84.78,12.59,76.45),
							array(4,'kerala' ,12.75,77.37,08.18,74.86),
							array(5,'punjab' ,32.46,76.93,29.53,73.87),
function GetRect() {
    if (isset($_POST['submit']))
        $tab = $_POST['tab'];

        $qresult = array();
        foreach ($tab as $t)
            $qresult[] = $table[$t];

        return $qresult;

// AddPoints - add store locations to 'poi' map layer

function AddPoints ( $map, $qresult ) {

     $this_layer = $map->getLayerByName('poi');

     $i = 0;
     foreach($qresult as $row) {
        $poi[$i] =  ms_newLineObj();
        $shp[$i] = ms_newShapeObj(MS_SHAPE_POLYGON);
        $shp[$i]->set(index, $row[0]);
        $this_layer->addFeature( $shp[$i] );
} // end AddPoints

$map = ms_newMapObj("/ms4w/apache/htdocs/india_roads3.map");
$extent = array(62.786563, 7.392830, 102.765356, 36.151322);

$qresult = GetRect();
AddPoints( $map, $qresult );



CheckBox Html code

<form method="POST" name="myform2" action="action="<?php echo
$_SERVER['PHP_SELF']; ?>">
    foreach ($table as $id=>$ar)
        <br><input name="tab[]" type="checkbox" value="<?=$id?>">Id :
<?=$id?>, Name : <?=$ar[0]?>
        <br><br><input name="submit" value="submit" type="submit">

This is the php code for GetRect() when we stored the arrays in session;
which is working fine

function GetStoreTable() {


     if (isset($_SESSION['table'])) { 
               foreach ($_SESSION['table'] as $arr) { 
                    if (! isset($arr[$i])) { 
                         $allValuesPresent = 0; 
 // Will get overwritten by query if any are missing 

   return $qresult;

} // end GetStoreTable

Image:-  http://osgeo-org.1803224.n2.nabble.com/file/n5650035/polygon5.jpg 

View this message in context: http://osgeo-org.1803224.n2.nabble.com/PHP-mapscript-Custom-rectangles-overlay-tp5650035p5650035.html
Sent from the Mapserver - User mailing list archive at Nabble.com.

More information about the mapserver-users mailing list