MapWindow5中的标签设置
最终实现效果,标签要在线段上部显示
先上预览图:
进入MapWindow官网查询后,发现不生效
查看类图如下:
最后打各种断点调试后发现,应该如下设置:
ILayer lineLayer = LayerHelper.getLayerByName(_context,
MW5.Shared.Enums.EquipmentType.GUAN_XIAN.ToString());
if (lineLayer == null)
{
MessageService.Current.Info(ResourceUtil.GetTitle("NoLineLayerMessage"));
return;
}
var mapcontrol = (Api.Map.MapControl)_context.Map;
var axmap = mapcontrol.GetMap();
var table = lineLayer.FeatureSet.Table;
var fs = lineLayer.FeatureSet;
fs.InteractiveEditing = true;
string fieldNames = string.Empty;
IEnumerator enumerator = fs.Fields.GetEnumerator();
while (enumerator.MoveNext())
{
fieldNames += ((AttributeField)enumerator.Current).Name+",";
}
if (!fieldNames.Contains("Press") && !fieldNames.Contains("Flow"))
{
fs.Fields.Add("Press", AttributeType.Double, 5, 20);
fs.Fields.Add("Flow", AttributeType.Double, 5, 20);
}
fs.Fields[fs.Fields.IndexByName("Press")].Visible = false;
fs.Fields[fs.Fields.IndexByName("Flow")].Visible = false;
if (itemSourceLists.Count > 0)
{
for (int i = 0; i < fs.Features.Count; i++)
{
var gid = table.CellValue(1, i);
var data = itemSourceLists.Where(t => t.Gid == Convert.ToInt32(gid)).ToList().FirstOrDefault();
if (data != null)
{
fs.Features[i].SetDouble(fs.Fields.IndexByName("Press"), data.LinePa);
fs.Features[i].SetDouble(fs.Fields.IndexByName("Flow"), data.LineTemp);
}
}
fs.GenerateEmptyLabels(LabelPosition.MiddleSegment, false);
fs.Labels.Expression = "[Press] +\"MPa \"+ [Flow] +\"Nm³/h\"";
fs.Labels.VisibilityExpression = "";
fs.Labels.Style.Orientation = LabelOrientation.Parallel;
fs.Labels.Style.Alignment = LabelAlignment.TopCenter;
fs.Labels.Synchronized = true;
fs.Labels.SavingMode = PersistenceType.None;
fs.Labels.Style.FontTransparency = 200;
fs.Labels.Style.FrameTransparency = 0;
fs.InteractiveEditing = false;
_context.Map.Redraw();
}
如果要设置其他更多的样式,点击fs.Label.Style中可以设置其他的样式。