AW: [mapguide-users] Re: How to integrate the ZoomToView function
Christoph Lauber
christoph.lauber at geoplanteam.ch
Wed Mar 24 02:27:13 EDT 2010
Hi List
Hi Jackie
Thanks a lot for your advise. The sample worked fine for an ajax
viewer. I just had to change the library constant ($wl) and the
$redirectTo variable because I use an other web service name.
Maybe as hint: In the layout definition (MapGuide Studio) you have to
set a custom view for initial view of the map. If you use map's
initial view x, y and scale won't take any effect.
I tried now to modify and use this code for fusion. Unfortunately
without success for the moment.
I think the beginning of my code could be right, because I see the
appropriate entry in the session repository when I call the application
with x,
y, and scale.
-------------------------------------------
<?php
// fusion include.
$fusionMGpath = "../../fusion/layers/MapGuide/php\\";
include $fusionMGpath . "Common.php";
$locale = GetDefaultLocale();
// 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();
// 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://51_geoseeland/layout/gpt_geoseeland.ApplicationDefinition";
// 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.ApplicationDefinition";
$sessionResourceId = new MgResourceIdentifier($sessionWebLayout);
// Write the updated web layout to the session.
$resourceService->SetResource($sessionResourceId,
$byteSource->GetReader(), null);
-------------------------------------------
But what follows didn't work.
-------------------------------------------
// Redirect to the Fusion viewer pointing at the map at the desired
coordinates.
$redirectTo =
"mapguide2010/fusion/templates/mapguide/slate_Basic/index.html/?SESSION=
$sessionId&APPLICATIONDEFINITION=$sessionWebLayout";
$host = $_SERVER["HTTP_HOST"];
$url = "http://$host/$redirectTo";
// Redirect!
header("Location: $url");
exit;
?>
-------------------------------------------
Any idea what I have to change in the second section? I have the
impression that this path
"mapguide2010/fusion/templates/mapguide/slate_Basic/index.html" is not
correct. But what do I have to set instead?
Thanks for your help.
By the way:
There is still the question if somebody has an example with the
ZoomToScale function (In a working environment. Not the one in the
phpscamplecode).
Regards
Christoph
-----Ursprüngliche Nachricht-----
Von: mapguide-users-bounces at lists.osgeo.org
[mailto:mapguide-users-bounces at lists.osgeo.org] Im Auftrag von Jackie Ng
Gesendet: Sonntag, 21. März 2010 23:29
An: mapguide-users at lists.osgeo.org
Betreff: [mapguide-users] Re: How to integrate the ZoomToView function
Hi Christoph,
Try this sample here:
http://trac.osgeo.org/mapguide/wiki/CodeSamples/PHP/InitialMapView
The WebLayout document which defines your AJAX viewer interface, has a
section that specifies the initial extents of the map. The above code
sample
re-writes the initial extents in that document based on your custom X, Y
and
scale and passes that modified document on to the AJAX viewer.
Hope that helps.
- Jackie
--
View this message in context:
http://n2.nabble.com/How-to-integrate-the-ZoomToView-function-tp4772980p
4775039.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