Afternoon all,

 

I'm hoping someone will be able to look through the code I have to
dynamically set the initial map position and scale. I have taken this
straight from the code sample
(http://trac.osgeo.org/mapguide/wiki/CodeSamples/PHP/InitialMapView) but
when I run it, it just opens the map up at the default scale level. Any
help would be greatly appreciated...

 

I am passing in X, Y and Scale as parameters within the query string.

 

        global $_itkconfig, $session;

         //this code is used to display the Open Source MapGuide Web
Layout screen

         //common file from MapGuide Open Source

         require_once('..\data\common.php');                    

         

         //need to include the MapGuide Open Source constants file for
PHP        

 
require_once($_itkconfig['site']['mapObject']['viewerDir'].'constants.ph
p');

 

       //

      // Check and get the required parameters.

      //

      if (!isset($_REQUEST["x"]) || !isset($_REQUEST["y"]) ||
!isset($_REQUEST["scale"])) {

          echo "<Error>One or more of the required arguments is
missing.</Error>";

          exit;

      }

 

      $x = $_REQUEST["x"];

      $y = $_REQUEST["y"];

      $scale = $_REQUEST["scale"];

 

 

        //

        // Usual initialisation step.

        //

 
MgInitializeWebTier($_itkconfig['site']['mapObject']['webConfigFilePath'
]);

 

        //

        // Obtain a new session ID for this anonymous user, use it to
set up

        // a new site connection and use that to create a resource
service.

        //

        $site = new MgSite();

        $site->Open(new MgUserInformation("Anonymous", ""));

 

        $sessionId = $site->CreateSession();

 

        $siteConnection = new MgSiteConnection();

        $siteConnection->Open(new MgUserInformation($sessionId));

 

        $resourceService =
$siteConnection->CreateService(MgServiceType::ResourceService);

 

        //

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

        //

        $wl = "Library:// Layouts/Development_Layout.WebLayout"; // TODO
Constant!

        $wlResourceId = new MgResourceIdentifier($wl);

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

        $wlXml = $wlReader->ToString();

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

 

        //

        // Now, update the initial x, y and scale values with the
desired values.

        //

        $nodeCenterX =
$wlDomDoc->getElementsByTagName("CenterX")->item(0);

        $nodeCenterX->nodeValue = "$x";

 

        $nodeCenterY =
$wlDomDoc->getElementsByTagName("CenterY")->item(0);

        $nodeCenterY->nodeValue = "$y";

 

        $nodeScale = $wlDomDoc->getElementsByTagName("Scale")->item(0);

        $nodeScale->nodeValue = "$scale";

 

        //

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

        //

        $updatedXml = $wlDomDoc->saveXML();

        $byteSource = new MgByteSource($updatedXml,
strlen($updatedXml));

 

        //

        // Create a web layout in the session to hold the updated
version

        // from the library.

        //

        $sessionMapName = $wlResourceId->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/?SESSION=$sessionId&WEBLAYOUT=$sessionWebLayout"
; 

        $url = "http://localhost:8008/$redirectTo";;

        

        

        header("Location: $url");

        exit;

 

Thanks,

 

Bev

 


This email and any attachment are intended solely for the addressee, are 
strictly confidential and may be legally privileged. If you are not the 
intended recipient any reading, dissemination, copying or any other use or 
reliance is prohibited. If you have received this email in error please notify 
the sender immediately by email and then permanently delete the email. 
Copyright reserved.

All communications, incoming and outgoing, may be recorded and are monitored 
for legitimate business purposes. 

The security and reliability of email transmission cannot be guaranteed. It is 
the recipient’s responsibility to scan this e-mail and any attachment for the 
presence of viruses. 

The Capita Group plc and its subsidiaries ("Capita") exclude all liability for 
any loss or damage whatsoever arising or resulting from the receipt, use or 
transmission of this email. 

Any views or opinions expressed in this email are those of the author only.
_______________________________________________
mapguide-users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/mapguide-users

Reply via email to