Show in Contents

Add to Favorites

Home: MapGuide Developer's Guide
Passing Parameters From the Task Pane Frame

Active Selections

Example: Listing Selected Parcels (AJAX or DWF 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 a small 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 only):
- 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. Note that this will also work for the AJAX Viewer.
To retrieve and manipulate the active
selection for a map (AJAX or 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 formFrame. 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.