|
Hi,
Most of the suggestions were similar:
Find the width of the object
Find the width of the window
Zoom to the width of the object, and play around with width:height ratios
to make sure everything fits in the window. Code follows - Sub from part
of an application I'm writing which requires a maximised
window. I haven't tried it for a re-sized window. This code
also doesn't allow for margins (objects will extend to window limit in one
dimension), and was thrown together fairly quickly - it does seem to work
though! Written with MB6.0 (MBR() function may not be available
on versions earlier than 5.5?)
Thanks to Jacques Paris and David Haycraft for code snippets:
- Sub ZoomObject (AnObj as object)
'30.11.2000. Following
discussion with Jacques Paris, add sub that will 'zoom the map view to the
total extents of the current object. This will be used 'during
blocklabelling and while defining the direction & number of rows to
create ' Dim MBR_AnObj as object Dim CosmeticName as string Dim
Ob_Height,Ob_Width,x,y,x1,y1,x2,y2 as float Dim WinH,WinW,WinRatio,Objratio
as float
'get the minimum bounding rectangle of the object. MBR_AnObj =
MBR(AnObj)
- 'get the nume of the map windows cosmetic layer
CosmeticName =
Windowinfo(FrontWindow(),WIN_INFO_TABLE)
- 'add this object to the cosmetic layer
Insert Into CosmeticName (Obj)
Values (MBR_AnObj)
- 'get the centre of the MBR_AnObj
x = CentroidX(MBR_AnObj) y =
CentroidY(MBR_AnObj)
- 'get the width and height of the mapper window
WinH =
WindowInfo(FrontWindow(),WIN_INFO_HEIGHT) WinW =
WindowInfo(FrontWindow(),WIN_INFO_WIDTH)
- 'calculate the width to height ratio for the window
Winratio =
WinW/WinH
- 'get the width of the MBR_AnObj (in metres)
x1 =
ObjectGeography(MBR_AnObj,OBJ_GEO_MINX) x2 =
ObjectGeography(MBR_AnObj,OBJ_GEO_MAXX) y1 =
ObjectGeography(MBR_AnObj,OBJ_GEO_MINY) y2 =
ObjectGeography(MBR_AnObj,OBJ_GEO_MAXY)
- Ob_Width = distance(x1,y1,x2,y1,"m")
Ob_Height=
distance(x1,y1,x1,y2,"m")
- 'calculate the width to height ratio for the
object
ObjRatio=Ob_Width/Ob_height
- 'Zoom to the centre of the object. The zoom width depends on the w:h
ratio.
if WinRatio>ObjRatio then Set Map Center (x,y)
Zoom (Ob_Height*Winratio) Units "m" else Set Map Center (x,y) Zoom
(Ob_Height*Objratio) Units "m" end if
- 'clear the cosmetic layer
Delete from CosmeticName
- 'end sub - execution passes back to calling sub.
End Sub
|