The easiest way to programmatically create new layers is to
LayerDefinition-version.xsd schema, which is documented in the MapGuide Web API Reference. This schema closely parallels the UI in the Studio’s Layer Editor, as described in the Studio Help.
The XML schema for layer definitions is defined by theThis example
MapGuide Web API Reference.
You can use the DOM to modify any layers, including ones that already exist in the map, not just new layers that you are adding to the map. You can also use the DOM to modify other resources; the XML schemas are described in the
// (initialization etc. not shown here)
// Open the map
$map = new MgMap();
$map->Open($resourceService, $mapName);
// --------------------------------------------------//
// Load a layer from XML, and use the DOM
to change it
// Load the prototype layer definition into
// a PHP DOM object.
$domDocument =
DOMDocument::load('RecentlyBuilt.LayerDefinition');
if ($domDocument == NULL)
{
echo "The layer definition
'RecentlyBuilt.LayerDefinition' could not be
found.<BR>\n";
return;
}
// Change the filter
$xpath = new DOMXPath($domDocument);
$query = '//AreaRule/Filter';
// Get a list of all the <AreaRule><Filter>
elements in
// the XML.
$nodes = $xpath->query($query);
// Find the correct node and change it
foreach ($nodes as $node )
{
if ($node->nodeValue == 'YRBUILT > 1950')
{
$node->nodeValue = 'YRBUILT > 1980';
}
}
// Change the legend label
$query = '//LegendLabel';
// Get a list of all the <LegendLabel>
elements in the
// XML.
$nodes = $xpath->query($query);
// Find the correct node and change it
foreach ($nodes as $node )
{
if ($node->nodeValue == 'Built after 1950')
{
$node->nodeValue = 'Built after 1980';
}
}
// ...
If you wish to modify an existing layer that is visible in other users’ maps, without affecting those maps: