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

Kenneth Skovhede, GEOGRAF A/S ks at geograf.dk
Tue Jan 6 15:35:18 EST 2009


Not in PHP, but a javascript like this should do it:
top.location.reload();

Regards, Kenneth Skovhede, GEOGRAF A/S



Arnaud De Groof skrev:
>
> OK, in fact my comprehension of the "target" was incorrect. It was not 
> necessary to use the target to view the new temporary Weblayout; a 
> simple refresh allows it.
>
> Is it possible to refresh directly the viewer by adding a line in the 
> php code? I saw a RefreshMap.js.
>
>  
>
> Regards,
>
>  
>
> Arnaud De Groof
>
>  
>
> ------------------------------------------------------------------------
>
> *From:* mapguide-users-bounces at lists.osgeo.org 
> [mailto:mapguide-users-bounces at lists.osgeo.org] *On Behalf Of *Kenneth 
> Skovhede, GEOGRAF A/S
> *Sent:* mardi 6 janvier 2009 13:58
> *To:* MapGuide Users Mail List
> *Subject:* Re: [mapguide-users] create a temporary !Mapdefinition and 
> add a layer
>
>  
>
> The "Target" stuff refers to clicking on a link on a feature.
>
> The PHP code below only relocates the current page.
> This means that the new window is created *before* the
> code below is being run. Try locating that spot,
> and change the target to "_top" or "_self".
>
> For explanation on the targets, look here:
> http://www.codetoad.com/html/frames/specifying_frames.asp
>
> If you are actually modifying the WebLayout when clicking a feature,
> the target should probably be set to "_parent" in Maestro.
> After setting the target, press the "View Xml" button to
> see what changes your code has to make to achieve the same.
>
> Regards, Kenneth Skovhede, GEOGRAF A/S
>
>
>
> Arnaud De Groof skrev:
>
> Hi Kenneth,
>
>  
>
> Thanks to your precisions, all the code is correct.
>
> I have a specific question. The new temporary WebLayout appears in a 
> new window. Is it possible to update only the current viewer with this 
> new temporary WebLayout? I don't find specific command in Maestro for it.
>
> Invoke URL command:
>
> -> Extra properties
>
> Target :
>
>     * NewWindow = WebLayout in a new window
>     * SpecifiedFrame = WebLayout in a new window (I have used the "id"
>       of the Viewer Frame)
>     * TaskPane = WebLayout in the Taskpane
>
>  
>
> Thanks
>
>  
>
> Arnaud De Groof
>
>  
>
>  
>
> The new 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=$wlsessionWebLayout";
>
> $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;
>
>  
>
> ?>
>
>  
>
> ------------------------------------------------------------------------
>
> *From:* mapguide-users-bounces at lists.osgeo.org 
> <mailto:mapguide-users-bounces at lists.osgeo.org> 
> [mailto:mapguide-users-bounces at lists.osgeo.org] *On Behalf Of *Kenneth 
> Skovhede, GEOGRAF A/S
> *Sent:* dimanche 28 décembre 2008 12:34
> *To:* MapGuide Users Mail List
> *Subject:* Re: [mapguide-users] create a temporary !Mapdefinition and 
> add a layer
>
>  
>
> You must also make a temporary WebLayout.
> This WebLayout must then point to the temporary MapDefinition.
>
> In one of the last lines, you redirect to the temporary WebLayout.
> If that temporary WebLayout points to the temporary MapDefinition,
> all should be good. (Assuming layer is visible, in range, on top, etc.).
>
> Regards, Kenneth Skovhede, GEOGRAF A/S
>
>
>
> Arnaud De Groof skrev:
>
> Hi,
>
>  
>
> I have found my error. In fact, I used the command "SetRessource" with 
> a WebLayout in place of a MapDefinition. Now the script seems ok.
>
>  
>
> How to load the WebLayout with the new MapDefinition (with the new 
> layer) and not the MapDefinition coming from the library (without the 
> new layer)?
>
>  
>
>  
>
> New 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" <http://$host/$redirectTo>;
>
>  
>
> // Redirect!
>
>    header("Location: $url");
>
>    exit;
>
>  
>
>  
>
> Thanks,
>
>  
>
> Arnaud De Groof
>
>  
>
>  
>
> ------------------------------------------------------------------------
>
> *From:* mapguide-users-bounces at lists.osgeo.org 
> <mailto:mapguide-users-bounces at lists.osgeo.org> 
> [mailto:mapguide-users-bounces at lists.osgeo.org] *On Behalf Of *Kenneth 
> Skovhede, GEOGRAF A/S
> *Sent:* mardi 23 décembre 2008 8:15
> *To:* MapGuide Users Mail List
> *Subject:* Re: [mapguide-users] create a temporary !Mapdefinition and 
> add a layer
>
>  
>
> The previous error you had indicated that the xml was invalid.
>
> This is likely because you are not sending the entire xml document to 
> the server.
> Perhaps someone with better PHP skills can help you out.
>
> Regards, Kenneth Skovhede, GEOGRAF A/S
>
>
>
> Arnaud De Groof skrev:
>
> I have changed the line: "$byteSource = new MgByteSource($updatedXml, strlen($updatedXml));" by "$byteSource = new MgByteSource($updatedXml, mb_strlen($updatedXml));"  without success.
>
>  
>
> The xml code coming from the initial MapDefinition was carried out 
> thanks to Maestro. I join here the result of the $updatedXml:
>
>  
>
> <?xml version="1.0" encoding="utf-8"?>
>
> <MapDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
> <http://www.w3.org/2001/XMLSchema-instance> 
> xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
> <http://www.w3.org/2001/XMLSchema> 
> xsi:noNamespaceSchemaLocation="MapDefinition-1.0.0.xsd">
>
>   <Name>New Map</Name>
>
>   <CoordinateSystem>PROJCS["WGS 84 / UTM zone 48N",GEOGCS["WGS 
> 84",DATUM["WGS_1984",SPHEROID["WGS 
> 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",105],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","32648"]]</CoordinateSystem>
>
>   <Extents>
>
>     <MinX>608404.999984747</MinX>
>
>     <MaxX>641160.000015253</MaxX>
>
>     <MinY>1121406.87752137</MinY>
>
>     <MaxY>1142427.99990895</MaxY>
>
>   </Extents>
>
>   <BackgroundColor>ffffffff</BackgroundColor>
>
>   <Metadata/>
>
>   
> <MapLayer><Name>YYY</Name><ResourceId>Session:92b640a0-ffff-ffff-8002-001aa0d22567_fr_7F0000010AFC0AFB0AFA// 
> YYY.LayerDefinition</ResourceId><Selectable>false</Selectable><ShowInLegend>false</ShowInLegend><LegendLabel/><ExpandInLegend>false</ExpandInLegend><Visible>true</Visible><Group/></MapLayer><MapLayer>
>
>     <Name>Station</Name>
>
>     <ResourceId>Library://XXX/Station.LayerDefinition</ResourceId>
>
>     <...
>
>  
>
> Thanks for your help.
>
>  
>
> Regards,
>
>  
>
> Arnaud De Groof
>
>  
>
>   
>
> **<hr size=2 width="100%" align=center> **
>
> **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.
>
> ------------------------------------------------------------------------
>  
>  
>  
>  
>  
>
>
> ------------------------------------------------------------------------
>
>
>  
>  
>  
>  
>  
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org <mailto:mapguide-users at lists.osgeo.org>
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>   
>  
>
>
> ------------------------------------------------------------------------
>
>
>  
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org <mailto:mapguide-users at lists.osgeo.org>
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20090106/a71cf993/attachment.html


More information about the mapguide-users mailing list