Rename Roads Layer
Open($userInfo);
$map = new MgMap($siteConnection);
$map->Open($mgMapName);
$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();
echo "Layer label has been changed to $newLabel.
";
echo 'Run again
';
}
catch (MgLayerNotFoundException $e)
{
echo 'Layer not found
';
}
catch (MgObjectNotFoundException $e)
{
echo 'Layer not found
';
}
catch (MgException $e)
{
echo $e->GetExceptionMessage();
echo $e->GetDetails();
}
?>