This sample illustrates basic page structure. It is designed to be called as a task from a Viewer. It connects to a MapGuide server and displays the map name and spatial reference system for the map currently being displayed in the Viewer. See Running the Example for details about how to install and run this page.
It is also possible to embed a Viewer in your own page, so you can supply your own logo, page header information, or authorization. See Embedding a Viewer in Your Own Page for details.
<html>
<head><title>Hello, map</title></head>
<body>
<p>
<?php
//
Define some common locations
$installDir =
'C:\Program Files\MapGuideOpenSource\\';
$extensionsDir = $installDir . 'WebServerExtensions\www\\';
$viewerDir = $extensionsDir . 'mapviewerphp\\';
// constants.php
is required to set some enumerations
//
for PHP. The same step is not required for .NET
//
or Java applications.
include $viewerDir . 'constants.php';
try
{
//
Get the session information passed from the viewer.
$mgSessionId = ($_SERVER['REQUEST_METHOD'] == "POST")
? $_POST['SESSION']: $_GET['SESSION'];
$mgMapName = ($_SERVER['REQUEST_METHOD'] == "POST")
? $_POST['MAPNAME']: $_GET['MAPNAME'];
//
Basic initialization needs to be done every time.
MgInitializeWebTier("$extensionsDir\webconfig.ini");
//
Get the user information using the session id,
//
and set up a connection to the site server.
$userInfo = new MgUserInformation($mgSessionId);
$siteConnection = new MgSiteConnection();
$siteConnection->Open($userInfo);
//
Get an instance of the required service(s).
$resourceService = $siteConnection->
CreateService(MgServiceType::ResourceService);
//
Display the spatial reference system used for the map.
$map = new MgMap();
$map->Open($resourceService, $mgMapName);
$srs = $map->GetMapSRS();
echo 'Map <strong>' . $map->GetName() .
'</strong> uses this reference system: <br />' . $srs;
}
catch (MgException $e)
{
echo "ERROR: " . $e->GetMessage() . "<br />";
echo $e->GetStackTrace() . "<br />";
}
?>
</p>
</body>
</html>