[mapguide-users] Response text error in Getting layer properties

padmini godavarthi godavarthi.padmini at gmail.com
Fri Mar 26 05:00:48 EDT 2010



Hi,
iam doing zoom to feature function in php .i have taken the query sample
code from phpviewersample(querymain.php,querycontroller.php ,query.php)
but iam unable to get the layer properties in the drop down list. it shows
the following error while tracking the code at 
alert(reqHandler.responseText);


my code was:

in zoommain.php  the code was

<?php
	require_once '../utilityfunctions.php';
    require_once '../JSON.php';
	require_once 'classes/zoom1.php';
	$args = ($_SERVER['REQUEST_METHOD'] == "POST") ? $_POST : $_GET;
	$errorMsg = null;
	$errorDetail = null;
	try
	{
		MgInitializeWebTier($configFilePath);
		$query = new Query($args);
		$layerNames = $query->GetMapLayerNames();
	}
	catch (MgException $mge)
	{
		$errorMsg = $mge->GetMessage();
		$errorDetail = $mge->GetDetails();
		echo $errorMsg;
		echo $errorDetail;
	}
	catch (Exception $e)
	{
		$errorMsg = $e->GetMessage();
		echo $errorMsg;
	}
?>
<html>
<head>
	<title>Zoom Features</title>
    <link rel="stylesheet" href="../styles/gt.css" type="text/css">
	<script language="javascript"
src="../../viewerfiles/browserdetect.js"></script>
	<script language="javascript" src="../json.js"></script>
	<script language="javascript">
		var READY_STATE_UNINITIALIZED 	= 0;
		var READY_STATE_LOADING 		= 1;
		var READY_STATE_LOADED 			= 2;
		var READY_STATE_INTERACTIVE 	= 3;
		var READY_STATE_COMPLETE 		= 4;
		var NOT_BUSY_IMAGE = "../images/loader_inactive.gif";
		var BUSY_IMAGE = "../images/loader_pulse.gif";

        var session = '<?= $args['SESSION'] ?>';
        var mapName = 'map';
		var reqHandler = null;
		var properties = null;
		function OnLayerChange()
		{
            var layerSelect = document.getElementById("layerSelect");
            var propertySelect = document.getElementById("propertySelect");
            var valueSelect = document.getElementById("valueSelect");
            reqParams = "COMMAND=GETLAYERPROPERTIES";
			reqParams += "&SESSION=" + encodeURIComponent(session);
            reqParams += "&MAPNAME=" + encodeURIComponent(mapName);
			reqParams += "&LAYERNAME=" + encodeURIComponent(layerSelect.value);
            if (msie)
                reqHandler = new ActiveXObject("Microsoft.XMLHTTP");
            else
                reqHandler = new XMLHttpRequest();
            reqHandler.open("POST", "zoomcontroller1.php", false);
            reqHandler.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
			reqHandler.send(reqParams);
alert(reqHandler.responseText);
			properties = reqHandler.responseText.parseJSON();
			propertySelect.options.length = 0;
			for (var i = 0; i < properties.length; i++)
			{
				propertySelect.options[i] = new Option(properties[i].name, i, false,
false);

			}
			OnPropertyChange();
		}
			function OnPropertyChange()
				{
		            var propertySelect =
document.getElementById("propertySelect");

					if (propertySelect.selectedIndex >= 0)
					{
						alert("hiiproperty");
					}

		}

		function OnLoad()
		{
			OnLayerChange();

		}
	</script>

</head>
<body onLoad="OnLoad();" marginwidth=5 marginheight=5 leftmargin=5
topmargin=5 bottommargin=5 rightmargin=5>
<?php if ($errorMsg == null) { ?>
<table class="RegText" border="0" cellspacing="0" width="100%">
	<tr><td class="Title"> ../images/loader_inactive.gif &nbsp;Zoom
Features<hr></td></tr>
	<tr><td class="SubTitle">Select a Layer</td></tr>
    <tr><td>Layer:</td></tr>
	<tr>
		<td class="RegText">
			<select size="1" class="Ctrl" id="layerSelect" onChange="OnLayerChange()"
style="width: 100%">
				<?php
					$selected = 'selected';
					foreach($layerNames as $layerName => $layerLabel) {
				?>
				<option value="<?= $layerName ?>" <?=$selected ?> ><?= $layerLabel
?></option>
				<?php
						$selected = '';
					}
				?>
		  	</select>
		</td>
	</tr>

    <tr><td>Property:</td></tr>
	<tr>
		<td class="RegText">
			<select size="1" class="Ctrl" id="propertySelect"
onChange="OnPropertyChange()" style="width: 100%">
		  	</select>
		</td>
	</tr>

    <tr><td>Value:</td></tr>
	<tr>
		<td class="RegText">

		<select size="1" class="Ctrl" id="valueSelect" style="width: 100%">
		  	</select>

		</td>
	</tr>
    <tr><td class="Spacer"></td></tr>
	<tr>
		<td>
			<input class="Ctrl" id="zoomBtn" type="button"  value="Zoom"
style="width:60px">
			<input class="Ctrl" id="selectBtn" type="button"  value="Select"
style="width:60px">
		</td>
	</tr>

</table>

<?php } else { ?>

<table class="RegText" border="0" cellspacing="0" width="100%%">
	<tr><td class="Title">Error<hr></td></tr>
	<tr><td><?= $errorMsg ?></td></tr>
	<tr><td><?= $errorDetail ?></td></tr>
</table>

<?php } ?>

</body>

</html>

in  zoomcontroller1.php  as the code is same as quercontroller.php except 
require_once 'classes/query.php'; is replaced with require_once
'classes/zoom1.php';

and in zoom1.php the code was..

function GetMapLayerNames()
       {
           $layerNames = array();

           $resourceService =
$this->site->CreateService(MgServiceType::ResourceService);

           $map = new MgMap();
           $map->Open($resourceService, 'map');
           $layers = $map->GetLayers();

           for ($i = 0; $i < $layers->GetCount(); $i++)
           {
               $layer = $layers->GetItem($i);

               if((substr($layer->GetName(), 0, 1) != "_") &&
(substr(strtoupper($layer->GetFeatureSourceId()), 0, 7) != "SESSION"))
               {
                   $layerNames[$layer->GetName()] =
$layer->GetLegendLabel();
               }
           }
           asort($layerNames);

           return $layerNames;
    }
     function GetLayerProperties()
       {
           $properties = array();

           $resourceService =
$this->site->CreateService(MgServiceType::ResourceService);

           $map = new MgMap();
           $map->Open($resourceService, 'map');
           $layer = $map->GetLayers()->GetItem('layer');

           $featureService =
$this->site->CreateService(MgServiceType::FeatureService);
           $resId = new MgResourceIdentifier($layer->GetFeatureSourceId());
           $schemaClass = explode(':', $layer->GetFeatureClassName());
           try
           {

           $classDef = $featureService->GetClassDefinition($resId,
$schemaClass[0], $schemaClass[1]);

           for ($i = 0; $i < $classDef->GetProperties()->GetCount(); $i++)
           {
               $propertyDef = $classDef->GetProperties()->GetItem($i);

               if ($propertyDef->GetPropertyType() ==
MgFeaturePropertyType::DataProperty)
               {
                   $dataType = $propertyDef->GetDataType();
                   if ($this->IsValidDataType($dataType))
                   {
                       array_push($properties, new
Property($propertyDef->GetName(), $dataType == MgPropertyType::String));
                   }
               }
           }
           }
           catch (MgException $mge)
		   	{
		   		$errorMsg = $mge->GetMessage();
		   		$errorDetail = $mge->GetDetails();
		   		echo $errorMsg;
		   		echo $errorDetail;
	}

           return $properties;
           }
i think iam passing the parameters correctly...
if anybody aware of that please let me know?? 

  http://n2.nabble.com/file/n4802751/error.jpg 
-- 
View this message in context: http://n2.nabble.com/Response-text-error-in-Getting-layer-properties-tp4802751p4802751.html
Sent from the MapGuide Users mailing list archive at Nabble.com.


More information about the mapguide-users mailing list