[mapguide-users] Creating a static image problem

Chris Claydon chris.claydon at autodesk.com
Wed Aug 12 12:48:51 EDT 2009


At a first glance, it looks like you may need to save the map you've created so that it is actually written to the session repository.

Chris.

-----Original Message-----
From: mapguide-users-bounces at lists.osgeo.org [mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Jo Cook
Sent: Wednesday, August 12, 2009 9:40 AM
To: mapguide-users at lists.osgeo.org
Subject: [mapguide-users] Creating a static image problem


Dear All,

I am trying to implement the following:
The user selects a property (for example) from a drop-down list and is taken
to a page with more details, a thumbnail map of the location, and an option
to click on a link and go to the main map, where the property will be zoomed
and highlighted. The setup is MGOS 2.1 with apache and php.

I have managed to implement the second part, opening the main map page,
highlighting the property and zooming to it, with some judicious use of an
example posted elsewhere on the forum. 

However, I'm stuck trying to implement the thumbnail image. I am using the
property report example from the developers guide as my starting point, and
using the same code that works for highlighting and zooming to create the
selection for the rendering service. So what I want to do is send the
parameters for the map, the scale, the coordinates etc, the selection and
the session to the createmapimage.php file from the developers guide. That
page fails with a resource not found error, pointing at the map resource
(Session:19bacd00-6982-102c-8000-00142acfcbee_en_7F0000010AFC0AFB0AFA//Map1.Map).

Here's the php for the file that sends off the selection: 

$args = ($_SERVER['REQUEST_METHOD'] == 'POST') ? $_POST : $_GET;
$mapScale = 3000;
$imageHeight = 300;
$imageWidth = 300;
$SMAlayer = 'Events';
$SMAlocation = $args['PKEY'];
try
{
  if($SMAlayer && $SMAlocation) {
		$userInfo = new MgUserInformation("Anonymous", "");				
		$siteConn = new MgSiteConnection();
	    $siteConn->Open($userInfo);
	    $site = new MgSite();
	    $site->Open($userInfo);
	    $sessionId = $site->CreateSession();
	    $userInfo->SetMgSessionId($sessionId);
	    
	    $resourceSrvc =
$siteConn->CreateService(MgServiceType::ResourceService);
	    $map = new MgMap();
	    $resId = new MgResourceIdentifier("Library://Maps/Map1.MapDefinition");
	    $mapName = $resId->GetName();
	    $map->Create($resourceSrvc, $resId, $mapName);
	    
	    $layers = $map->GetLayers();
	    $selLayer = $layers->GetItem($SMAlayer);
		$featureResourceId = new
MgResourceIdentifier($selLayer->GetFeatureSourceId());
		$featureClassName = $selLayer->GetFeatureClassName();
	   
		$filter = "PKEY = $SMAlocation"; 
		echo $filter;
		$queryOptions = new MgFeatureQueryOptions(); 
		$queryOptions->SetFilter($filter); 
	   
	    $featureSrvc = $siteConn->CreateService(MgServiceType::FeatureService);
	    $featureReader = $featureSrvc->SelectFeatures($featureResourceId,
$featureClassName, $queryOptions);
	                         
	    $selection = new MgSelection($map);
		$selection->AddFeatures($selLayer, $featureReader, 1);
		$selectionXml = $selection->ToXml();
		print_r($selectionXml);
		  
		  //get the coordinates for javascript zoom
		$geometryReaderWriter = new MgAgfReaderWriter();
		$featureReader = $featureSrvc->SelectFeatures($featureResourceId,
$featureClassName, $queryOptions);
		if($featureReader->ReadNext()) {
			$byteReader = $featureReader->GetGeometry("Geometry");
			$geometry = $geometryReaderWriter->Read($byteReader); 
			$centerPoint = $geometry->GetCentroid();
			$mapCenterX = $centerPoint->GetCoordinate()->GetX();
          $mapCenterY = $centerPoint->GetCoordinate()->GetY();
          $sitecode = $featureReader->GetString('SITE_CODE');
        }
      }
	}
catch (MgException $e)
{
  echo '<p>' . $e->GetMessage() . '</p>';
  echo '<p>' . $e->GetDetails() . '</p>';
}
$selectionEncoded = urlencode($selectionXml);
$imageUrl =
"./devguide/custom_output/createmapimage.php?SESSION=$sessionId&SELECTION=$selectionEncoded&MAPNAME=$mapName&SCALE=$mapScale"
.
 
"&HEIGHT=$imageHeight&WIDTH=$imageWidth&CENTERX=$mapCenterX&CENTERY=$mapCenterY";

?>

This correctly picks up the scale, the coordinates, the sitecode etc. 

createmapimage.php is un-modified from the base setup. 

I'm very new to this, so I'm stuck trying to figure out what is wrong with
what I'm sending to createmapimage.php. If someone could help, I'd be very
grateful!

Thanks

Jo
-- 
View this message in context: http://n2.nabble.com/Creating-a-static-image-problem-tp3431631p3431631.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