[mapguide-users] Zooming to extent of multiple selections

Jo Cook j.cook at oxfordarch.co.uk
Mon Dec 21 10:37:54 EST 2009


Dear All,

I have a select and zoom to extents problem in the ajax viewer. The user
chooses a postcode from a list, and this returns multiple results. I simply
want the map to zoom to the combined extent of these results. I thought the
right option to use is GetExtents, but when I try and derive the coordinates
from the envelope this creates (as a method of checking the php is correct
before moving on to the javascript), it returns the same value each time,
which I assume is probably the value for the entire layer. I have checked
that the correct number of features are returned, so I know it's not that.
Any thoughts would be greatly appreciated.

My code is as follows:

	MgInitializeWebTier ($webconfigFilePath);

		$userInfo = new MgUserInformation($sessionId);
		$siteConnection = new MgSiteConnection();
		$siteConnection->Open($userInfo);

		echo $mapName."<br />";
		$map = new MgMap($siteConnection);
		$map->Open($mapName);
	
		$cfilter = "POSTCODE = '$ccode'"; 
		echo $cfilter.'<br />';


		$queryOptions = new MgFeatureQueryOptions(); 
		$queryOptions->SetFilter($cfilter); 

		echo $SMAlayer.'<br />';
		$layers = $map->GetLayers();
		$selLayer = $layers->GetItem($SMAlayer);


		$featureresourceID = new
MgResourceIdentifier($selLayer->GetFeatureSourceId());	
		$featureclassname = $selLayer->GetFeatureClassName();
		$featureService =
$siteConnection->CreateService(MgServiceType::FeatureService);
		$dataReader = $featureService->SelectFeatures($featureresourceID,
$featureclassname, $queryOptions);
		$dataReader->ReadNext();
		//$resourceService =
$siteConnection->CreateService(MgServiceType::ResourceService);
	
		$selection = new MgSelection($map);
		$selection->AddFeatures($selLayer, $dataReader, 0);


		//$selection->Save($resourceService, $mapName);
			
      

		$count =
$selection->GetSelectedFeaturesCount($selLayer,$featureclassname);
		echo 'Count: '.$count.'<br />';
		$dataReader->Close();
		$extent = $selection->GetExtents($featureService);
		$upperRightY = $extent->GetUpperRightCoordinate()->GetY();
		$lowerLeftX=$extent->GetLowerLeftCoordinate()->GetX();
		$width = $extent->GetWidth();
		$height = $extent->GetHeight();
		$centreX = $lowerLeftX + ($width)/2;
		$centreY = $upperRightY - ($height)/2;
		echo "Centre Coordinates: ".$centreX.",".$centreY;

Thanks

Jo
-- 
View this message in context: http://n2.nabble.com/Zooming-to-extent-of-multiple-selections-tp4199009p4199009.html
Sent from the MapGuide Users mailing list archive at Nabble.com.


More information about the mapguide-users mailing list