Changes between Initial Version and Version 1 of CodeSamples/PHP/MPUCalculator


Ignore:
Timestamp:
05/14/12 06:37:05 (13 years ago)
Author:
jng
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CodeSamples/PHP/MPUCalculator

    v1 v1  
     1[[PageOutline]]
     2
     3This page is one of the !MapGuide Community CodeSamples.  Visit the CodeSamples page to view more!
     4
     5== Calculating meters-per-unit ==
     6
     7The 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.
     8
     9The 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.
     10
     11Here 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:
     12
     13http://yourservername:port/mapguide/mpucalc/mpucalc.php?MapDefinition=Library://Path/To/My.MapDefinition
     14
     15eg. http://localhost:8008/mapguide/mpucalc/mpucalc.php?MapDefinition=Library://Samples/Sheboygan/MapsTiled/Sheboygan.MapDefinition
     16
     17It will output the meters-per-unit value for the specified Map Definition.
     18
     19'''mpucalc.php'''
     20{{{
     21#!php
     22<html>
     23    <head>
     24        <title>Meters-per-unit calculator</title>
     25    </head>
     26    <body>
     27    <?php
     28
     29    MgInitializeWebTier(dirname(__FILE__)."/../webconfig.ini");
     30
     31    if (!isset($_REQUEST["MapDefinition"]))
     32    {
     33        echo "ERROR: MapDefinition parameter is required";
     34    }
     35    else
     36    {
     37        $csFactory = new MgCoordinateSystemFactory();
     38        $siteConnection = new MgSiteConnection();
     39        $userInfo = new MgUserInformation("Anonymous", "");
     40        $siteConnection->Open($userInfo);
     41        $map = new MgMap($siteConnection);
     42        $mdfId = new MgResourceIdentifier($_REQUEST["MapDefinition"]);
     43        $map->Create($mdfId, $mdfId->GetName());
     44       
     45        $mapCs = $csFactory->Create($map->GetMapSRS());
     46        $metersPerUnit = $mapCs->ConvertCoordinateSystemUnitsToMeters(1.0);
     47       
     48        echo "Meters per unit is: $metersPerUnit";
     49    }
     50    ?>
     51    </body>
     52</html>
     53}}}