using System; using System.Collections.ObjectModel; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.WebEdition; using System.Data.SqlClient; using System.Collections.Generic; namespace helloPakistan { public partial class _Default : System.Web.UI.Page { int k = 0; List provinceNames = new List(); List provincePopulation = new List(); List divisionNames = new List(); List divisionPopulation = new List(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int i = 0; myDataClassesDataContext db = new myDataClassesDataContext(); var provinces = from p in db.Provinces select p; foreach (var province in provinces) { provinceNames.Add(province.name); provincePopulation.Add(Convert.ToInt32(province.population)); } var divisions = from d in db.Divisions select d; foreach (var division in divisions) { divisionNames.Add(division.name); divisionPopulation.Add(Convert.ToInt32(division.population)); } Map1.CurrentExtent = new RectangleShape(5, 70, 30, 36); Map1.MapTools.ScaleLine.Enabled = true; Map1.MapUnit = GeographyUnit.DecimalDegree; Map1.MapTools.MouseCoordinate.MouseCoordinateType = MouseCoordinateType.LongitudeLatitude; Map1.MapTools.MouseCoordinate.Enabled = true; Map1.Cursor = CursorType.Pointer; Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean); //Map1.AjaxEnabled = true; ShapeFileFeatureLayer pakLayer = new ShapeFileFeatureLayer(@"C:\Users\ahsan\Desktop\shapefiles\PAK_adm0.shp"); ShapeFileFeatureLayer.BuildIndexFile(@"C:\Users\ahsan\Desktop\shapefiles\PAK_adm0.shp"); pakLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; //Map1.StaticOverlay.Layers.Add(pakLayer); ShapeFileFeatureLayer.BuildIndexFile(@"C:\Users\ahsan\Desktop\shapefiles\PAK_adm1.shp"); ShapeFileFeatureLayer provinceLayer = new ShapeFileFeatureLayer(@"C:\Users\ahsan\Desktop\shapefiles\PAK_adm1.shp"); //----------------statment to make an overlay to generate hover effect-------------------------// // provinceLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.SimpleColors.Green)); //---------------------------end----------------------------------------------------------------// //--------------------------------end------------------------------------------------------------// provinceLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(255, 243, 239, 228), GeoColor.FromArgb(255, 218, 193, 163), 1)); //provinceLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.CreateSimpleTextStyle("NAME_1", "Arial", 10, DrawingFontStyles.Regular, GeoColor.StandardColors.Red, 0, -12); //------------------------------statement needed for "custom data usage"-------------------------------// //provinceLayer.ZoomLevelSet.ZoomLevel04..DefaultTextStyle =TextStyles.CreateSimpleTextStyle("Test", "Arial", 10, DrawingFontStyles.Regular, GeoColor.StandardColors.Black, 0, -12); //----------------------------------end-----------------------------------------------------------------// provinceLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(TextStyles.CreateSimpleTextStyle("Test", "Arial", 10, DrawingFontStyles.Regular, GeoColor.StandardColors.Black, 0, -12)); provinceLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(TextStyles.CreateSimpleTextStyle("NAME_1", "Arial", 10, DrawingFontStyles.Regular, GeoColor.StandardColors.Red, 0, -12)); provinceLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level06; provinceLayer.DrawingMarginPercentage = 50; // -----------event rigistertom for custom data usage--------------------// provinceLayer.FeatureSource.CustomColumnFetch += new EventHandler(FeatureSource_CustomColumnFetch); provinceLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.RequiredColumnNames.Add("Test"); //------------end--------------------------------//// ShapeFileFeatureLayer.BuildIndexFile(@"C:\Users\ahsan\Desktop\shapefiles\PAK_adm2.shp"); ShapeFileFeatureLayer districtLayer = new ShapeFileFeatureLayer(@"C:\Users\ahsan\Desktop\shapefiles\PAK_adm2.shp"); districtLayer.ZoomLevelSet.ZoomLevel06.CustomStyles.Add( AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.FromArgb(50, GeoColor.SimpleColors.BrightRed))); //districtLayer.ZoomLevelSet.ZoomLevel06.DefaultTextStyle = TextStyles.CreateSimpleTextStyle("NAME_2", "Arial", 6, DrawingFontStyles.Regular, GeoColor.StandardColors.Red, 0, -12); districtLayer.ZoomLevelSet.ZoomLevel06.CustomStyles.Add(TextStyles.CreateSimpleTextStyle("Test1", "Arial", 10, DrawingFontStyles.Regular, GeoColor.StandardColors.Black, 0, -12)); districtLayer.ZoomLevelSet.ZoomLevel06.CustomStyles.Add(AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(255, 243, 239, 228), GeoColor.FromArgb(255, 218, 193, 163), 1)); districtLayer.ZoomLevelSet.ZoomLevel06.CustomStyles.Add(TextStyles.CreateSimpleTextStyle("NAME_2", "Arial", 6, DrawingFontStyles.Regular, GeoColor.StandardColors.Red, 0, -12)); districtLayer.ZoomLevelSet.ZoomLevel06.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; //Map1.StaticOverlay.Layers.Add(districtLayer); // districtLayer.DrawingMarginPercentage = 50; districtLayer.FeatureSource.CustomColumnFetch += new EventHandler(featuresource_customcolumnfetch); districtLayer.ZoomLevelSet.ZoomLevel06.DefaultAreaStyle.RequiredColumnNames.Add("Test1"); int featureCount = divisionPopulation.Count(); //----------------------set background color of map on bases of data attribyte-----------------// //--------------------------------end----------------------------------------------------------// //--------------Selection of a particular feature---------------------// provinceLayer.Open(); Map1.CurrentExtent = provinceLayer.GetBoundingBox(); provinceLayer.Close(); InMemoryFeatureLayer provinceDivisionLayer = new InMemoryFeatureLayer(); provinceDivisionLayer.ZoomLevelSet.ZoomLevel06.CustomStyles.Add(AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.FromArgb(50, GeoColor.SimpleColors.BrightRed))); provinceDivisionLayer.ZoomLevelSet.ZoomLevel06.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; LayerOverlay staticOverlay = new LayerOverlay("StaticOverlay"); staticOverlay.IsBaseOverlay = false; staticOverlay.Layers.Add("ProvinceLayer", provinceLayer); staticOverlay.Layers.Add("DivisionLayer", districtLayer); staticOverlay.Layers.Add("ProvinceDivisionLayer", provinceDivisionLayer); Map1.CustomOverlays.Add(staticOverlay); /* //------------------ to highlight overlay nd hover feature-------------// districtLayer.Open(); Map1.HighlightOverlay.HighlightStyle = new FeatureOverlayStyle(GeoColor.FromArgb(120, GeoColor.StandardColors.LightGreen), GeoColor.StandardColors.Red, 1); foreach (Feature feature in districtLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.NoColumns)) { Map1.HighlightOverlay.Features.Add(feature.Id, feature); } districtLayer.Close(); */ // TAKE A LOOK ON ABOVE FEATURE.ID TO SHOW THE RECORD FRM THE DATA BASE //-------------------end--------------------// } } //-----------------to handle the custm column event-------------// void FeatureSource_CustomColumnFetch(object sender, CustomColumnFetchEventArgs e) { ShapeFileFeatureLayer provinceLayer = new ShapeFileFeatureLayer(@"C:\Users\ahsan\Desktop\shapefiles\PAK_adm1.shp"); provinceLayer.Open(); Feature feature = provinceLayer.FeatureSource.GetFeatureById(e.Id, ReturningColumnsType.AllColumns); provinceLayer.Close(); string featureName = feature.ColumnValues["NAME_1"]; for (int i = 0; i < provinceNames.Count(); i++) { if (provinceNames[i] == featureName) { e.ColumnValue = provincePopulation[i].ToString(); } } } //------------------------end-----------------------------// void featuresource_customcolumnfetch(object sender, CustomColumnFetchEventArgs e) { ShapeFileFeatureLayer divisionLayer = new ShapeFileFeatureLayer(@"C:\Users\ahsan\Desktop\shapefiles\PAK_adm2.shp"); divisionLayer.Open(); Feature feature = divisionLayer.FeatureSource.GetFeatureById(e.Id, ReturningColumnsType.AllColumns); divisionLayer.Close(); string featureName = feature.ColumnValues["NAME_2"]; for (int i = 0; i < divisionNames.Count(); i++) { if (divisionNames[i] == featureName) { e.ColumnValue = divisionPopulation[i].ToString(); } } } * -> DEAR JOHNY! I WANT TO CHANGE THE COLOUR OF THE SELECTED AREA IN RESULT OF CALLING BELOW Button1_Click FUNCTION //--------------------------detect the user selected area on the map-----------------------------------------// protected void Button1_Click(object sender, EventArgs e) { LayerOverlay dynamicOverlay = (LayerOverlay)Map1.CustomOverlays["StaticOverlay"]; ShapeFileFeatureLayer ProvinceLayer = (ShapeFileFeatureLayer)dynamicOverlay.Layers["ProvinceLayer"]; ShapeFileFeatureLayer divisionLayer = (ShapeFileFeatureLayer)dynamicOverlay.Layers["DivisionLayer"]; InMemoryFeatureLayer provinceDivisionLayer = (InMemoryFeatureLayer)dynamicOverlay.Layers["provinceDivisionLayer"]; string Provinces = ProvincesList.SelectedValue; ProvinceLayer.Open(); Collection features = ProvinceLayer.QueryTools.GetFeaturesByColumnValue("NAME_1", Provinces); ProvinceLayer.Close(); if (features.Count > 0) { Map1.CurrentExtent = features[0].GetBoundingBox(); divisionLayer.Open(); Collection divisionFeatures = divisionLayer.QueryTools.GetFeaturesIntersecting(features[0], ReturningColumnsType.NoColumns); divisionLayer.Close(); provinceDivisionLayer.InternalFeatures.Clear(); foreach (Feature feature in divisionFeatures) { provinceDivisionLayer.InternalFeatures.Add(feature); } } } protected void Button2_Click(object sender, EventArgs e) { int i = 0; myDataClassesDataContext db = new myDataClassesDataContext(); var provinces = from p in db.Provinces select p; foreach (var province in provinces) { provinceNames.Add(province.name); provincePopulation.Add(Convert.ToInt32(province.population)); } var divisions = from d in db.Divisions select d; foreach (var division in divisions) { divisionNames.Add(division.name); divisionPopulation.Add(Convert.ToInt32(division.population)); } if (areaLevel.SelectedIndex == 0) { Map1.CurrentExtent = new RectangleShape(5, 70, 30, 36); Map1.MapTools.ScaleLine.Enabled = true; Map1.MapUnit = GeographyUnit.DecimalDegree; Map1.MapTools.MouseCoordinate.MouseCoordinateType = MouseCoordinateType.LongitudeLatitude; Map1.MapTools.MouseCoordinate.Enabled = true; Map1.Cursor = CursorType.Pointer; Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean); //Map1.AjaxEnabled = true; ShapeFileFeatureLayer pakLayer = new ShapeFileFeatureLayer(@"C:\Users\ahsan\Desktop\shapefiles\PAK_adm0.shp"); ShapeFileFeatureLayer.BuildIndexFile(@"C:\Users\ahsan\Desktop\shapefiles\PAK_adm0.shp"); pakLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; Map1.StaticOverlay.Layers.Add(pakLayer); ShapeFileFeatureLayer.BuildIndexFile(@"C:\Users\ahsan\Desktop\shapefiles\PAK_adm1.shp"); ShapeFileFeatureLayer provinceLayer = new ShapeFileFeatureLayer(@"C:\Users\ahsan\Desktop\shapefiles\PAK_adm1.shp"); //----------------statment to make an overlay to generate hover effect-------------------------// // provinceLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.SimpleColors.Green)); //---------------------------end----------------------------------------------------------------// //--------------------------------end------------------------------------------------------------// provinceLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(255, 243, 239, 228), GeoColor.FromArgb(255, 218, 193, 163), 1)); provinceLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(TextStyles.CreateSimpleTextStyle("Test", "Arial", 10, DrawingFontStyles.Regular, GeoColor.StandardColors.Black, 0, -12)); provinceLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(TextStyles.CreateSimpleTextStyle("NAME_1", "Arial", 10, DrawingFontStyles.Regular, GeoColor.StandardColors.Red, 0, -12)); provinceLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; provinceLayer.DrawingMarginPercentage = 50; // -----------event rigistertom for custom data usage--------------------// provinceLayer.FeatureSource.CustomColumnFetch += new EventHandler(FeatureSource_CustomColumnFetch); provinceLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.RequiredColumnNames.Add("Test"); Map1.StaticOverlay.Layers.Add(provinceLayer); //----------------------set background color of map on bases of data attribyte-----------------// int featureCount = provinceNames.Count(); Collection colorsInFamily = GeoColor.GetColorsInHueFamily(GeoColor.StandardColors.Green, featureCount); ValueStyle valueStyle = new ValueStyle(); valueStyle.ColumnName = "NAME_1"; for (int j = 0; j < featureCount; j++) { valueStyle.ValueItems.Add(new ValueItem(provinceNames[j], new AreaStyle(new GeoSolidBrush(colorsInFamily[j])))); TextBox2.Text = TextBox2.Text + " " + provincePopulation[j]; } provinceLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle); //--------------------------------end----------------------------------------------------------// ShapeFileFeatureLayer.BuildIndexFile(@"C:\Users\ahsan\Desktop\shapefiles\PAK_adm2.shp"); ShapeFileFeatureLayer districtLayer = new ShapeFileFeatureLayer(@"C:\Users\ahsan\Desktop\shapefiles\PAK_adm2.shp"); //districtLayer.ZoomLevelSet.ZoomLevel06.CustomStyles.Add( AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.FromArgb(50, GeoColor.SimpleColors.BrightRed))); //districtLayer.ZoomLevelSet.ZoomLevel06.DefaultTextStyle = TextStyles.CreateSimpleTextStyle("NAME_2", "Arial", 6, DrawingFontStyles.Regular, GeoColor.StandardColors.Red, 0, -12); districtLayer.ZoomLevelSet.ZoomLevel06.CustomStyles.Add(TextStyles.CreateSimpleTextStyle("NAME_2", "Arial", 6, DrawingFontStyles.Regular, GeoColor.StandardColors.Red, 0, -12)); Map1.ZoomLevelSet.ZoomLevel06.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; Map1.StaticOverlay.Layers.Add(districtLayer); //-----------------city layer addition-------------------// ShapeFileFeatureLayer.BuildIndexFile(@"C:\Users\ahsan\Desktop\shapefiles\PAK_adm3.shp"); ShapeFileFeatureLayer cityLayer = new ShapeFileFeatureLayer(@"C:\Users\ahsan\Desktop\shapefiles\PAK_adm3.shp"); cityLayer.ZoomLevelSet.ZoomLevel07.CustomStyles.Add(TextStyles.Urban1("NAME_3")); cityLayer.ZoomLevelSet.ZoomLevel07.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; Map1.StaticOverlay.Layers.Add(cityLayer); //------------------end----------------------------------// } else { Map1.CurrentExtent = new RectangleShape(5, 78, 30, 36); Map1.MapTools.ScaleLine.Enabled = true; Map1.MapUnit = GeographyUnit.DecimalDegree; Map1.MapTools.MouseCoordinate.MouseCoordinateType = MouseCoordinateType.LongitudeLatitude; Map1.MapTools.MouseCoordinate.Enabled = true; Map1.Cursor = CursorType.Pointer; Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean); //Map1.AjaxEnabled = true; ShapeFileFeatureLayer pakLayer = new ShapeFileFeatureLayer(@"C:\Users\ahsan\Desktop\shapefiles\PAK_adm0.shp"); ShapeFileFeatureLayer.BuildIndexFile(@"C:\Users\ahsan\Desktop\shapefiles\PAK_adm0.shp"); pakLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; Map1.StaticOverlay.Layers.Add(pakLayer); ShapeFileFeatureLayer.BuildIndexFile(@"C:\Users\ahsan\Desktop\shapefiles\PAK_adm1.shp"); ShapeFileFeatureLayer provinceLayer = new ShapeFileFeatureLayer(@"C:\Users\ahsan\Desktop\shapefiles\PAK_adm1.shp"); //----------------statment to make an overlay to generate hover effect-------------------------// // provinceLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.SimpleColors.Green)); //---------------------------end----------------------------------------------------------------// //--------------------------------end------------------------------------------------------------// provinceLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(255, 243, 239, 228), GeoColor.FromArgb(255, 218, 193, 163), 1)); provinceLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(TextStyles.CreateSimpleTextStyle("NAME_1", "Arial", 10, DrawingFontStyles.Regular, GeoColor.StandardColors.Red, 0, -12)); provinceLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; provinceLayer.DrawingMarginPercentage = 50; Map1.StaticOverlay.Layers.Add(provinceLayer); ShapeFileFeatureLayer.BuildIndexFile(@"C:\Users\ahsan\Desktop\shapefiles\PAK_adm2.shp"); ShapeFileFeatureLayer districtLayer = new ShapeFileFeatureLayer(@"C:\Users\ahsan\Desktop\shapefiles\PAK_adm2.shp"); districtLayer.ZoomLevelSet.ZoomLevel06.CustomStyles.Add( AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.FromArgb(50, GeoColor.SimpleColors.BrightRed))); districtLayer.ZoomLevelSet.ZoomLevel06.CustomStyles.Add(TextStyles.CreateSimpleTextStyle("NAME_2", "Arial", 6, DrawingFontStyles.Regular, GeoColor.StandardColors.Red, 0, -12)); districtLayer.ZoomLevelSet.ZoomLevel06.CustomStyles.Add(TextStyles.CreateSimpleTextStyle("Test", "Arial", 10, DrawingFontStyles.Regular, GeoColor.StandardColors.Black, 0, -12)); Map1.ZoomLevelSet.ZoomLevel06.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; Map1.StaticOverlay.Layers.Add(districtLayer); districtLayer.FeatureSource.CustomColumnFetch += new EventHandler(featuresource_customcolumnfetch); districtLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.RequiredColumnNames.Add("Test"); //----------------------set background color of map on bases of data attribyte-----------------// int featureCount = divisionNames.Count(); Collection colorsInFamily = GeoColor.GetColorsInHueFamily(GeoColor.StandardColors.Green, featureCount); ValueStyle valueStyle = new ValueStyle(); valueStyle.ColumnName = "NAME_2"; for (int j = 0; j < featureCount; j++) { valueStyle.ValueItems.Add(new ValueItem(divisionNames[j], new AreaStyle(new GeoSolidBrush(colorsInFamily[j])))); TextBox2.Text = TextBox2.Text + " " + divisionPopulation[j]; } districtLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle); //--------------------------------end----------------------------------------------------------// } } } }