Zoom - php help

Kevin Grootendorst kgrootendorst at BAIRD.COM
Thu Feb 3 10:42:36 EST 2005


Below is code I've used for zooming to a polygon. Can anyone point me in
the right direction for zooming to a point feature?  I'm unclear as to how
I determine and set the extents for a point.
Thanks.

if (isset( $http_form_vars["doParcelZoom"]) && ($http_form_vars
["doParcelZoom"] > "0" ))
{
 echo "zoom to parcel";

 // the Parcel number to query for
 $szParcelNumber = $http_form_vars["parcelnum"];
 echo "$szParcelNumber";
 // the current extents will be the default if we fail.
 $oExtents = $oMapSession->oMap->extent;
 $oldExtents=$oExtents;

 //get layer name
 $oParcelLayer = $oMapSession->oMap->getLayerByName( "ParcelData" );

 $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);
  $oParcelLayer->open();
  echo " results3";
  $oShape = $oParcelLayer->GetShape($oResult-
>tileindex,$oResult->shapeindex); //**** problem?
  echo " results4";
  $oExtents = $oShape->bounds;
  echo " results5";
  $oShape->free();

  //at this point we might add a buffer to the extents
  $nXBuffer = ( $oExtents->maxx - $oExtents->minx )*5;
  $nYBuffer = ( $oExtents->maxy - $oExtents->miny )*5;
  $nMinX = $oExtents->minx - $nXBuffer;
  $nMaxX = $oExtents->maxx + $nXBuffer;
  $nMinY = $oExtents->miny - $nYBuffer;
  $nMaxY = $oExtents->maxy + $nYBuffer;
  //$nMinX = $oExtents->minx;
  //$nMaxX = $oExtents->maxx;
  //$nMinY = $oExtents->miny;
  //$nMaxY = $oExtents->maxy;
  $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;

 //set map in pixel units
 $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);
 //$oMapNavigator->zoomRectangle($nMinX, $nMaxX, $nMinY, $nMaxY);
 //$oMapNavigator->zoomRectangle($px1, $py1, $px2, $py2);
}
else
{
echo "parcel is null or negative";
}



More information about the mapserver-users mailing list