Example
 
 

The following example toggles the name of the Roads layer between Roads and Streets.

$awSessionId = ($_SERVER['REQUEST_METHOD'] == "POST")?

   $_POST['SESSION']: $_GET['SESSION'];

try

{

   //

Initialize the Web Extensions and connect to the Server using

   //

the Web Extensions session identifier stored in PHP

   //

session state

.

 

   // $configFilePath

is the path to the web server configuration

   MgInitializeWebTier ($configFilePath);

 

   $userInfo = new MgUserInformation($awSessionId);

   $siteConnection = new MgSiteConnection();

   $siteConnection->Open($userInfo);

 

   $resourceService =

   $siteConnection->CreateService(MgServiceType::ResourceService);

 

   $map = new MgMap();

   $map->Open($resourceService, 'Sheboygan');

 

   $layers = $map->GetLayers();

 

   $roadLayer = $layers->GetItem('Roads');

   $roadLabel = $roadLayer->GetLegendLabel();

   if ($roadLabel == 'Roads')

      $newLabel = 'Streets';

   else

      $newLabel = 'Roads';

 

   $roadLayer->SetLegendLabel($newLabel);

 

   //

You must save the updated map or the

   //

changes will not be applied

   //

Also be sure to refresh the map on page load.

   $map->Save($resourceService);

 

   echo '<p>Layer label has been changed.</p>';

 

}

catch (MgLayerNotFoundException $e)

{

   echo '<p>Layer not found</p>';

}

catch (MgObjectNotFoundException $e)

{

   echo '<p>Layer not found</p>';

}

catch (MgException $e)

{

   echo $e->GetMessage();

   echo $e->GetDetails();

}