|
008、如何为mapControl中的一个地图表增加主题? 为SHENGQU这个面样式表来增加主题。 // Listen to some map events mapControl1.Resize += new EventHandler(mapControl1_Resize); //在此事件中处理当mapControl改变大小时来重新定位主题表的位置。
// Create a ranged theme on the USA layer. Map map = mapControl1.Map; FeatureLayer lyr = map.Layers["SHENGQU"] as MapInfo.Mapping.FeatureLayer; RangedTheme thm = new MapInfo.Mapping.Thematics.RangedTheme( lyr, "Round(MI_Area(Obj, 'sq km', 'Spherical'), 1)", "Area (square kilometer)", 5, MapInfo.Mapping.Thematics.DistributionMethod.EqualRangeSize);//.EqualCountPerRange); lyr.Modifiers.Append(thm); // Change the default fill colors from Red->Gray to White->Blue AreaStyle ars; // Get the style from our first bin CompositeStyle cs = thm.Bins[0].Style; // Get the region -- Area -- style ars = cs.AreaStyle; // Change the fill color ars.Interior = StockStyles.WhiteFillStyle(); // Update the CompositeStyle with the new region color cs.AreaStyle = ars; // Update the bin with the new CompositeStyle settings thm.Bins[0].Style = cs; // Change the style settings on the last bin int nLastBin = thm.Bins.Count - 1; cs = thm.Bins[nLastBin].Style; ars = cs.AreaStyle; ars.Interior = StockStyles.BlueFillStyle(); thm.Bins[nLastBin].Style = cs; // Tell the theme how to fill in the other bins thm.SpreadBy = SpreadByPart.Color; thm.ColorSpreadBy = ColorSpreadMethod.Rgb; thm.RecomputeStyles(); // Create a legend legend = map.Legends.CreateLegend(new Size(5, 5)); legend.Border = true; ThemeLegendFrame frame = LegendFrameFactory.CreateThemeLegendFrame("Area", "Area", thm); legend.Frames.Append(frame); frame.Title = "Area (sq. mi.)"; map.Adornments.Append(legend); // Set the initial legend location to be the lower right corner of the map control. System.Drawing.Point pt = new System.Drawing.Point(0, 0); pt.X = mapControl1.Size.Width - legend.Size.Width; pt.Y = mapControl1.Size.Height - legend.Size.Height; legend.Location = pt; 在mapControl1_Resize事件中针对mapControl大小的改变来变化主题表的位置。 private void mapControl1_Resize(object sender, System.EventArgs e) { Control control = (Control)sender; // Move the Legend to the lower right corner... System.Drawing.Point pt = new System.Drawing.Point(0, 0); pt.X = control.Size.Width - legend.Size.Width; pt.Y = control.Size.Height - legend.Size.Height; legend.Location = pt; }
|