| MGMap.getWidth |
|
double getWidth(String units)
Gets the current width of the map in the specified unit of measure.
Note that because of the floating-point calculation inaccuracy in operating systems, if you set the width of the map using setWidth before calling getWidth, the value returned by getWidth may be inaccurate, especially if the width is set to a very high number.
units - The unit type, which will be MI (miles), FT (feet), KM (kilometers), (meters), null, or an empty string ("").
Note that null and "" do not work with the ActiveX Control. If you pass in null or empty string, Autodesk MapGuide uses the current unit.
double - The width of the map.
none
The following example is designed to work with the Tutorial.mwf file that is included with Autodesk MapGuide Author. It uses the "KM " argument to display a dialog box showing the height and width of the map in kilometers:
function showSize()
{
var map = getMap();
var width = map.getWidth("KM");
var height = map.getHeight("KM");
alert("width: " + width + ", height: " + height);
}
Here's a more complex use of getHeight() and getWidth(). In the following example, an HTML form lets the user select the unit of measurement from a drop-down list:
<FORM NAME="myForm">
<SELECT NAME="optionList" size="1" onChange="showSize();">
<OPTION VALUE="MI">miles</OPTION>
<OPTION VALUE="FT">feet</OPTION>
<OPTION VALUE="KM">kilometers</OPTION>
<OPTION VALUE="M">meters</OPTION>
</SELECT>
<INPUT TYPE="button" VALUE="Go..." ONCLICK="showSize();">
</FORM>
The form calls a JavaScript function, passing it the value and text properties of the selected form option:
function showSize()
{
var map = getMap();
// For selected form option, get array index, VALUE
// attribute, and option name as it appears in the browser
var idx = window.document.myForm.optionList.selectedIndex;
var val = window.document.myForm.optionList.options[idx].value;
var type = window.document.myForm.optionList.options[idx].text;
// Use val and type to call height/width methods and display alert
alert( "Size is " + map.getWidth(val) + " by " + map.getHeight(val) + " " + type);
}
If the user selected kilometers from the form, showSize would read the selected item's value and text properties ("KM" and "kilometers", respectively). In that case, the line:
alert( "Size is " + map.getWidth(val) + " by " + map.getHeight(val) + " " + type);
Would evaluate as:
alert( "Size is " + map.getWidth("KM") + " by " + map.getHeight("KM") + " " + "kilometers");