[Mapserver-users] Reference map in PHP Mapscript / HTML

Vinko Vrsalovic vinko at cprsig.cl
Fri Nov 14 14:58:52 PST 2003


On Wed, Nov 12, 2003 at 11:05:55AM +0100, Sebastian Albrecht wrote:
> Hello,
> 
> I have a big problem I try to solve since a few days. I've already
> searched the whole archive but did not found anything.
> 
> So far I developed a web interface using PHP Mapscript. It should act
> and work as the Mapserver cgi-bin interface.
> 
> The only problem I have is the reference map. It displays the red box
> correct but I do not right know what to do with the xyinput of the box
> if a user clicks on it.
> Does anybody have an example of how to implement the reference map and
> how to zoom to the correct point in mapscript (language doesn't
> matter)?

you have to define an extent for the reference map, then you can convert
your pixel coords to georreferenced ones and then set the main map
extent accordingly, for instance: (improvised code)

$x_ref = $reference_map['x'];
$y_ref = $reference_map['y']; //assuming the form variable for the
			      //reference map is reference_map

$reference_click = pix2geo($x_ref,$y_ref,$mapobj->reference->extent,
			$mapobj->reference->width,$mapobj->reference->height);

$mapobj->setextent($reference_click->x - 100, $reference_click->y - 100,
		   $reference_click->x + 100, $reference_click->y + 100);

		//Assuming you'll want to center the map on the point
		//clicked on the reference map with 200 units radius

where pix2geo would be:

function pix2geo($pix_x,$pix_y,&$extent,$width,$height) {


                $pix_x_geo_x = ($extent->maxx - $extent->minx)
				 / ($width - 1);
                $pix_x_geo_y = ($extent->maxy - $extent->miny) 
				/ ($height - 1);

                $geo_x = $extent->minx + $pix_x_geo_x*$pix_x;
                $geo_y = $extent->maxy - $pix_x_geo_y*$pix_y;

                $my_point = ms_newPointObj();
                $my_point->setXY($geo_x,$geo_y);

                return $my_point;
}


		
-- 
Vinko Vrsalovic <el[|- at -|]vinko.cl>
http://www.cprsig.cl



More information about the MapServer-users mailing list