<%@ Page Language="C#" %> <%@ Import Namespace="System" %> <%@ Import Namespace="System.IO" %> <%@ Import Namespace="System.Collections.Generic" %> <%@ Import Namespace="System.Web" %> <%@ Import Namespace="System.Xml" %> <%@ Import Namespace="System.Globalization" %> <%@ Import Namespace="OSGeo.MapGuide" %> <% mapName = ""; sessionId = ""; locale = ""; GetRequestParameters(); if (String.IsNullOrEmpty(locale)) locale = GetDefaultLocale(); culture = CultureInfo.GetCultureInfo(locale); regex = new System.Text.RegularExpressions.Regex("\\s+"); //HACK: The default locale (en) resolves to a neutral culture, .net forbids the use of //neutral cultures for formatting purposes, so default to InvariantCulture if the resolved //culture is not neutral. if (culture.IsNeutralCulture) culture = CultureInfo.InvariantCulture; //We need a non-neutral culture try { MgUserInformation cred = new MgUserInformation(sessionId); cred.SetClientIp(GetClientIp(Request)); cred.SetClientAgent(GetClientAgent()); MgSiteConnection site = new MgSiteConnection(); site.Open(cred); MgResourceService resSvc = (MgResourceService)site.CreateService(MgServiceType.ResourceService); MgMap map = new MgMap(site); map.Open(mapName); MgSelection selection = new MgSelection(map); selection.Open(resSvc, mapName); MgReadOnlyLayerCollection layers = selection.GetLayers(); if (layers != null && layers.Count > 0) { int layerCount = layers.Count; MgAgfReaderWriter agfRW = new MgAgfReaderWriter(); SelectionSet selectionSet = new SelectionSet(); for (int i = 0; i < layerCount; i++) { MgLayerBase layer = layers[i]; String layerName = layer.Name; MgResourceIdentifier fsId = new MgResourceIdentifier(layer.GetFeatureSourceId()); String className = layer.GetFeatureClassName(); String geomName = layer.GetFeatureGeometryName(); MgFeatureQueryOptions query = new MgFeatureQueryOptions(); NameValueCollection mappings = GetLayerPropertyMappings(resSvc, layer); foreach (String key in mappings.Keys) { query.AddFeatureProperty(key); } query.AddFeatureProperty(geomName); String filter = selection.GenerateFilter(layer, className); query.SetFilter(filter); MgFeatureReader reader = layer.SelectFeatures(query); MgClassDefinition clsDef = reader.GetClassDefinition(); MgPropertyDefinitionCollection props = clsDef.GetProperties(); while (reader.ReadNext()) { Feature feat = new Feature(layerName); ZoomBox zoom = null; for (int k = 0; k < props.Count; k++) { MgPropertyDefinition propDef = props[k]; String propName = propDef.Name; int propType = reader.GetPropertyType(propName); if (mappings[propName] != null || propType == MgPropertyType.Geometry) { String value = ""; if (!reader.IsNull(propName)) { if (propName == geomName) { MgByteReader agf = reader.GetGeometry(propName); MgGeometry geom = agfRW.Read(agf); MgEnvelope env = geom.Envelope(); MgCoordinate ll = env.GetLowerLeftCoordinate(); MgCoordinate ur = env.GetUpperRightCoordinate(); zoom = new ZoomBox(); zoom.MinX = ll.X; zoom.MinY = ll.Y; zoom.MaxX = ur.X; zoom.MaxY = ur.Y; feat.Zoom = zoom; } else { value = GetPropertyValueFromFeatureReader(reader, agfRW, propType, propName); } if (mappings[propName] != null) { FeatureProperty fp = new FeatureProperty(); fp.Name = mappings[propName]; fp.Value = value; feat.AddProperty(fp); } } } } selectionSet.AddFeature(feat); } reader.Close(); } //Now output the selection set Response.AddHeader("Content-Type", "application/json"); Response.AddHeader("X-JSON", "true"); Response.Write(GetJson(selectionSet)); } } catch (MgException ex) { Response.AddHeader("Content-Type", "application/json"); Response.AddHeader("X-JSON", "true"); Response.Write(JsonifyError(ex)); } catch (Exception ex) { Response.AddHeader("Content-Type", "application/json"); Response.AddHeader("X-JSON", "true"); Response.Write(JsonifyError(ex)); } %>