这一部分也比较简单,主要使用SharpMap提供的标注图层LabelLayer、标注样式LabelStyle,LabelLayer使用示例使用SharpMap提供的,这里就直接粘贴过来:
/// SharpMap.Layers.LabelLayer layLabel = new SharpMap.Layers.LabelLayer("Country labels");
/// layLabel.DataSource = layCountries.DataSource;
/// layLabel.Enabled = true;
/// layLabel.LabelColumn = "Name";
/// layLabel.Style = new SharpMap.Styles.LabelStyle();
/// layLabel.Style.CollisionDetection = true;
/// layLabel.Style.CollisionBuffer = new SizeF(20, 20);
/// layLabel.Style.ForeColor = Color.White;
/// layLabel.Style.Font = new Font(FontFamily.GenericSerif, 8);
/// layLabel.MaxVisible = 90;
/// layLabel.Style.HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center;
这里layLabel比较重要的两个属性:DataSource赋值为需要动态显示标注的图层数据源、LabelColumn赋值为图层数据源的属性字段名称,