Contents | IndexSelecting with the Viewer

Active Selections

Example: Listing Selected Parcels (AJAX Viewer)

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):
- Create an MgSelection object for
the map. Initialize it to the active selection.
- Retrieve selected layers from the MgSelection object.
- 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.
- Call MgSelection::GenerateFilter() to
create a selection filter that contains the selected features in
the class.
- Call MgFeatureService::SelectFeatures() to
create an MgFeatureReader object
for the selected features.
- 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):
- Get the current selection using the Viewer
API call GetSelectionXML().
- 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.
- In the page, create an MgSelection object for
the map.
- Initialize the MgSelection object with
the list of features passed to the page.
- Retrieve selected layers from the MgSelection object.
- 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.
- Call MgSelection::GenerateFilter() to
create a selection filter that contains the selected features in
the class.
- Call MgFeatureService::SelectFeatures() to
create an MgFeatureReader object
for the selected features.
- Process the MgFeatureReader object,
retrieving each selected feature.