Example: Listing Selected Parcels (AJAX or DWF Viewer)
 
 
 

The steps for listing the selected parcels for the DWF Viewer are nearly the same as for the AJAX Viewer. The major difference is you must pass the selection information from the Viewer to your page.

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);
 
// ----------------------------------------------------------
// Use the following code for AJAX or DWF Viewers
// This requires passing selection data via HTTP POST
 
if (isset($_POST['SELECTION']) && $_POST['SELECTION'] != '')
{
  $selection = new MgSelection($map, $_POST['SELECTION']);
  $layers = $selection->GetLayers();
}
else
$layers = 0;
// ---------------------------------------------------------
 
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 />&nbsp;&nbsp;' . 
          $featureReader->GetString('RPROPAD');
        echo $val . '<br />';
      }
    }
  }
}
else
echo 'No selected layers';
echo '</p>';