[mapguide-users] Re: Zoom+select features problem

Mauricio Villablanca mgvillablanca at yahoo.com
Sat Mar 13 16:33:24 EST 2010


You need to properly separate your server-side code from the client-sided
code. In your code, the first line of PHP is 
<?php echo $selectionXml;?>

which will fail since the variable hasn't even been defined yet.

I suggest you check a book on PHP development. Having said that, this is
what your code should look like:

<?php
	include 'utilityfunctions.php';
	try {
		$webconfigDirectory = $webExtensionsDirectory . 'www\\';
		$webconfigFilePath = $webconfigDirectory . 'webconfig.ini';
		
		MgInitializeWebTier($webconfigFilePath);
		
		$args =  ($_SERVER['REQUEST_METHOD'] == "POST") ? $_POST : $_GET;
		$sessionId = $args['SESSION'];
		$mapName = $args['MAPNAME'];
		$userInfo = new MgUserInformation($sessionId);
		$siteConnection = new MgSiteConnection();
		$siteConnection->Open($userInfo);	
		$resourceService =
$siteConnection->CreateService(MgServiceType::ResourceService);
		$featureService =
$siteConnection->CreateService(MgServiceType::FeatureService);
		
		$map = new MgMap();
		$map->Open($resourceService, 'map');
		
		$layers = $map->GetLayers();	
		$count = $layers->GetCount();
		for ($i = 0; $i < $count; $i++) {
			$layer = $layers->GetItem($i);
		}
		$layerClassName1 = $layer->GetFeatureClassName();
		$FeatureResId = new
MgResourceIdentifier("Library://data/resource.FeatureSource");
		$queryOptions = new MgFeatureQueryOptions();
		$val="PARCEL";
		$val1="44142300003000";
		$query=$val . "=" . $val1;
		$queryOptions->SetFilter($selectionString);
		$featureReader = $featureService->SelectFeatures($FeatureResId,
$layerClassName1, $queryOptions);
		
		$featureReader->ReadNext();
		$featureAgfGeometry = $featureReader->GetGeometry('Geometry');
		$agfReaderWriter = new MgAgfReaderWriter();
		$featureGeometry = $agfReaderWriter->Read($featureAgfGeometry);
		$centroid = $featureGeometry->GetCentroid();
		$mapCenterX = $centroid->GetCoordinate()->GetX();
		$mapCenterY = $centroid->GetCoordinate()->GetY();
		
		$selection = new MgSelection($map);
		$selection->AddFeatures($layer, $featureReader, 1);	
		$selectionXml = $selection->ToXml();
	}
	catch (MgException $e)
	{
		echo "<p><strong>Error:</strong> ";
		echo $e->GetDetails();
		echo "</p>";
	}
?>
    
   
<html>
<head>
 <title>Zoom Feature</title>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <meta http-equiv="content-script-type" content="text/javascript">
    <meta http-equiv="content-style-type" content="text/css">
    <link href="../styles/globalStyles.css" rel="stylesheet" 
type="text/css">
    <link href="../styles/otherStyles.css" rel="stylesheet" type="text/css">
    <script language="javascript">
			function Zoom1(x,y) {
			    var xval=x;
			    var yval=y;
			    parent.parent.mapFrame.ZoomToView(xval, yval, 2000, true);
			}
			
			function Zoom() {
				selectionXml = '<?php echo $selectionXml;?>';
			    parent.parent.mapFrame.SetSelectionXML(selectionXml);
			}
    </script>
</head>
<body>
	<input type="text" name="id" size="15">
	<input type="button" name="button" value="Click" size="10"
onclick="Zoom1(<?php echo $mapCenterX;?>,<?php echo $mapCenterY;?>)">
	<input type="button" name="button1" value="Select" size="10"
onclick="Zoom()">
</body>
</html> 


Regarding the second question, how about taking the code in your Zoom
function and putting it in the other function? :)
-- 
View this message in context: http://n2.nabble.com/Zoom-select-features-problem-tp4708107p4729119.html
Sent from the MapGuide Users mailing list archive at Nabble.com.


More information about the mapguide-users mailing list