[[PageOutline]] This page is one of the !MapGuide Community CodeSamples. Visit the CodeSamples page to view more! == Calculating meters-per-unit == '''NOTE: As of MapGuide Open Source 2.6, [wiki:MapGuideRfc134 the CREATERUNTIMEMAP operation in the mapagent] can return this value for you, thus it is no longer necessary to use this script for the purpose of obtaining this value for MapGuide 2.6 onwards''' The meters-per-unit is a crucial value needed for calculating scales and setting up appropriate parameters for rendering. If you are using the AJAX/Fusion viewers, this value is automatically calculated for you, but is not accessible via methods in the MgMap class. If you are setting up a simple MapGuide viewer with [http://www.openlayers.org OpenLayers] or are setting up a tiling run with MgCooker using the official method, you need to have this value defined. The ability to calculate this value is available via the official MapGuide API, but not via the HTTP mapagent. This is why applications like MgCooker require you to fill in this value manually because it does not have the ability to calculate this value using the HTTP APIs provided by MapGuide. Here is a simple PHP script that can automatically calculate the meters-per-unit value, save the contents of the script below into a directory under the '''www''' directory of your MapGuide installation (eg. mpucalc) and open the following URL in your web browser: http://yourservername:port/mapguide/mpucalc/mpucalc.php?MapDefinition=Library://Path/To/My.MapDefinition eg. http://localhost:8008/mapguide/mpucalc/mpucalc.php?MapDefinition=Library://Samples/Sheboygan/MapsTiled/Sheboygan.MapDefinition It will output the meters-per-unit value for the specified Map Definition. '''mpucalc.php''' {{{ #!php Meters-per-unit calculator Open($userInfo); $map = new MgMap($siteConnection); $mdfId = new MgResourceIdentifier($_REQUEST["MapDefinition"]); $map->Create($mdfId, $mdfId->GetName()); $mapCs = $csFactory->Create($map->GetMapSRS()); $metersPerUnit = $mapCs->ConvertCoordinateSystemUnitsToMeters(1.0); echo "Meters per unit is: $metersPerUnit"; } ?> }}}