private void ApplyStyleOnMap(CosM.CosmeticTableBaseM cosLayer)
        {
            var  mvLayer       = Program.mainFrm1.axMapLIb1.getLayer(cosLayer.Name);
            bool isPrevVisible = mvLayer != null ? mvLayer.Visible : false;

            cosLayer.IsVisible = false;

            // Указываем стиль по умолчанию для слоя и стиль подписей
            mvLayer = Program.mainFrm1.axMapLIb1.getLayer(cosLayer.Name);
            if (mvLayer != null)
            {
                mvLayer.MaxScale  = (uint)cosLayer.DefaultStyle.MaxScale;
                mvLayer.MinScale  = (uint)cosLayer.DefaultStyle.MinScale;
                mvLayer.usebounds = cosLayer.DefaultStyle.UseBounds;

                var symbolStyle = new mvSymbolObject()
                {
                    shape = (uint)cosLayer.DefaultStyle.Symbol
                };
                var penStyle = new mvPenObject()
                {
                    Color = (uint)cosLayer.DefaultStyle.PenColor,
                    ctype = (ushort)cosLayer.DefaultStyle.PenType,
                    width = (uint)cosLayer.DefaultStyle.PenWidth
                };
                var brushStyle = new mvBrushObject()
                {
                    bgcolor = (uint)cosLayer.DefaultStyle.BrushBgColor,
                    fgcolor = (uint)cosLayer.DefaultStyle.BrushFgColor,
                    hatch   = (ushort)cosLayer.DefaultStyle.BrushHatch,
                    style   = (ushort)cosLayer.DefaultStyle.BrushStyle
                };
                var fontStyle = new mvFontObject()
                {
                    fontname     = cosLayer.DefaultStyle.FontName,
                    Color        = (uint)cosLayer.DefaultStyle.FontColor,
                    framecolor   = (uint)cosLayer.DefaultStyle.FontFrameColor,
                    graphicUnits = cosLayer.DefaultStyle.GraphicUnits,
                    size         = cosLayer.DefaultStyle.FontSize
                };

                if (cosLayer.DefaultStyle.BrushStyle == 0 && cosLayer.DefaultStyle.BrushHatch == 0)
                {
                    int grey = Convert.ToInt32(255 & (int)(cosLayer.DefaultStyle.Opacity * 255));
                    brushStyle.bgcolor = Convert.ToUInt32(grey + (grey << 8) + (grey << 16));
                }
                else if (!cosLayer.DefaultStyle.HasBackground)
                {
                    brushStyle.bgcolor = 0xffffffff;
                }


                cosLayer.SetDefaultStyle(symbolStyle, fontStyle, penStyle, brushStyle);

                mvFontObject labelFontObj = new mvFontObject();
                labelFontObj.Color    = cosLayer.LabelStyle.LabelFontColor;
                labelFontObj.fontname = cosLayer.LabelStyle.LabelFontName;
                if (cosLayer.LabelStyle.LabelShowFrame)
                {
                    labelFontObj.framecolor = cosLayer.LabelStyle.LabelFrameColor;
                }
                else
                {
                    labelFontObj.framecolor = 0xFFFFFFFF;
                }
                labelFontObj.graphicUnits = cosLayer.LabelStyle.LabelUseGraphicUnits;
                labelFontObj.italic       = cosLayer.LabelStyle.LabelFontItalic;
                labelFontObj.size         = cosLayer.LabelStyle.LabelFontSize;
                labelFontObj.strikeout    = cosLayer.LabelStyle.LabelFontStrikeout;
                labelFontObj.underline    = cosLayer.LabelStyle.LabelFontUnderline;
                if (cosLayer.LabelStyle.LabelFontBold)
                {
                    labelFontObj.weight = 650;
                }
                mvLayer.showlabels = true;
                if (cosLayer.LabelStyle.LabelUseBounds)
                {
                    mvLayer.labelBounds   = true;
                    mvLayer.labelMinScale = cosLayer.LabelStyle.LabelMinScale;
                    mvLayer.labelMaxScale = cosLayer.LabelStyle.LabelMaxScale;
                }
                mvLayer.labelParallel = cosLayer.LabelStyle.LabelParallel;
                mvLayer.labelOverlap  = cosLayer.LabelStyle.LabelOverlap;
                mvLayer.labelOffset   = cosLayer.LabelStyle.LabelOffset;
                mvLayer.LabelField    = 1;
                mvLayer.SetLabelstyle(labelFontObj);

                cosLayer.IsVisible = isPrevVisible;

                _mv.mapRepaint();
                mvLayer.Update();
                ReloadInfo();
            }
        }
        /// <summary>
        /// Сохранить стиль объекта и применить к объекту
        /// </summary>
        private void SaveStyle()
        {
            if (TableObject != null)
            {
                TableObject.Style = StyleVM;
            }
            var layer    = _source.MapViewer.getLayer(Table.Name);
            var layerObj = layer.getObject(TableObject.Id);

            if (layer != null)
            {
                if (HasOwnStyle)
                {
                    int  ownStyleNum       = layerObj.style;
                    bool ownStyleIsDefault =
                        ownStyleNum == Table.DefaultDotStyle.Value ||
                        ownStyleNum == Table.DefaultLineStyle.Value ||
                        ownStyleNum == Table.DefaultPolygonStyle.Value;
                    switch (StyleVM.CosmeticStyleType)
                    {
                    case CosM.CosmeticStyleType.Point:
                        mvSymbolObject symbol = new mvSymbolObject()
                        {
                            shape = (uint)StyleVM.Symbol
                        };
                        mvFontObject font = new mvFontObject()
                        {
                            fontname   = StyleVM.FontName,
                            size       = StyleVM.FontSize,
                            Color      = (uint)StyleVM.FontColor,
                            framecolor = (uint)StyleVM.FontFrameColor
                        };
                        if (ownStyleIsDefault)
                        {
                            layerObj.style = layer.CreateDotStyle(symbol, font);
                        }
                        else
                        {
                            layer.editStyle(ownStyleNum, null, null, symbol, font);
                        }
                        break;

                    case CosM.CosmeticStyleType.Line:
                        mvPenObject pen_line = new mvPenObject()
                        {
                            Color = (uint)StyleVM.PenColor,
                            ctype = (ushort)StyleVM.PenType,
                            width = (uint)StyleVM.PenWidth
                        };
                        if (ownStyleIsDefault)
                        {
                            layerObj.style = layer.CreateLineStyle(pen_line);
                        }
                        else
                        {
                            layer.editStyle(ownStyleNum, pen_line, null, null, null);
                        }
                        break;

                    case CosM.CosmeticStyleType.Polygon:
                        mvPenObject stroke = new mvPenObject()
                        {
                            Color = (uint)StyleVM.PenColor,
                            ctype = (ushort)StyleVM.PenType,
                            width = (uint)StyleVM.PenWidth
                        };
                        mvBrushObject brush = new mvBrushObject()
                        {
                            bgcolor = (uint)StyleVM.BrushBgColor,
                            fgcolor = (uint)StyleVM.BrushFgColor,
                            style   = (ushort)StyleVM.BrushStyle,
                            hatch   = (ushort)StyleVM.BrushHatch
                        };

                        if (StyleVM.BrushStyle == 0 && StyleVM.BrushHatch == 0)
                        {
                            int grey = Convert.ToInt32(255 & (int)(StyleVM.Opacity * 255));
                            brush.bgcolor = Convert.ToUInt32(grey + (grey << 8) + (grey << 16));
                        }
                        else if (!StyleVM.HasBackground)
                        {
                            brush.bgcolor = 0xffffffff;
                        }

                        if (ownStyleIsDefault)
                        {
                            layerObj.style = layer.CreatePolygonStyle(stroke, brush);
                        }
                        else
                        {
                            layer.editStyle(ownStyleNum, stroke, brush, null, null);
                        }
                        break;
                    }
                }
                else
                {
                    switch (StyleVM.CosmeticStyleType)
                    {
                    case CosM.CosmeticStyleType.Point:
                        layerObj.style = Table.DefaultDotStyle.Value;
                        break;

                    case CosM.CosmeticStyleType.Line:
                        layerObj.style = Table.DefaultLineStyle.Value;
                        break;

                    case CosM.CosmeticStyleType.Polygon:
                        layerObj.style = Table.DefaultPolygonStyle.Value;
                        break;
                    }
                }
                layer.ExternalFullReloadVisible();
            }
        }
示例#3
0
        public void SetDefaultStyle(mvSymbolObject symbolStyle, mvFontObject fontStyle, mvPenObject penStyle, mvBrushObject brushStyle)
        {
            var layer = Program.mainFrm1.axMapLIb1.getLayer(Name);

            if (_defaultDotStyle == null || _defaultLineStyle == null || _defaultPolygonStyle == null)
            {
                _defaultDotStyle     = layer.CreateDotStyle(symbolStyle, fontStyle);
                _defaultLineStyle    = layer.CreateLineStyle(penStyle);
                _defaultPolygonStyle = layer.CreatePolygonStyle(penStyle, brushStyle);
            }
            else
            {
                layer.editStyle(_defaultDotStyle.Value, null, null, symbolStyle, fontStyle);
                layer.editStyle(_defaultLineStyle.Value, penStyle, null, null, null);
                layer.editStyle(_defaultPolygonStyle.Value, penStyle, brushStyle, null, null);
            }
        }