<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
h4
        {mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman";
        font-weight:bold;}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
p
        {mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman";}
pre
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:Arial;
        color:windowtext;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
        {page:Section1;}
-->
</style>
</head>
<body link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Hi,</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> </span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>According to the codes samples (<a href="http://trac.osgeo.org/mapguide/wiki/CodeSamples" title="http://trac.osgeo.org/mapguide/wiki/CodeSamples">http://trac.osgeo.org/mapguide/wiki/CodeSamples</a>),
I try to use the PHP code samples to add a layer to the initial map. </span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>I carried out the below code but it seems that “</span></font>$resourceService->SetResource($sessionResourceId,
$byteSource->GetReader(), null);” encounters an error in the code.<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'></span></font></p>
<h4><b><font size=3 face="Times New Roman"><span style='font-size:12.0pt;
font-weight:normal'><?php</span></font></b></h4>
<pre><font size=2 face="Courier New"><span style='font-size:10.0pt'>include "../../mapviewerphp/constants.php";</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'>include "../../mapviewerphp/common.php";</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'>// Initialize</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> MgInitializeWebTier($webconfigFilePath);</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $args = ($_SERVER['REQUEST_METHOD'] == "POST") ? $_POST : $_GET;</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $sessionId = $args['SESSION'];</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $mapName = $args['MAPNAME'];</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $layerName1 = 'YYY';</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $userInfo = new MgUserInformation($sessionId);</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $siteConnection = new MgSiteConnection();</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $siteConnection->Open($userInfo);</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $resourceService = $siteConnection->CreateService(MgServiceType::ResourceService);</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $wl = "Library://XXX/XXX.WebLayout"; // TODO Constant!</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'>// Build a string pointing to the new layer in the Session</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $rlLayerResourceId = "Session:$sessionId//$layerName1.LayerDefinition";</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'>// Read the XML of the Library Map Definition</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $md ="Library://XXX/$mapName.MapDefinition";</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $mdResourceId = new MgResourceIdentifier($md); </span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $mdReader = $resourceService->GetResourceContent($mdResourceId);</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $mdXml = $mdReader->ToString();</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $mdDomDoc = DOMDocument::loadXML($mdXml); </span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'>// Create the MapLayer XML nodeset in the first position</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $targetNode = $mdDomDoc->getElementsByTagName("MapLayer")->item(0);</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $newNode = $targetNode->parentNode->insertBefore(new DOMElement("MapLayer"), $targetNode); </span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $newNode->appendChild($mdDomDoc->createElement("Name", $layerName1));</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $newNode->appendChild($mdDomDoc->createElement("ResourceId", $rlLayerResourceId));</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $newNode->appendChild($mdDomDoc->createElement("Selectable", "false"));</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $newNode->appendChild($mdDomDoc->createElement("ShowInLegend", "false"));</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $newNode->appendChild($mdDomDoc->createElement("LegendLabel"));</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $newNode->appendChild($mdDomDoc->createElement("ExpandInLegend", "false"));</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $newNode->appendChild($mdDomDoc->createElement("Visible", "true"));</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $newNode->appendChild($mdDomDoc->createElement("Group"));</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'>// Write the XML out to form the Session Map Definition</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $updatedXml = $mdDomDoc->saveXML();</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $byteSource = new MgByteSource($updatedXml, strlen($updatedXml));</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'>// Create a web layout in the session to hold the updated version</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'>// from the library.</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $sessionMapName = $mdResourceId->GetName();</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $sessionWebLayout = "Session:$sessionId//$sessionMapName.WebLayout";</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $sessionResourceId = new MgResourceIdentifier($sessionWebLayout);</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'>// Write the updated web layout to the session.</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $resourceService->SetResource($sessionResourceId, $byteSource->GetReader(), null);</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'>// Redirect to the Ajax viewer pointing at the map at the desired coordinates.</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $redirectTo = "mapguide/mapviewerajax/?WEBLAYOUT=$sessionWebLayout&SESSION=$sessionId";</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $host = $_SERVER["HTTP_HOST"];</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $url = "http://$host/$redirectTo";</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'>// Redirect!</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> header("Location: $url");</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> exit;</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'>//Test</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $f = 'exemple.txt';</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> $handle = fopen($f,"w");</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> fwrite($handle, "test0: <".$sessionId.">\r\ntest1 :<".$wl.">\r\ntest2 :<".$rlLayerResourceId.">\r\ntest3 :<".$md.">\r\ntestxml :<".$mdXml.">\r\ntest4 :<".$layerName1.">\r\ntestxml1 :<".$updatedXml.">\r\ntest6 :<".$sessionMapName.">\r\ntest5 :<".$sessionWebLayout.">\r\ntest6 :<".$host.">\r\ntest7 :<".$redirectTo.">");</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> fclose($handle);</span></font></pre>
<h4><b><font size=3 face="Times New Roman"><span style='font-size:12.0pt;
font-weight:normal'>?></span></font></b></h4>
<pre><font size=2 face="Courier New"><span style='font-size:10.0pt'>Please would you like to help me to resolve the following issue?</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'>Thanks,</span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'> </span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'>Arnaud De Groof</span></font></pre>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> </span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> </span></font></p>
</div>
<!--[object_id=#spacebel.be#]--><P><FONT color=#0000ff><FONT face=Tahoma><STRONG>
<HR>
<FONT size=2>E-MAIL DISCLAIMER</FONT></STRONG></FONT></FONT></P>
<P><FONT face=Arial color=#0000ff size=1>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.</FONT></P>
<P><FONT face=Arial color=#0000ff size=1>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.<BR>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.</FONT></P>
<P><FONT face=Arial color=#0000ff size=1>SPACEBEL denies all liability where E-mail is used for private use.</FONT></P>
<P><FONT size=2><FONT face=Arial color=#0000ff size=1>SPACEBEL cannot be held responsible for possible viruses that might corrupt this message and/or your computer system.<BR></FONT></P><FONT face=Arial color=#0000ff>
<HR>
</FONT></FONT>
<P></P></body>
</html>