[mapguide-users] create a temporary !Mapdefinition and add a layer

Arnaud De Groof Arnaud.DeGroof at spacebel.be
Fri Dec 19 05:23:29 EST 2008


Hi,

 

According to the codes samples
(http://trac.osgeo.org/mapguide/wiki/CodeSamples), I try to use the PHP
code samples to add a layer to the initial map. 

I carried out the below code but it seems that
"$resourceService->SetResource($sessionResourceId,
$byteSource->GetReader(), null);" encounters an error in the code.


<?php

include "../../mapviewerphp/constants.php";
include "../../mapviewerphp/common.php";
 
// Initialize
    MgInitializeWebTier($webconfigFilePath);
    $args = ($_SERVER['REQUEST_METHOD'] == "POST") ? $_POST : $_GET;
    $sessionId = $args['SESSION'];
    $mapName = $args['MAPNAME'];
    $layerName1 = 'YYY';
    
    $userInfo = new MgUserInformation($sessionId);
    $siteConnection = new MgSiteConnection();
    $siteConnection->Open($userInfo);
    $resourceService =
$siteConnection->CreateService(MgServiceType::ResourceService);
 
    $wl = "Library://XXX/XXX.WebLayout"; // TODO Constant!
 
// Build a string pointing to the new layer in the Session
    $rlLayerResourceId =
"Session:$sessionId//$layerName1.LayerDefinition";
 
// Read the XML of the Library Map Definition
   $md ="Library://XXX/$mapName.MapDefinition";
   $mdResourceId = new MgResourceIdentifier($md);  
   $mdReader = $resourceService->GetResourceContent($mdResourceId);
   $mdXml = $mdReader->ToString();
   $mdDomDoc = DOMDocument::loadXML($mdXml); 
 
// Create the MapLayer XML nodeset in the first position
   $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"));
 
// Write the XML out to form the Session Map Definition
   $updatedXml = $mdDomDoc->saveXML();
   $byteSource = new MgByteSource($updatedXml, strlen($updatedXml));
 
// Create a web layout in the session to hold the updated version
// from the library.
   $sessionMapName = $mdResourceId->GetName();
   $sessionWebLayout = "Session:$sessionId//$sessionMapName.WebLayout";
   $sessionResourceId = new MgResourceIdentifier($sessionWebLayout);
 
// Write the updated web layout to the session.
   $resourceService->SetResource($sessionResourceId,
$byteSource->GetReader(), null);
 
// Redirect to the Ajax viewer pointing at the map at the desired
coordinates.
   $redirectTo =
"mapguide/mapviewerajax/?WEBLAYOUT=$sessionWebLayout&SESSION=$sessionId"
;
   $host = $_SERVER["HTTP_HOST"];
   $url = "http://$host/$redirectTo";
 
 
// Redirect!
   header("Location: $url");
   exit;
 
//Test
   $f = 'exemple.txt';
   $handle = fopen($f,"w");
   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.">");
   fclose($handle);

?>

Please would you like to help me to resolve the following issue?
 
Thanks,
 
Arnaud De Groof

 

 


___________________________________________________________________________________
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.
____________________________________________________________________________________



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20081219/5a8d1b63/attachment.html


More information about the mapguide-users mailing list