using System; using System.Collections.ObjectModel; using System.Data; using System.Web.UI; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.WebEdition; namespace CSSamples.Samples.Querying_Vector_Layers { public partial class GetDataWhenUserClicks : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF")); Map1.CurrentExtent = new RectangleShape(-125, 72, 50, -46); Map1.MapUnit = GeographyUnit.DecimalDegree; WorldMapKitWmsWebOverlay worldMapKitOverlay = new WorldMapKitWmsWebOverlay(); Map1.CustomOverlays.Add(worldMapKitOverlay); ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(MapPath("~/SampleData/world/cntry02.shp")); worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.FromArgb(100, GeoColor.SimpleColors.Green)); worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; LayerOverlay staticOverlay = new LayerOverlay("StaticOverlay"); staticOverlay.IsBaseOverlay = false; staticOverlay.Layers.Add("WorldLayer", worldLayer); Map1.CustomOverlays.Add(staticOverlay); } } protected void Map1_Click(object sender, MapClickedEventArgs e) { LayerOverlay staticOverlay = (LayerOverlay)Map1.CustomOverlays["StaticOverlay"]; foreach (Layer layer in staticOverlay.Layers) { if (layer is FeatureLayer) { layer.Open(); Collection selectedFeatures = ((FeatureLayer)layer).QueryTools.GetFeaturesContaining(e.Position, ReturningColumnsType.AllColumns); if (selectedFeatures.Count > 0) { Collection columns = ((FeatureLayer)layer).QueryTools.GetColumns(); DataTable table = new DataTable(); foreach (FeatureSourceColumn column in columns) { table.Columns.Add(column.ColumnName); } foreach (Feature feature in selectedFeatures) { DataRow row = table.NewRow(); for (int i = 0; i < table.Columns.Count; i++) { row[i] = feature.ColumnValues[table.Columns[i].ColumnName]; } table.Rows.Add(row); } // Your customized logic break; } layer.Close(); } } } } }