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

Kenneth Skovhede, GEOGRAF A/S ks at geograf.dk
Sun Dec 28 06:33:56 EST 2008


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";
>
>  
>
> // 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] *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
>
>  
>
>   
>
> *
> ------------------------------------------------------------------------
> 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
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20081228/59f870cf/attachment.html


More information about the mapguide-users mailing list