float CalculateMapScale(Rect boundingBox)
// float CalculateMapScale()
{
// Cache the map's size.
Vector3 mapScale = Map.transform.localScale;
// Find the Map width and height. - In World coords
float mapWidth = RightAnchor.position.x - LeftAnchor.position.x;
float mapHeight = TopAnchor.position.y - BottomAnchor.position.y;
// Calculate the Map aspect ratio.
float mapAspect = mapWidth / mapHeight;
// Work out the Width and Height scales relative to the bounding box.
float newMapWScale = mapWidth / Mathf.Abs(boundingBox.width);
float newMapHScale = mapHeight / Mathf.Abs(boundingBox.height);
/*
Vector3 bbBottomLeft = NGUICam.ScreenToWorldPoint(new Vector3(boundingBox.xMin, boundingBox.yMin, 1));
Debug.Log("bbBottomLeft = " + bbBottomLeft);
Vector3 bbTopRight = NGUICam.ScreenToWorldPoint(new Vector3(boundingBox.xMax, boundingBox.yMax, 1));
Debug.Log("bbTopRight = " + bbTopRight);
Vector3 bbWidthHeight = bbTopRight - bbBottomLeft;
Debug.Log("bbWidthHeight = " + bbWidthHeight);
*/
float newMapScale = 0;
if (newMapWScale >= newMapHScale)
newMapScale = newMapWScale;
else
newMapScale = newMapHScale;
return newMapScale;
}