[mapguide-users] Generate Simple Static Map

Denis Lalonde denlalonde at gmail.com
Thu May 16 06:33:47 PDT 2013


Thanks Jackie;

Yes, I am indeed creating the runtime app outside of the viewer, so
changing the code to use $map->Create fixed that issue. Everything seems to
be working except that, I can't get the actual image to appear in the
browser. When I run the code below in IE, I sometimes get a page full of
jargon text (which starts with "□PNG  IHDR □J"□/ IDATx□□..." but most
times I get a missing image icon (red X). I was able to confirm that the
image is created successfully in the Window's Temp directory, just not the
browser. I imagine it's not handling the content type...but not sure why.
Ideas?

*<?php //create static keymap*
*include 'mapviewerphp/common.php';*
*include 'mapviewerphp/constants.php';*
*$username="Anonymous";*
*$password="";*
*
*
*InitializeWebTier();*
*
*
*$userInfo = new MgUserInformation();*
*$userInfo->SetMgUsernamePassword($username, $password);*
*$siteConnection = new MgSiteConnection();*
*$siteConnection->Open($userInfo);*

*$resourceService  = $siteConnection->CreateService(0);*
*$renderingService = $siteConnection->CreateService(4);*
*
*
*$mapDefId = new MgResourceIdentifier("Library://MyMap.MapDefinition");*
*$map = new MgMap();*
*$mapName = $mapDefId->GetName();*
*$map->Create($resourceService, $mapDefId, $mapName); *
*$selection = new MgSelection($map);*
*
*
*//find&zoomto code will go here...*
*$center = $map->GetViewCenter()->GetCoordinate();*
*$scale = **2000;*
*
*
*$colorString = $map->GetBackgroundColor();*
*$colorString = substr($colorString, 2, 6) . substr($colorString, 0, 2);*
*$color = new MgColor($colorString);*
*
*
*$mgReader = $renderingService->RenderMap($map, $selection, $center, **
$scale**, 400, 300, $color, "PNG", false); *
*$tempImage = "C:\Windows\Temp\sometempfilename.png";*
*$mgReader->ToFile($tempImage); //confirmed that image is created in temp
folder*
*$image = imagecreatefrompng($tempImage);*
*unlink($tempImage);*
*header ("Content-type: image/png"); *
*imagepng($image);*
*imagedestroy($image);*
*?>*


On Wed, May 15, 2013 at 8:58 AM, Jackie Ng <jumpinjackie at gmail.com> wrote:

> The map name is the name of the runtime map state that's stored in the
> user's
> session repository. That means, pretty much anywhere a map name is
> involved,
> you'll need the session id as well.
>
> So you should be replacing this:
>
> $userInfo = new MgUserInformation();
> $userInfo->SetMgUsernamePassword($username, $password);
> $siteConnection = new MgSiteConnection();
> $siteConnection->Open($userInfo);
>
> with this:
>
> $userInfo = new MgUserInformation($sessionId);
> $siteConnection = new MgSiteConnection();
> $siteConnection->Open($userInfo);
>
> Where $sessionId is set based on a request parameter to your PHP script. If
> your PHP script is set up as an InvokeURL command or widget, it will always
> get passed the MAPNAME and SESSION parameters that you can access with
> $_REQUEST
>
> This assumes a runtime map already created by the AJAX/Fusion viewer. If
> you
> are trying to create the runtime map *outside* of the viewer, the you
> should
> be using $map->Create instead of $map->Open. In such case, then your
> MgSiteConnection initialization fragment with username/password is the
> correct one to use.
>
> - Jackie
>
>
>
> --
> View this message in context:
> http://osgeo-org.1560.x6.nabble.com/Generate-Simple-Static-Map-tp5053393p5053399.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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapguide-users/attachments/20130516/9e3fe289/attachment.html>


More information about the mapguide-users mailing list