Working With the Active Selection
 
 

For the AJAX Viewer, whenever a selection is changed by the Viewer, the selection information is sent to the web server so the map can be re-generated. For the DWF Viewer, the selection information is managed by the Viewer, so the Viewer must pass the selection information to the web server before it can be used.

If you are writing an application that will be used by both Viewers, you can use the DWF method, which will result in some additional overhead for the AJAX Viewer. Alternatively, you can write different code for each Viewer.

To retrieve and manipulate the active selection for a map (AJAX Viewer):

  1. Create an MgSelection object for the map. Initialize it to the active selection.
  2. Retrieve selected layers from the MgSelection object.
  3. For each layer, retrieve selected feature classes. There will normally be one feature class for the layer, so you can use the MgSelection::GetClass() method instead of the MgSelection::GetClasses() method.
  4. Call MgSelection::GenerateFilter() to create a selection filter that contains the selected features in the class.
  5. Call MgFeatureService::SelectFeatures() to create an MgFeatureReader object for the selected features.
  6. Process the MgFeatureReader object, retrieving each selected feature.

The procedure for the DWF Viewer is similar, but the Viewer must send the selection information as part of the HTTP request.

To retrieve and manipulate the active selection for a map (DWF Viewer):

  1. Get the current selection using the Viewer API call GetSelectionXML().
  2. Pass this to the Web server as part of an HTTP request. The simplest method for this is to use the Submit() method of the form frame. This loads a page and passes the parameters using an HTTP POST.
  3. In the page, create an MgSelection object for the map.
  4. Initialize the MgSelection object with the list of features passed to the page.
  5. Retrieve selected layers from the MgSelection object.
  6. For each layer, retrieve selected feature classes. There will normally be one feature class for the layer, so you can use the MgSelection::GetClass() method instead of the MgSelection::GetClasses() method.
  7. Call MgSelection::GenerateFilter() to create a selection filter that contains the selected features in the class.
  8. Call MgFeatureService::SelectFeatures() to create an MgFeatureReader object for the selected features.
  9. Process the MgFeatureReader object, retrieving each selected feature.