#1 Fri 19 December 2008 10:14
- adegroof
- Participant occasionnel
- Date d'inscription: 15 Oct 2008
- Messages: 13
[MapGuide OS] ajout d'un layer à la vue initial
Bonjour,
En suivant les 2 exemples fournis à l'adresse suivante : http://trac.osgeo.org/mapguide/wiki/CodeSamples. Je tente d'introduire une application permettant d'introduire dans la vue initial de mapguide un nouveau layer pour une session déterminée (pas de sauvegarde dans la librairie).
Malheureusement je n'arrive pas à faire fonctionner cette application, le process "$resourceService->SetResource($sessionResourceId,$byteSource->GetReader(), null);" semble en effet planter le code que voici:
Code:
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);
Pourriez-vous m'aider à résoudre ce problème.
Merci
Hors ligne
#2 Tue 27 January 2009 00:14
- poulet1212
- Participant actif
- Date d'inscription: 10 Apr 2007
- Messages: 74
Re: [MapGuide OS] ajout d'un layer à la vue initial
Salut,
A froid comme ça je dirais de vérifier les droits de l'utilisateur authentifié. Je crois que pour bricoler des ressources comme ça il faut avoir le rôle MapAuthor.
Sinon, regarde aussi les exemples des generic tasks, ils y probablement la problématique que tu cherches et les codes sources sont naturellement disponibles.
http://data.mapguide.com/mapguide/gt/index.php
Hors ligne
#3 Tue 03 February 2009 16:22
- adegroof
- Participant occasionnel
- Date d'inscription: 15 Oct 2008
- Messages: 13
Re: [MapGuide OS] ajout d'un layer à la vue initial
Merci.
Voic la réponse à ma propre question :
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); // Insert the layer in the MapDefinition $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 MapDefinition $updatedXml = $mdDomDoc->saveXML(); $byteSource = new MgByteSource($updatedXml, strlen($updatedXml)); // Create a new MapDefinition (session repository). $sessionMapName = $mdResourceId->GetName(); $sessionMapDefinition = "Session:$sessionId//$sessionMapName.MapDefinition"; $sessionResourceId = new MgResourceIdentifier($sessionMapDefinition); // Write the updated MapDefinition $resourceService->SetResource($sessionResourceId, $byteSource->GetReader(), null); // Test the new MapDefinition $mdtest = "Session:$sessionId///$mapName.MapDefinition"; $mdResourceIdtest = new MgResourceIdentifier($mdtest); $mdReadertest = $resourceService->GetResourceContent($mdResourceIdtest); $mdXmltest = $mdReader2->ToString(); $mdDomDoctest = DOMDocument::loadXML($mdXmltest); // 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;
Hors ligne