[mapguide-users] Redirecting to the desired coordinates

Martin Morrison martin.morrison at edsi.com
Sun May 22 20:50:08 EDT 2011


All of this just to zoom to a coordinate?    I forget the exact function, but in ajakmapane.templ there is a fnction that does this.  ('Zoom to point' or something)

Martin
________________________________________
From: mapguide-users-bounces at lists.osgeo.org [mapguide-users-bounces at lists.osgeo.org] On Behalf Of benjanmin [erictsn at gmail.com]
Sent: Sunday, May 22, 2011 11:54 AM
To: mapguide-users at lists.osgeo.org
Subject: [mapguide-users] Redirecting to the desired coordinates

All,

The following code can work in old MG 2.0, but it cannot work in
MG2.1.0.4283. Anyone have idea? Thanks.

<?php

//
// Vital includes.
//
$viewerDir = "mapviewerphp/";
include $viewerDir . "constants.php";
include $viewerDir . "common.php";

//
// 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.
//
InitializeWebTier();

//
// 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://Basic/Basic.WebLayout";
$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";
$host = $_SERVER["HTTP_HOST"];
$url = "http://$host/$redirectTo";

//
// Redirect!
//
header("Location: $url");
exit;

?>


--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Redirecting-to-the-desired-coordinates-tp6391725p6391725.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
_______________________________________________
mapguide-users mailing list
mapguide-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-users



More information about the mapguide-users mailing list