Zoom to Parcel
Kevin Grootendorst
kgrootendorst at BAIRD.COM
Tue Feb 1 07:54:50 PST 2005
Below is the code I'm using to implement a 'zoom to parcel' feature in my
map, where the user inputs a parcel number, and the map will zoom to the
parcel.
For some reason, there is a problem with the 'GetShape' statement, as this
is where the mapserver halts.
Does anyone know what's wrong with the 'GetShape' statement?
MS 4.2
PHP 4.3.4
Win 2000
if (isset( $http_form_vars["parcelnum"]) && ($http_form_vars["parcelnum"]
> "0" ))
{
echo "zoom to parcel";
// the Parcel number to query for
$szParcelNumber = $http_form_vars["parcelnum"];
// the current extents will be the default if we fail.
$oExtents = $oMapSession->oMap->extent;
$oldExtents=$oExtents;
//get layer name
$oParcelLayer = $oMapSession->oMap->getLayerByName( "ParcelData" );
//if (isset($oReachLayer))
//echo "reach is set";
//print_r ($oReachLayer);
$oParcelLayer->queryByAttributes("PIN", $szParcelNumber,
MS_SINGLE );
$results = $oParcelLayer->getNumResults();
//echo "$results";
//now check to see if there are any results
if ($oParcelLayer->getNumResults() > 0 )
{
echo " results2";
//at least one result, assume only one for this example
$oResult = $oParcelLayer->getResult( 0 );
//oResult is a resultCacheMemberObj
$oParcelLayer->open($oMapSession->oMap->shapepath);
echo " results3"; //this is echoed
//**problem with next line
$oShape = $oParcelLayer->GetShape($oResult-
>tileindex,$oResult->shapeindex); //**** problem?
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 "$nMinX";
echo "$nMaxX";
echo "$nMinY";
echo "$nMaxY";
}
else{
echo " no results";}
$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);
}
else
{
echo "parcel is null or negative";
}
More information about the MapServer-users
mailing list