One method to do this is to create a JavaScript function, then call this function from the Viewer using an Invoke Script command or as a result of an onClick event in the task pane. For example, the task pane of the Working With Feature Data sample contains a JavaScript function executed by an onClick event.
function listSelection()
{
xmlSel = parent.parent.mapFrame.GetSelectionXML();
params = new Array("SESSION",
parent.parent.mapFrame.GetSessionId(),
"MAPNAME", parent.parent.mapFrame.GetMapName(),
"SELECTION", xmlSel);
pageUrl =
"/mapguide/samplesphp/working_with_feature_data/
listselection.php";
parent.parent.formFrame.Submit(pageUrl, params,
"taskPaneFrame");
}
This submits a request to listselection.php, which contains the following:
$map = new MgMap();
$map->Open($resourceService, $mapName);
$selection = new MgSelection($map);
$selection->Open($resourceService, $mapName);
$layers = $selection->GetLayers();
if ($layers)
{
$queryOptions = new MgFeatureQueryOptions();
for ($i = 0; $i < $layers->GetCount(); $i++)
{
// Only check selected features in the Parcels layer.
$layer = $layers->GetItem($i);
if ($layer && $layer->GetName() == 'Parcels')
{
// Create a filter containing the IDs of the selected
// features on this layer
$layerClassName = $layer->GetFeatureClassName();
$selectionString = $selection->GenerateFilter($layer,
$layerClassName);
// Get the feature resource for the selected layer
$layerFeatureId = $layer->GetFeatureSourceId();
$layerFeatureResource = new
MgResourceIdentifier($layerFeatureId);
// Apply the filter to the feature resource for the
// selected layer. This returns
// an MgFeatureReader of all the selected features.
$queryOptions->SetFilter($selectionString);
$featureReader =
$featureService->SelectFeatures($layerFeatureResource,
$layerClassName, $queryOptions);
// Process each item in the MgFeatureReader,
// displaying the owner name
while ($featureReader->ReadNext())
{
$val = $featureReader->GetString('NAME') .
'<br /> ' .
$featureReader->GetString('RPROPAD');
echo $val . '<br />';
}
}
}
}
else
echo 'No selected layers';
echo '</p>';