[mapguide-users] Saving map to session doesn't persist?

Jason Birch Jason.Birch at nanaimo.ca
Fri Nov 17 16:42:06 EST 2006


Ok, now you've got me going around in circles, but I think it's working
now (script attached) :)

- I need to save the MgMap as an MgResourceType::Map

- For the GETMAPIMAGE mapagent operation, it appears that the
MAPDEFINITION parameter is not used if the MAPNAME and SESSION variables
are set.  This caused me a fair amount of confusion.

- I added the lines that Chris suggested earlier between the map->Create
and the map->Save :

    //create an empty selection object and store it in the session
repository
    $sel = new MgSelection($map);
    $sel->Save($resourceService, 'Sheboygan');

I'm thinking that this whole issue may be in the way that the MapAgent
GETMAPIMAGE operation works.  It doesn't appear that there is any way to
call the MgRenderingService->RenderMap() without an MgSelection, so I'm
guessing that the MapAgent is expecting the map in the session
repository to have a Selection associated with it.  If this is the case,
it would be nicer if the MapAgent just created a null selection if there
wasn't one there.

As an aside, I could REALLY use an example of how to use the
RenderingService in PHP instead of having to waste cycles passing the
map through the repository.  The php viewer sample utilityfunctions.php
has a function called OutputReaderContent which should help, but I have
a few questions about how to do DPI / width calculations (are the width
and height in RenderMap in map units?) and a couple other things.

Jason
 

-----Original Message-----
From: Paul Spencer [mailto:pspencer at dmsolutions.ca] 
Sent: Friday, November 17, 2006 11:30
To: users at mapguide.osgeo.org
Subject: Re: [mapguide-users] Saving map to session doesn't persist?

Jason, in your $map->Save use MgResourceType::Map

Cheers

Paul

On 17-Nov-06, at 1:22 PM, Jason Birch wrote:

> This is what the code looks like now:
>
>     //Set up the map to be used in this service
>     $resourceID = new
> MgResourceIdentifier('Library://Samples/Sheboygan/Maps/
> Sheboygan.MapDefi
> nition');
>
>     //Create a connection to the map
>     $map = new MgMap();
>     $map->Create($resourceService,$resourceID,'Sheboygan');
>
>     //Save the map into the repository
>     $mapId = new MgResourceIdentifier("Session:$sessionId//
> Sheboygan.".
> MgResourceType::MapDefinition);
>     $map->Save($resourceService, $mapId);
>
> Now I'm getting the following error on the MgMap->Save :
>
> Error: An exception occurred in the XML parser.
> Details:An exception occurred in the XML parser. Exception occurred in

> method MgResourceContentManager.ValidateDocument at line 586 in file 
> c:\build_tux_area\mgdev\server\src\services\resource
> \ResourceContentMana
> ger.cpp
>
> ???
>
> Is it possible that the MapDefinition in the Sheboygan sample is not 
> valid?  But then it would have errored on the Load in Administrator.
>
> Jason
>
>
> -----Original Message-----
> From: Tom Fukushima [mailto:tom.fukushima at autodesk.com]
> Sent: Friday, November 17, 2006 09:26
> To: users at mapguide.osgeo.org
> Subject: RE: [mapguide-users] Saving map to session doesn't persist?
>
> Hi Jason,
>
> Where you are using MgResourceType::Map, try using 
> MgResourceType::MapDefinition instead.
>
> Hope this solves the problem,
> Tom
>
> -----Original Message-----
> From: Jason Birch [mailto:Jason.Birch at nanaimo.ca]
> Sent: Friday, November 17, 2006 10:08 AM
> To: users at mapguide.osgeo.org
> Subject: [mapguide-users] Saving map to session doesn't persist?
>
> I've attached an example that I think should save a MapDefinition to 
> the session repository, but a call to MapAgent to render the map comes

> up with a MgResourceNotFoundException (I think).
>
> Is there something that says that MapDefinitions need to be modified 
> to be persisted?  Is there a typo in there somewhere?
>
> Jason
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe at mapguide.osgeo.org
> For additional commands, e-mail: users-help at mapguide.osgeo.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe at mapguide.osgeo.org
> For additional commands, e-mail: users-help at mapguide.osgeo.org
>

+-----------------------------------------------------------------+
|Paul Spencer                          pspencer at dmsolutions.ca    |
+-----------------------------------------------------------------+
|Chief Technology Officer                                         |
|DM Solutions Group Inc                http://www.dmsolutions.ca/ |
+-----------------------------------------------------------------+





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe at mapguide.osgeo.org
For additional commands, e-mail: users-help at mapguide.osgeo.org

-------------- next part --------------
<?php

$extensionDir="C:/Program Files/MapGuideOpenSource/WebServerExtensions/www/";
$viewerDir = $extensionDir . "mapviewerphp/";

include $viewerDir . 'common.php';
include $viewerDir . 'constants.php';

try
{

    MgInitializeWebTier($extensionDir."webconfig.ini");
    $user = new MgUserInformation('Administrator','admin');
    $siteConnection = new MgSiteConnection();
    $siteConnection->Open($user);
    $resourceService = $siteConnection->CreateService (MgServiceType::ResourceService);
    $site = $siteConnection->GetSite();
    $sessionId = $site->CreateSession();
    $user->SetMgSessionId($sessionId);

    //Set up the map to be used in this service
    $resourceID = new MgResourceIdentifier('Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition');

    //Create a connection to the map
    $map = new MgMap();
    $map->Create($resourceService,$resourceID,'MapTest');

    //create an empty selection object and store it in the session repository
    $sel = new MgSelection($map);
    $sel->Save($resourceService, 'MapTest');

    //Save the map into the repository
    $mapId = new MgResourceIdentifier("Session:$sessionId//MapTest.". MgResourceType::Map);
    $map->Save($resourceService, $mapId);

    $imageURL= "http://localhost/mapguide/mapagent/mapagent.fcgi" .
    		   "?OPERATION=GETMAPIMAGE&VERSION=1.0.0" .
    		   "&MAPNAME=MapTest&LOCALE=en".
    		   "&FORMAT=image/png" .
    		   "&SETVIEWCENTERX=-87.73".
    		   "&SETVIEWCENTERY=43.73".
    		   "&SETVIEWSCALE=4000&SETDISPLAYDPI=100".
    		   "&SETDISPLAYWIDTH=600&SETDISPLAYHEIGHT=600".
    		   "&SESSION=".$sessionId;


    //Output the contents of the request
    header("Content-Type: image/png");
    print file_get_contents($imageURL);

}
catch (MgException $ex)
{
    print "<p>Error: " . $ex->GetMessage() . "<br/>";
    print "Details:" . $ex->GetDetails() . "</p>";
    exit;
}


More information about the Mapguide-users mailing list