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中可以设置其他的样式。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值