[mapguide-users] Layer properties problem
padmini godavarthi
godavarthi.padmini at gmail.com
Wed Apr 7 03:29:57 EDT 2010
Hi,
iam doing zoom to feature (i mean if i select layername from dropdownlist
the layer properties have to appear in 2nd dropdownlist.when i select one of
layer property the propertyvalues have to display in 3rd
dropdownlist)partially i succeeded.but iam unable to get the selected value
of layer property.because iam new to php
in .net i will write as dropdownlist.selecteditem(if i select featId then it
will come),But how to retrieve this value in php.
my code is as follows
<?php
require_once '../utilityfunctions.php';
require_once '../JSON.php';
require_once 'classes/zoom.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>Query 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 queryReqHandler = null;
var properties = null;
var propertyvalues=null;
var results;
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", "zoomcontroller.php", false);
reqHandler.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
reqHandler.send(reqParams);
alert(reqParams);
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");
var valueSelect = document.getElementById("valueSelect");
if (propertySelect.selectedIndex > 0)
{
alert(propertySelect.value); [it comes as the index value]
reqParams = "COMMAND=GETLAYERPROPERTYVALUES";
reqParams += "&SESSION=" + encodeURIComponent(session);
reqParams += "&MAPNAME=" + encodeURIComponent(mapName);
reqParams += "&LAYERNAME=" + encodeURIComponent(layerSelect.value);
reqParams += "&PROPNAME=" + encodeURIComponent("FeatId");
alert(reqParams);
if (msie)
reqHandler = new ActiveXObject("Microsoft.XMLHTTP");
else
reqHandler = new XMLHttpRequest();
reqHandler.open("POST", "zoomcontroller.php", false);
reqHandler.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
reqHandler.send(reqParams);
alert(reqHandler.responseText);
propertyvalues=reqHandler.responseText.parseJSON();
valueSelect.options.length = 0;
for (var i = 0; i < propertyvalues.length; i++)
{
valueSelect.options[i] = new Option(propertyvalues[i], i, false, false);
}
}
}
function OnReadyStateChange()
{
alert("readyState");
var ready = reqHandler.readyState;
if (ready == READY_STATE_COMPLETE)
{
alert(reqHandler.responseText);
results = reqHandler.responseText.parseJSON();
OnResultChange();
}
}
function OnResultChange()
{
var zoomBtn = document.getElementById("zoomBtn");
var selectBtn = document.getElementById("selectBtn");
if (valueSelect.selectedIndex >= 0)
{
zoomBtn.disabled = false;
}
else
{
zoomBtn.disabled = false;
}
}
function OnLoad()
{
OnLayerChange();
OnResultChange()
}
function ZoomToFeature()
{
var propertySelect = document.getElementById("propertySelect");
var valueSelect = document.getElementById("valueSelect");
var query= "FeatId" + "=" + valueSelect.Value;
alert(query);
reqParams = "COMMAND=ZOOMTOFEATURE";
reqParams += "&SESSION=" + encodeURIComponent(session);
reqParams += "&MAPNAME=" + encodeURIComponent(mapName);
reqParams += "&LAYERNAME=" + encodeURIComponent(layerSelect.value);
reqParams += "&QUERY=" + encodeURIComponent(query);
if (msie)
reqHandler = new ActiveXObject("Microsoft.XMLHTTP");
else
reqHandler = new XMLHttpRequest();
reqHandler.onreadystatechange = OnReadyStateChange;
reqHandler.open("POST", "zoomcontroller.php", false);
reqHandler.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
reqHandler.send(reqParams);
feature = results[0];
SelectFeature();
parent.parent.mapFrame.ZoomToView(feature.centerX, feature.centerY,3000,
true);
}
function SelectFeature()
{
alert("iamselectfeature");
reqParams = "COMMAND=GETSELECTIONXML";
reqParams += "&SESSION=" + encodeURIComponent(session);
reqParams += "&MAPNAME=" + encodeURIComponent(mapName);
reqParams += "&LAYERNAME=" + encodeURIComponent(layerSelect.value);
reqParams += "&IDLIST=" + results[0].idList.toJSONString();
if (msie)
reqHandler = new ActiveXObject("Microsoft.XMLHTTP");
else
reqHandler = new XMLHttpRequest();
reqHandler.open("POST", "zoomcontroller.php", false);
reqHandler.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
reqHandler.send(reqParams);
alert("iaminselectfeature");
alert(reqHandler.responseText);
selectionXml = reqHandler.responseText;
parent.parent.mapFrame.SetSelectionXML(TrimString(selectionXml));
}
function TrimString(responseString)
{
responseString = responseString.replace( /^\s+/g, "" );
return responseString.replace( /\s+$/g, "" );
}
</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 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>
<input class="Ctrl" id="zoomBtn" type="button" onClick="ZoomToFeature()"
value="Zoom" 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>
1)How to retrieve the selecteditem in Propertyselect dropdownlist
</html>
--
View this message in context: http://n2.nabble.com/Layer-properties-problem-tp4863462p4863462.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
More information about the mapguide-users
mailing list