[maplab-users] Zoom to Point functionality

kgrootendorst at baird.com kgrootendorst at baird.com
Wed Feb 2 09:24:03 EST 2005


List,
I'm trying to implement a zoom to point function, where by a user 
specifies a point (reach) number, clicks on a submit button, and the map 
will zoom to the point.
However, I'm having trouble with a GetShape statement.  Something isn't 
right.  The mapserver stops at this particular line of code:

$oShape = 
$oReachLayer->getShape($oResult->tileindex,$oResult->shapeindex);

Below is my code for this feature.  You'll see that I still have to modify 
the code for zooming to a point rather than a polygon, but I haven't got 
that far yet.
I've searched the MapServer list and posted, but with no luck.  Using MS 
4.2, php 4.3.4.

Thanks in advance.

Kevin 

Code:

if (isset( $http_form_vars["doReachZoom"]) && 
($http_form_vars["doReachZoom"] > "0" ))
{
        //echo "zoom to reach";
        // the reach number to query for
        $szReachNumber = $http_form_vars["reachnum"];

        // the current extents will be the default if we fail.
        $oExtents = $oMapSession->oMap->extent;
        $oldExtents=$oExtents;

        //first we need a handle on the layer, let's assume that we have
        //it's name
        $oReachLayer = $oMapSession->oMap->getLayerByName( "Reaches" );

        $oReachLayer->queryByAttributes("REACH", $szReachNumber, MS_SINGLE 
);
        //echo ("$szReachNumber");
        $results = $oReachLayer->getNumResults();
        //echo ("-- $results --");
        //now check to see if there are any results?
        if ($oReachLayer->getNumResults() > 0 )
        {
                //echo " results2";
                //at least one result, assume only one for this example
                $oResult = $oReachLayer->getResult(0);
 
                //oResult is a resultCacheMemberObj
                $oReachLayer->open($oMapSession->oMap->shapepath);
                echo " results3";   // THIS IS ECHOED
                $oShape = 
$oReachLayer->getShape($oResult->tileindex,$oResult->shapeindex); //  IS 
THERE A PROBLEM WITH THIS LINE???
                echo " results4";  // THIS IS NOT ECHOED 
                $oExtents = $oShape->bounds;
                echo " results5";
                //$oShape->free();

                //at this point we might add a buffer to the extents
                $nXBuffer = ( $oExtents->maxx - $oExtents->minx )*0.05;
                $nYBuffer = ( $oExtents->maxy - $oExtents->miny )*0.05;
                $nMinX = $oExtents->minx - $nXBuffer;
                $nMaxX = $oExtents->maxx + $nXBuffer;
                $nMinY = $oExtents->miny - $nYBuffer;
                $nMaxY = $oExtents->maxy + $nYBuffer;
                $oExtents->setextent( $nMinX, $nMinY, $nMaxX, $nMaxY );
echo "oExtents have been set";
        }
//      else{
//       echo " no results";}



        // now use $oMapNavigator to navigate to the parcel
        // location. There are two useful options now. We
        // can zoom to a rectangle which we have calculated or
        // to a point and scale. Let's assume we have calculated
        // a rectangle and put a buffer around it if necessary.
        //$width=$oMapSession->oMap->width;
//      $height=$oMapSession->oMap->height;

// 
$px1=$width/($oldExtents->maxx-$oldExtents->minx)*($oExtents->minx-$oldExtents->minx);
// 
$px2=$width/($oldExtents->maxx-$oldExtents->minx)*($oExtents->maxx-$oldExtents->minx);
// 
$py1=$height/($oldExtents->maxy-$oldExtents->miny)*($oldExtents->maxy-$oExtents->maxy);
// 
$py2=$height/($oldExtents->maxy-$oldExtents->miny)*($oldExtents->maxy-$oExtents->miny);

        //$oMapNavigator->zoomRectangle($px1, $py2, $px2, $py1);

        // alternately if it's a point and a scale ...
        $oMapNavigator->zoomScale( 1000, 100, 100 );
}
else
{
echo "reach is null or negative";
}

______________________________
Baird 
Innovation, Excellence, & Service 
Oceans, Lakes & Rivers
Kevin Grootendorst 
905-845-5385 phone    905-845-0698 fax
627 Lyons Lane, Suite 200
Oakville, Ontario, Canada L6J 5Z7 
mailto:kgrootendorst at baird.com    http://www.baird.com/ 
______________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maptools.org/pipermail/maplab-users/attachments/20050202/4fd176db/attachment-0001.html


More information about the Maplab-users mailing list