[mapguide-users] Adding a temporary Layer in MapGuide

Arnaud De Groof Arnaud.DeGroof at spacebel.be
Mon Jan 12 10:18:25 EST 2009


The first code :
<?php

// Vital includes.

include "../../mapviewerphp/constants.php";

include "../../mapviewerphp/common.php";

 

 

$args = ($_SERVER['REQUEST_METHOD'] == "POST") ? $_POST : $_GET;

$sessionId = $args['SESSION'];

$mapName = $args['MAPNAME'];

$layerName1 = 'YYY';

$rlLayerResourceId = "Library://XXX/$layerName1.LayerDefinition";

 

InitializeWebTier();

 

$userInfo = new MgUserInformation($sessionId);

$siteConnection = new MgSiteConnection();

$siteConnection->Open($userInfo);

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

 

// Read the MapDefinition into an XML DOM document object.

$md = " Library://XXX/$mapName.MapDefinition "; // TODO Constant!

$mdResourceId = new MgResourceIdentifier($md);

$mdReader = $resourceService->GetResourceContent($mdResourceId);

$mdXml = $mdReader->ToString();

$mdDomDoc = DOMDocument::loadXML($mdXml); 

 

// Add a new MapLayer

$targetNode = $mdDomDoc->getElementsByTagName("MapLayer")->item(0);

$newNode = $targetNode->parentNode->insertBefore(new
DOMElement("MapLayer"), $targetNode); 

$newNode->appendChild($mdDomDoc->createElement("Name", $layerName1));

$newNode->appendChild($mdDomDoc->createElement("ResourceId",
$rlLayerResourceId));

$newNode->appendChild($mdDomDoc->createElement("Selectable", "false"));

$newNode->appendChild($mdDomDoc->createElement("ShowInLegend",
"false"));

$newNode->appendChild($mdDomDoc->createElement("LegendLabel"));

$newNode->appendChild($mdDomDoc->createElement("ExpandInLegend",
"false"));

$newNode->appendChild($mdDomDoc->createElement("Visible", "true"));

$newNode->appendChild($mdDomDoc->createElement("Group"));

 

// Save the updated MapDefinition

$updatedXml = $mdDomDoc->saveXML();

$byteSource = new MgByteSource($updatedXml, strlen($updatedXml));

 

// Create the temporary MapDefinition

$sessionMapName = $mdResourceId->GetName();

$sessionMapDefinition =
"Session:$sessionId//$sessionMapName.MapDefinition";

$sessionResourceId = new MgResourceIdentifier($sessionMapDefinition);

 

// Write the updated MapDefinition

$resourceService->SetResource($sessionResourceId,
$byteSource->GetReader(), null);

 

//Test the updated MapDefinition

$md1 = "Session:$sessionId//X.MapDefinition";

$mdResourceId2 = new MgResourceIdentifier($md1);

$mdReader2 = $resourceService->GetResourceContent($mdResourceId2);

$mdXml2 = $mdReader2->ToString();

$mdDomDoc2 = DOMDocument::loadXML($mdXml2);

 

 

// Read the WebLayout into an XML DOM document object.

$wl = "Library://XXX/XXX.WebLayout"; // TODO Constant!

$wlResourceId = new MgResourceIdentifier($wl);

$wlReader = $resourceService->GetResourceContent($wlResourceId);

$wlXml = $wlReader->ToString();

$wlDomDoc = DOMDocument::loadXML($wlXml); 

 

// Now, update the MapDefinition.

$mapdef = $wlDomDoc->getElementsByTagName("ResourceId")->item(0);

$mapdef->nodeValue = "$md1";

 

// Prepare the updated XML to be written out to the session.

$wlupdatedXml = $wlDomDoc->saveXML();

$wlbyteSource = new MgByteSource($wlupdatedXml, strlen($wlupdatedXml));

 

// Create a temporary WebLayout

$wlsessionMapName = $wlResourceId->GetName();

$wlsessionWebLayout = "Session:$sessionId//$wlsessionMapName.WebLayout";

$wlsessionResourceId = new MgResourceIdentifier($wlsessionWebLayout);

 

// Write the updated WebLayout to the session.

$resourceService->SetResource($wlsessionResourceId,
$wlbyteSource->GetReader(), null);

 

// Redirect to the Ajax viewer.

$redirectTo =
"mapguide/mapviewerajax/?SESSION=$sessionId&WEBLAYOUT=$wlsessionWebLayou
t";

$host = $_SERVER["HTTP_HOST"];

$url = "http://$host/$redirectTo";

 

//Test

$f = 'test.txt';

$handle = fopen($f,"w");

fwrite($handle, "test1:<".$mdXml.">\r\ntest 2 :<".$updatedXml.">\r\ntest
3 :<".$wlXml.">\r\ntest 4 :<".$wlupdatedXml.">\r\ntest 5 :<".$url.">");

fclose($handle);

 

// Redirect!

header("Location: $url");

exit;

 

?>

___________________________________________________________________________________
E-MAIL DISCLAIMER

The present message may contain confidential and/or legally privileged information.
If you are not the intended addressee and in case of a transmission error,
please notify the sender immediately and destroy this E-mail. 
Disclosure, reproduction or distribution of this document and its possible 
attachments is strictly forbidden.

SPACEBEL denies all liability for incomplete, improper, inaccurate, intercepted, 
(partly) destroyed, lost and/or belated transmission of the current information 
given that unencrypted electronic transmission cannot currently be guaranteed 
to be secure or error free. Upon request or in conformity with formal, contractual 
agreements, an originally signed hard copy will be sent to you to confirm 
the information contained in this E-mail.

SPACEBEL denies all liability where E-mail is used for private use.

SPACEBEL cannot be held responsible for possible viruses that might corrupt this 
message and/or your computer system.
____________________________________________________________________________________





More information about the mapguide-users mailing list