[mapguide-users] Adding a temporary Layer in MapGuide

Carmelo Saffioti csaffi at libero.it
Mon Jan 12 09:32:58 EST 2009


Excuse me Arnaud,
but where is that "last" code? The only code I see is that on your first post...

  ----- Original Message ----- 
  From: Arnaud De Groof 
  To: MapGuide Users Mail List 
  Sent: Monday, January 12, 2009 3:21 PM
  Subject: RE: [mapguide-users] Adding a temporary Layer in MapGuide


  The last code is enough. 

  My first code included only the step 3 and 4. 



  Regards




------------------------------------------------------------------------------

  From: mapguide-users-bounces at lists.osgeo.org [mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Carmelo Saffioti
  Sent: lundi 12 janvier 2009 12:24
  To: MapGuide Users Mail List
  Subject: Re: [mapguide-users] Adding a temporary Layer in MapGuide



  Thank you Arnaud for your reply!

  You said: "Please find an example of code for the different steps". What do you mean?

  The code you posted is not enough?



  If it's not enough, which of the following steps can I do with that code?

  1. Create a temporary FeatureSource for an SDF
  2. Insert data into the temporary FeatureSource
  3. Create a temporary LayerDefinition that points to the temporary FeatureSource
  4. Insert the temporary layer into the runtime map
  5. Refresh the map



  Thank you very much again for your help

  Cheers

  Carmelo

    

    ----- Original Message ----- 

    From: Arnaud De Groof 

    To: MapGuide Users Mail List 

    Sent: Friday, January 09, 2009 9:37 AM

    Subject: RE: [mapguide-users] Adding a temporary Layer in MapGuide



    Hi,



    Please find an example of code for the different steps: 



    <?php



    include "../../mapviewerphp/constants.php";

    include "../../mapviewerphp/common.php";

    //include 'common.php';

    //include 'constants.php';



    $args = ($_SERVER['REQUEST_METHOD'] == "POST") ? $_POST : $_GET;

    $sessionId = $args['SESSION'];

    $mapName = $args['MAPNAME'];



        $locale = "en";

        $dataName = "test";

        $popup = 0;

        $lcolor = "0000ff";

        $ffcolor = "ff0000";

        $fbcolor = "ffffff";

        $transparent = 0;

        $distance = 0;

        $units = "Points";

        $linestyle = "Solid";

        $fillstyle = "Solid";

        $thickness = 1;

        $merge = 0;

        $foretrans = 50;

        $srs = "";

        $featureName = "Z";

        $params = null;





        //SetLocalizedFilesPath(GetLocalizationPath());



        $dataSource = "Session:" . $sessionId . "//" . $dataName . ".FeatureSource";

        $layerDef = "Session:" . $sessionId . "//" . $dataName . ".LayerDefinition";



            InitializeWebTier();



            $cred = new MgUserInformation($sessionId);

            $cred->SetClientIp(GetClientIp());

            $cred->SetClientAgent(GetClientAgent());



            //connect to the site and get a feature service and a resource service instances

            $site = new MgSiteConnection();

            $site->Open($cred);

            $featureSrvc = $site->CreateService(MgServiceType::FeatureService);

            $resourceSrvc = $site->CreateService(MgServiceType::ResourceService);



            $dataSourceId = new MgResourceIdentifier($dataSource);

            $layerDefId = new MgResourceIdentifier($layerDef);



            //load the map runtime state

            $map = new MgMap();

            $map->Open($resourceSrvc, $mapName);



            //locate the buffer layer in the map. It might or might not already exist

            $layers = $map->GetLayers();



            // Get the map SRS

            $srsFactory = new MgCoordinateSystemFactory();

            $srsDefMap = GetMapSRS($map);

            $mapSrsUnits = "";

            $srsMap = $srsFactory->Create($srsDefMap);

            $arbitraryMapSrs = $srsMap->GetType() == MgCoordinateSystemType::Arbitrary;

            if($arbitraryMapSrs)

                $mapSrsUnits = $srsMap->GetUnits();



            //Create/Modify layer definition

            $layerDefContent = BuildLayerDefinitionContent();

            $resourceSrvc->SetResource($layerDefId, $layerDefContent, null);



                $classDef = new MgClassDefinition();



                $classDef->SetName($featureName);

                $classDef->SetDescription(GetLocalizedString("DATACLASSDESCR", $locale));

                $classDef->SetDefaultGeometryPropertyName("GEOM");



                //Set KEY property

                $prop = new MgDataPropertyDefinition("KEY");

                $prop->SetDataType(MgPropertyType::Int32);

                $prop->SetAutoGeneration(true);

                $prop->SetReadOnly(true);

                $classDef->GetIdentityProperties()->Add($prop);

                $classDef->GetProperties()->Add($prop);



                //Set ID property.

                $prop = new MgDataPropertyDefinition("ID");

                $prop->SetDataType(MgPropertyType::Int32);

                $classDef->GetProperties()->Add($prop);



                //Set geometry property

                $prop = new MgGeometricPropertyDefinition("GEOM");

                ////$prop->SetGeometryTypes(MgFeatureGeometricType::mfgtSurface); //TODO use the constant when exposed

                $prop->SetGeometryTypes(4);

                $classDef->GetProperties()->Add($prop);



                //Create the schema

                $schema = new MgFeatureSchema("DataSchema", GetLocalizedString("DATASCHEMADESCR", $locale));

                $schema->GetClasses()->Add($classDef);



                //finally, creation of the feature source

                $sdfParams = new MgCreateSdfParams("LatLong", $srsDefMap, $schema);

                $featureSrvc->CreateFeatureSource($dataSourceId, $sdfParams);



                //Add layer to map

                $layer = new MgLayer($layerDefId, $resourceSrvc);

                $layer->SetName($dataName);

                $layer->SetLegendLabel($dataName);

                $layer->SetDisplayInLegend(true);

                $layer->SetSelectable(true);

                $layers->Insert(0, $layer);

            

                $fsResourceId = new MgResourceIdentifier($dataSource);

                $fsReader = $resourceSrvc->GetResourceContent($fsResourceId);

                $fsXml = $fsReader->ToString();

                $fsDomDoc = DOMDocument::loadXML($fsXml);

                

                $ldResourceId = new MgResourceIdentifier($layerDef);

                $ldReader = $resourceSrvc->GetResourceContent($ldResourceId);

                $ldXml = $ldReader->ToString();

                $ldDomDoc = DOMDocument::loadXML($lddXml);

                            

    // Read the web layout into an XML DOM document object.

    $md = "Library://Test/X.MapDefinition"; 

    $mdResourceId = new MgResourceIdentifier($md);

    $mdReader = $resourceSrvc->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", $dataName));

    $newNode->appendChild($mdDomDoc->createElement("ResourceId", $layerDef));

    $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"));



    // Prepare the updated XML to be written out to the session.

    $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();

    $sessionMapDefinition = "Session:$sessionId//$sessionMapName.MapDefinition";

    $sessionResourceId = new MgResourceIdentifier($sessionMapDefinition);



    // Write the updated mapdefinition

    $resourceSrvc->SetResource($sessionResourceId, $byteSource->GetReader(), null);



    //Test

    $md1 = "Session:$sessionId//X.MapDefinition";

    $mdResourceId2 = new MgResourceIdentifier($md1);

    $mdReader2 = $resourceSrvc->GetResourceContent($mdResourceId2);

    $mdXml2 = $mdReader2->ToString();

    $mdDomDoc2 = DOMDocument::loadXML($mdXml2);



    // Read the web layout into an XML DOM document object.

    $wl = "Library://Test/Y.WebLayout"; // TODO Constant!

    $wlResourceId = new MgResourceIdentifier($wl);

    $wlReader = $resourceSrvc->GetResourceContent($wlResourceId);

    $wlXml = $wlReader->ToString();

    $wlDomDoc = DOMDocument::loadXML($wlXml); 



    // Add the MapDefinition in the WebLayout

    $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 web layout in the session to hold the updated version

    // from the library.

    $wlsessionMapName = $wlResourceId->GetName();

    $wlsessionWebLayout = "Session:$sessionId//$wlsessionMapName.WebLayout";

    $wlsessionResourceId = new MgResourceIdentifier($wlsessionWebLayout);



    // Write the updated web layout to the session.

    $resourceSrvc->SetResource($wlsessionResourceId, $wlbyteSource->GetReader(), null);



    // Redirect to the Ajax viewer pointing at the map at the desired coordinates.

    $redirectTo = "mapguide/mapviewerajax/?SESSION=$sessionId&WEBLAYOUT=$wlsessionWebLayout";

    $redirectTo = "mapguide/mapviewerajax/?WEBLAYOUT=$wlsessionWebLayout&SESSION=$sessionId";

    $host = $_SERVER["HTTP_HOST"];

    $url = "http://$host/$redirectTo";





    function BuildLayerDefinitionContent()

    {

        global $dataSource, $featureName, $ffcolor, $fbcolor, $transparent, $linestyle, $thickness, $lcolor, $fillstyle, $foretrans;



        $xtrans = sprintf("%02x", 255 * $foretrans / 100);

        $layerTempl = file_get_contents("../../viewerfiles/arealayerdef.templ");

        $xmlStr = sprintf($layerTempl,

                          $dataSource,

                          $featureName,

                          "GEOM",

                          $fillstyle,

                          $xtrans . $ffcolor,

                          $transparent? "ff" . $fbcolor: "00" . $fbcolor,

                          $linestyle,

                          $thickness,

                          $lcolor);

        $src = new MgByteSource($xmlStr, strlen($xmlStr));

        return $src->GetReader();



    function GetMapSrs($map)

    {

        $srs = $map->GetMapSRS();

        if($srs != "")

            return $srs;



        //No SRS, set to ArbitrayXY meters

        

       return "LOCALCS[\"Non-Earth (Meter)\",LOCAL_DATUM[\"Local Datum\",0],UNIT[\"Meter\", 1],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]]";

    }



    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: vendredi 9 janvier 2009 9:03
    To: MapGuide Users Mail List
    Subject: Re: [mapguide-users] Adding a temporary Layer in MapGuide



    You need several steps.

    1. Create a temporary FeatureSource for an SDF
    2. Insert data into the temporary FeatureSource
    3. Create a temporary LayerDefinition that points to the temporary FeatureSource
    4. Insert the temporary layer into the runtime map
    5. Refresh the map

    This is a generic recipe for building dynamic layers, redlining, buffering, etc.
    There exist code that does this in the "buffer" function used in the basic AJAX viewer.
    Look at the "buffer.[php,aspx,jsp]" file in:
    C:\Program Files\MapGuideOpenSource2.0\WebServerExtensions\www\mapviewer[php,net,jsp]

    If you have trouble with one of the steps, please ask again.

    An easier way of dealing with it would be to create a layer that displays ALL points.
    Then use the SQL WHERE statement as the layers "filter" property.
    This approach obviously has some limitations.

Regards, Kenneth Skovhede, GEOGRAF A/S

    Carmelo Saffioti skrev: 

    Hi everybody!

    I hope you can help me about this problem I'm having since several days:



    1) having x,y coordinates of a point, resulting from a sql query, how can I display it at runtime on the map?



    2) having x,y coordinates of a sequence of points, resulting from a sql query, how can I display them at runtime on the map?







    I really hope you can help me with that

    Thank you very much in advance

    Carmelo

   

----------------------------------------------------------------------------

   _______________________________________________mapguide-users mailing listmapguide-users at lists.osgeo.orghttp://lists.osgeo.org/mailman/listinfo/mapguide-users  
----------------------------------------------------------------------------

    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



------------------------------------------------------------------------------


  _______________________________________________
  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/20090112/2a7d67f1/attachment.html


More information about the mapguide-users mailing list