Hi,
I am a newbie to this field, so after reading many samples, forum topics, and documentation. I have been unsuccessful at figuring out a way to inquiry from database tables and the color of the polygon change when the result match the geometry table “id”. Could you provide a code snippet that illustrates doing this?
This is the code I’m using :
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#b12020"));
Map1.CurrentExtent = new RectangleShape(40.8, 15.5, 54.5, 15.4);
Map1.MapUnit = GeographyUnit.DecimalDegree;
//layer of the provinces to be viseble on the map …
MsSql2008FeatureLayer sql2009Layer = new MsSql2008FeatureLayer(connectString, “ProvinceMap”, “Province_ID”);
sql2009Layer.Open();
sql2009Layer.ZoomLevelSet.ZoomLevel05.DefaultAreaStyle = AreaStyles.Country1;
sql2009Layer.ZoomLevelSet.ZoomLevel05.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level09;
// layer of the provinces names…
MsSql2008FeatureLayer sql2009Label = new MsSql2008FeatureLayer(connectString, “ProvinceMap”, “NAME_1”);
sql2009Label.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level08;
sql2009Layer.Srid = 4326;
//layer of the states to be viseble on the map …
MsSql2008FeatureLayer sql2008Layer = new MsSql2008FeatureLayer(connectString, “StateMap”, “State_ID”);
sql2008Layer.Open();
sql2008Layer.ZoomLevelSet.ZoomLevel09.DefaultAreaStyle = AreaStyles.Country1;
sql2008Layer.ZoomLevelSet.ZoomLevel09.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level15;
// layer of the state names…
MsSql2008FeatureLayer sql2008Label = new MsSql2008FeatureLayer(connectString, “StateMap”, “NAME_2”);
sql2008Label.ZoomLevelSet.ZoomLevel09.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level15;
//need to set the Srid to 4326 when convirting the shapfile to sql database or will face problems on the idintfiying the geometric…
sql2008Layer.Srid = 4326;
//layer of changing the color of clicked area …
InMemoryFeatureLayer highlightLayer = new InMemoryFeatureLayer();
highlightLayer.ZoomLevelSet.ZoomLevel05.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(100, 60, 180, 60), GeoColor.GeographicColors.DeepOcean);
highlightLayer.ZoomLevelSet.ZoomLevel05.DefaultTextStyle = TextStyles.Country1(“NAME_1”);
highlightLayer.ZoomLevelSet.ZoomLevel05.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
highlightLayer.DrawingMarginPercentage = 10;
//seting the province names text style
TextStyle textStyle = TextStyles.City2(“NAME_1”);
sql2009Label.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(textStyle);
//seting the state names text style , and to be visiable on zoom level 9 …
TextStyle textSty = TextStyles.City1(“NAME_2”);
sql2008Label.ZoomLevelSet.ZoomLevel09.CustomStyles.Add(textSty);
// to activate the ScaleLine of the map, need to adjeset the mouse for the ScaleLine to change by the change of the mouse location on the map…
Map1.MapTools.ScaleLine.Enabled = true;
Map1.MapTools.MouseCoordinate.MouseCoordinateType = MouseCoordinateType.DegreesMinutesSeconds;
Map1.MapTools.MouseCoordinate.Enabled = true;
//Activate the Minimap
Map1.MapTools.MiniMap.Enabled = true;
//if there’s problem or multipolygon of some geometric data in the database you use this method …
sql2009Layer.MakeAllGeometriesValid();
sql2008Layer.MakeAllGeometriesValid();
InMemoryFeatureLayer selectedLayer = new InMemoryFeatureLayer();
LayerOverlay overlay = new LayerOverlay(“YemenOverlay”);
overlay.IsBaseOverlay = true;
overlay.Layers.Add(“sql2009Layer”, sql2009Layer);
overlay.Layers.Add(“sql2008Layer”, sql2008Layer);
overlay.Layers.Add(“SelectedLayer”, selectedLayer);
overlay.Layers.Add(“sql2009Label”, sql2009Label);
overlay.Layers.Add(“sql2008Label”, sql2008Label);
LayerOverlay dynamicOverlay = new LayerOverlay(“DynamicOverlay”);
dynamicOverlay.IsBaseOverlay = false;
dynamicOverlay.TileType = TileType.SingleTile;
dynamicOverlay.Layers.Add(“HighlightLayer”, highlightLayer);
Map1.CustomOverlays.Add(dynamicOverlay);
Map1.CustomOverlays.Add(overlay);
sql2008Layer.Close();
sql2009Layer.Close();
}
}
Thanks,
Ghamdan
Inquiry From SQL database and affect the map by result
Hi Ghamdan,
If what I am guessing is correct, you want the features show different area style by feature id. We can use ValueStyle to do this.
Please try the codes below:
Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
Map1.CurrentExtent = new RectangleShape(-125, 72, 50, -46);
Map1.MapUnit = GeographyUnit.DecimalDegree;
MsSql2008FeatureLayer stateLayer = new MsSql2008FeatureLayer(connectionString, "States1", "ID");
stateLayer.Open();
var features = stateLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.NoColumns);
Collection<ValueItem> valueItems = new Collection<ValueItem>();
foreach (var item in features)
{
string pop = item.Id;
if (int.Parse(pop) > 20 && int.Parse(pop) < 26)
{
valueItems.Add(new ValueItem(pop, AreaStyles.CreateSimpleAreaStyle(GeoColor.GeographicColors.Sand, GeoColor.SimpleColors.Black, 3)));
}
}
stateLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(AreaStyles.CreateSimpleAreaStyle(GeoColor.StandardColors.DarkGray, GeoColor.SimpleColors.Green, 3));
stateLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(new ValueStyle("ID", valueItems));
stateLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
LayerOverlay overlay = new LayerOverlay();
overlay.Layers.Add(stateLayer);
Map1.CustomOverlays.Add(overlay);
If anything we misunderstanding, please feel free to correct us.
Thanks,
Bill
Hi Bill,
Sorry, for the late replay we had some connection problems.
Back to the subject : Your guessing is correct, I used the code you provided with small adjustment, and the first test was successful. I’ll run some more tests and see the results. Hope nothing goes wrong.
Thank you very much,
Ghamdan
Hi Ghamdan,
Good to hear the test works fine.
If the issue persists after more tests, please feel free to let us know.
Regards,
Johnny