Open($userInfo); $resourceService = $siteConnection->CreateService(MgServiceType::ResourceService); // --------------------------------------------------// // Open the map $map = new MgMap($siteConnection); $map->Open($mapName); // ... // --------------------------------------------------// // Load a layer from XML, and use the DOM to change it // Load the prototype layer definition into // a PHP DOM object. $domDocument = new DOMDocument(); $domDocument->load('RecentlyBuilt.LayerDefinition'); // Change the filter $xpath = new DOMXPath($domDocument); $query = '//AreaRule/Filter'; // Get a list of all the 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 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'; } } // --------------------------------------------------// // ... // Add the layer to the map $layerDefinition = $domDocument->saveXML(); $newLayer = add_layer_definition_to_map($layerDefinition, "RecentlyBuilt", "Built after 1980", $sessionId, $resourceService, $map); add_layer_to_group($newLayer, "Analysis", "Analysis", $map); // --------------------------------------------------// // Turn off the "Square Footage" themed layer (if it // exists) so it does not hide this layer. $layerCollection = $map->GetLayers(); if ($layerCollection->Contains("SquareFootage")) { $squareFootageLayer = $layerCollection->GetItem("SquareFootage"); $squareFootageLayer->SetVisible(false); } // --------------------------------------------------// // Turn on the visibility of this layer. // (If the layer does not already exist in the map, it will be visible by default when it is added. // But if the user has already run this script, he or she may have set the layer to be invisible.) $layerCollection = $map->GetLayers(); if ($layerCollection->Contains("RecentlyBuilt")) { $recentlyBuiltLayer = $layerCollection->GetItem("RecentlyBuilt"); $recentlyBuiltLayer->SetVisible(true); } // --------------------------------------------------// // Save the map back to the session repository $map->Save(); // --------------------------------------------------// } catch (MgException $e) { echo " \n"; } ?>