<%-- Copyright (C) 2004-2011 by Autodesk, Inc. This library is free software; you can redistribute it and/or modify it under the terms of version 2.1 of the GNU Lesser General Public License as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA --%> <%@ Page language="c#" %> <%@ Import Namespace="System" %> <%@ Import Namespace="System.Collections.Specialized" %> <%@ Import Namespace="System.IO" %> <%@ Import Namespace="OSGeo.MapGuide" %> Viewer Sample Application - List Selected Parcels

Selected Parcels

<% sessionId = Request.Params["SESSION"]; mapName = Request.Params["MAPNAME"]; try { // Initialize the Web Extensions and connect to the Server using // the Web Extensions session identifier stored in PHP session state. MapGuideApi.MgInitializeWebTier (Constants.WebConfigPath); MgUserInformation userInfo = new MgUserInformation(sessionId); MgSiteConnection siteConnection = new MgSiteConnection(); siteConnection.Open(userInfo); MgMap map = new MgMap(siteConnection); map.Open(mapName); // ---------------------------------------------------------- // Use the following code for AJAX or DWF Viewers // This requires passing selection data via HTTP POST MgReadOnlyLayerCollection layers = null; if (!String.IsNullOrEmpty(Request.Form["SELECTION"])) { selection = new MgSelection(map, HttpUtility.UrlDecode(Request.Form["SELECTION"])); layers = selection.GetLayers(); } // --------------------------------------------------------- // --------------------------------------------------------- // Use the following code for AJAX Viewers only. // This does not require passing selection data via HTTP POST. // // selection = new MgSelection(map); // selection.Open(resourceService, mapName); // layers = selection.GetLayers(); // --------------------------------------------------------- if (layers != null && selection != null) { for (int i = 0; i < layers.GetCount(); i++) { // Only check selected features in the Parcels layer. MgLayerBase layer = layers.GetItem(i); if (layer.GetName() == "Parcels") { // Create a filter containing the IDs of the selected features on this layer String layerClassName = layer.GetFeatureClassName(); MgFeatureReader featureReader = selection.GetSelectedFeatures(layer, layerClassName, false); // Process each item in the MgFeatureReader, displaying the owner name try { while (featureReader.ReadNext()) { String val = featureReader.GetString("NAME") + "
  " + featureReader.GetString("RPROPAD"); Response.Write(val + "
"); } } finally { //Finally guarantees code in this block will execute featureReader.Close(); } } } } else { Response.Write("No selected layers"); Response.Write("

"); } } catch (MgException e) { Response.Write("

" + e.GetExceptionMessage() + "

"); Response.Write("

" + e.GetDetails() + "

"); } %> <% String fileName = Server.MapPath("listselection.aspx"); %>

View source