[Mapserver-users] zoom-to-feature precision varies?

ANDY CANFIELD andy_canfield at hotmail.com
Fri Jul 30 19:31:21 EDT 2004


Dylan,

I have roughly the same thing going as you but I do it like this. I get the 
MBR for all features returned by the query. I calculate the center of that 
MBR and then buffer it by 5% then check to see if the buffered bounds will 
fit at the current zoom level.I do this by comparing the areas of the 
current view with the area of the buffered MBR. If they are I just center 
the buffered MBR by doing a $m_Map->setextent like so:
//claculate the new center
$centX = (($MBRmaxX - $MBRminX) * 0.5) + $MBRminX;
$centY = (($MBRmaxY - $MBRminY) * 0.5) + $MBRminY;

//get the distance in the x and y planes from the center
$dDistX = ($curMaxX - $curMinX) * 0.5;
$dDistY = ($curMaxY - $curMinY) * 0.5;

//recenter the map by setting it's extents
$m_Map->setextent(($centX - $dDistX), ($centY - $dDistY), ($centX + 
$dDistX), ($centY + $dDistY));

the $curMaxX etc are gotten from the map before the setextent like normal:
$curMaxX = $m_Map->extent->maxx;

if they won't fit in the current viewable extents then I do a:
m_Map->setextent(($MBRminX - $buffer), ($MBRminY - $buffer), ($MBRmaxX + 
$buffer), ($MBRmaxY + $buffer));

I am using UTM zone 10 North North American Datum of 83 which is probably 
very close to what you are using if not the exact same one.

Hope it helps,
Andy


>From: Dylan Keon <keon at nacse.org>
>To: mapserver-users at lists.gis.umn.edu
>Subject: [Mapserver-users] zoom-to-feature precision varies?
>Date: Fri, 30 Jul 2004 11:08:27 -0700
>
>I'm working on an app that allows the user to zoom to a feature after 
>querying the map.  I grab the $shapeObj->bounds of the feature (UTM 
>coords), calculate the center of the bounding box, and use zoomScale() to 
>zoom centered on that feature.
>
>It works great when the map is already zoomed in to a relatively small 
>extent - it zooms in a bit further and centers perfectly on the feature.  
>However, when starting from the full map extent, it's hit and miss. After 
>zooming in all the way, the feature will usually appear somewhere on the 
>map view, it just won't be centered.  If you tmmhen click that feature's 
>button again on the resulting page, it will center perfectly.
>
>It looks like it's not precise enough when zooming from a large extent to a 
>small extent, but zooming a small amount works great when trying to center 
>on a point.  Has anyone else noticed this?  Or is it more likely my code?  
>I found the same behavior when using zoomRectangle().
>
>If it helps, take a look at http://gis.nacse.org/temp/demo/index.php
>
>Thanks,
>--Dylan
>_______________________________________________
>Mapserver-users mailing list
>Mapserver-users at lists.gis.umn.edu
>http://lists.gis.umn.edu/mailman/listinfo/mapserver-users

_________________________________________________________________
Don’t just search. Find. Check out the new MSN Search! 
http://search.msn.click-url.com/go/onm00200636ave/direct/01/




More information about the mapserver-users mailing list