Beispiel #1
0
 public RedlineLayer(string name, string fsId, string layerDef, int geomTypes, RedlineStylizationType styleType)
 {
     this.Name            = name;
     this.FeatureSource   = fsId;
     this.LayerDefinition = layerDef;
     this.GeometryTypes   = geomTypes;
     this.StyleType       = styleType;
 }
Beispiel #2
0
        private string CreateRedlineLayerDefinitionContent(MgResourceIdentifier fsId, string className, RedlineStyle style, RedlineStylizationType type)
        {
            double transpc           = (100 - style.FillTransparency) / 100;
            string hexFgTransparency = string.Format("{0:X2}", Convert.ToInt32(255 * transpc)); //Convert % to alpha value
            string hexBgTransparency = style.FillBackTransparency ? "FF" : "00";                //All or nothing

            if (type == RedlineStylizationType.Basic)
            {
                string template = Strings.markuplayerdefinition;
                return(Util.Substitute(template,
                                       new string [] {
                    fsId.ToString(),                                                //<ResourceId> - Feature Source
                    className,                                                      //<FeatureName> - Class Name
                    style.LabelSizeUnits.ToString(),                                //<Unit> - Mark Label
                    style.LabelFontSize.ToString(CultureInfo.InvariantCulture),     //<SizeX> - Mark Label Size
                    style.LabelFontSize.ToString(CultureInfo.InvariantCulture),     //<SizeY> - Mark Label Size
                    "FF" + Util.ToHtmlColor(style.LabelForeColor),                  //<ForegroundColor> - Mark Label
                    "FF" + Util.ToHtmlColor(style.LabelBackColor),                  //<BackgroundColor> - Mark Label
                    style.LabelBackStyle.ToString(),                                //<BackgroundStyle> - Mark Label
                    style.LabelBold.ToString().ToLower(),                           //<Bold> - Mark Label
                    style.LabelItalic.ToString().ToLower(),                         //<Bold> - Mark Label
                    style.LabelUnderline.ToString().ToLower(),                      //<Underlined> - Mark Label
                    style.MarkerSizeUnits.ToString(),                               //<Unit> - Mark
                    style.MarkerSize.ToString(CultureInfo.InvariantCulture),        //<SizeX> - Mark
                    style.MarkerSize.ToString(CultureInfo.InvariantCulture),        //<SizeY> - Mark
                    style.MarkerType.ToString(),                                    //<Shape> - Mark
                    "FF" + Util.ToHtmlColor(style.MarkerColor),                     //<ForegroundColor> - Mark
                    "FF" + Util.ToHtmlColor(style.MarkerColor),                     //<Color> - Mark
                    style.LabelSizeUnits.ToString(),                                //<Unit> - Line Label
                    style.LabelFontSize.ToString(CultureInfo.InvariantCulture),     //<SizeX> - Line Label Size
                    style.LabelFontSize.ToString(CultureInfo.InvariantCulture),     //<SizeY> - Line Label Size
                    "FF" + Util.ToHtmlColor(style.LabelForeColor),                  //<ForegroundColor> - Line Label
                    "FF" + Util.ToHtmlColor(style.LabelBackColor),                  //<BackgroundColor> - Line Label
                    style.LabelBackStyle.ToString(),                                //<BackgroundStyle> - Line Label
                    style.LabelBold.ToString().ToLower(),                           //<Bold> - Line Label
                    style.LabelItalic.ToString().ToLower(),                         //<Bold> - Line Label
                    style.LabelUnderline.ToString().ToLower(),                      //<Underlined> - Line Label
                    style.LinePattern.ToString(),                                   //<LineStyle> - Line
                    style.LineThickness.ToString(CultureInfo.InvariantCulture),     //<Thickness> - Line
                    "FF" + Util.ToHtmlColor(style.LineColor),                       //<Color> - Line
                    style.LineSizeUnits.ToString(),                                 //<Unit> - Line
                    style.LabelSizeUnits.ToString(),                                //<Unit> - Polygon Label
                    style.LabelFontSize.ToString(CultureInfo.InvariantCulture),     //<SizeX> - Polygon Label Size
                    style.LabelFontSize.ToString(CultureInfo.InvariantCulture),     //<SizeY> - Polygon Label Size
                    "FF" + Util.ToHtmlColor(style.LabelForeColor),                  //<ForegroundColor> - Polygon Label
                    "FF" + Util.ToHtmlColor(style.LabelBackColor),                  //<BackgroundColor> - Polygon Label
                    style.LabelBackStyle.ToString(),                                //<BackgroundStyle> - Polygon Label
                    style.LabelBold.ToString().ToLower(),                           //<Bold> - Polygon Label
                    style.LabelItalic.ToString().ToLower(),                         //<Bold> - Polygon Label
                    style.LabelUnderline.ToString().ToLower(),                      //<Underlined> - Polygon Label
                    style.FillPattern.ToString(),                                   //<FillPattern> - Fill
                    hexFgTransparency + Util.ToHtmlColor(style.FillForeColor),      //<ForegroundColor> - Fill
                    hexBgTransparency + Util.ToHtmlColor(style.FillBackColor),      //<BackgroundColor> - Fill
                    style.BorderPattern.ToString(),                                 //<LineStyle> - Fill
                    style.BorderThickness.ToString(CultureInfo.InvariantCulture),   //<Thickness> - Fill
                    "FF" + Util.ToHtmlColor(style.BorderColor),                     //<Color> - Fill
                    style.BorderSizeUnits.ToString()                                //<Unit> - Fill
                }));
            }
            else
            {
                StringBuilder template       = new StringBuilder(Strings.markuplayerdefinition_advanced);
                double        fontHeight     = SizeInMM(style.LabelFontSize, style.LabelSizeUnits);
                string        labelForeColor = "FF" + Util.ToHtmlColor(style.LabelForeColor);
                string        labelBackColor = "FF" + Util.ToHtmlColor(style.LabelBackColor);

                //Substitute inner templates first, so their placeholders tokens are also brought in
                template.Replace("#{FILL_PATTERN_TEMPLATE}", GetFillPatternTemplate(style.FillPattern));
                template.Replace("#{BORDER_PATTERN_TEMPLATE}", GetBorderPatternGeometry(style.BorderPattern));

                //For non-opaque labels we need to empty the frame fill color
                if (style.LabelBackStyle == LabelStyle.Opaque)
                {
                    template.Replace("#{FRAME_FILL_COLOR}", "0xffffffff");
                }
                else
                {
                    template.Replace("#{FRAME_FILL_COLOR}", string.Empty);
                    if (style.LabelBackStyle == LabelStyle.Transparent)
                    {
                        labelBackColor = string.Empty;
                    }
                }

                //I don't think this is correct wrt to the UI, but this is to replicate the behaviour that we currently have under basic stylization
                //If fill is solid and background color is fully transparent, comment that portion out of the composite type style as it will interfere
                //with the area foreground symbol
                if (style.FillPattern == FillPattern.Solid && hexBgTransparency == "FF")
                {
                    template.Replace("#{START_BACKGROUND_FILL}", "<!--");
                    template.Replace("#{END_BACKGROUND_FILL}", "-->");
                }
                else
                {
                    template.Replace("#{START_BACKGROUND_FILL}", "");
                    template.Replace("#{END_BACKGROUND_FILL}", "");
                }

                //Then do a find/replace of all known tokens
                template.Replace("#{RESOURCE_ID}", fsId.ToString());
                template.Replace("#{FEATURE_CLASS}", className);
                template.Replace("#{FONT_HEIGHT}", fontHeight.ToString(CultureInfo.InvariantCulture));
                template.Replace("#{LABEL_FORE_COLOR}", labelForeColor);
                template.Replace("#{LABEL_BACK_COLOR}", labelBackColor);
                template.Replace("#{BOLD}", style.LabelBold.ToString().ToLower());
                template.Replace("#{ITALIC}", style.LabelItalic.ToString().ToLower());
                template.Replace("#{UNDERLINE}", style.LabelUnderline.ToString().ToLower());
                template.Replace("#{MARKER_GEOMETRY}", GetMarkerGeometry(style.MarkerType));
                template.Replace("#{MARKER_SIZE_X}", GetMarkerSize(style.MarkerSize, style.MarkerSizeUnits));
                template.Replace("#{MARKER_SIZE_Y}", GetMarkerSize(style.MarkerSize, style.MarkerSizeUnits));
                template.Replace("#{MARKER_COLOR}", "FF" + Util.ToHtmlColor(style.MarkerColor));
                template.Replace("#{LINE_PATTERN_GEOMETRY}", GetLinePatternGeometry(style.LinePattern));
                template.Replace("#{LINE_THICKNESS}", GetLineThickness(style.LineThickness, style.LineSizeUnits));
                template.Replace("#{LINE_COLOR}", "FF" + Util.ToHtmlColor(style.LineColor));
                template.Replace("#{FILL_BACK_COLOR}", hexBgTransparency + Util.ToHtmlColor(style.FillBackColor));
                template.Replace("#{FILL_FORE_COLOR}", hexFgTransparency + Util.ToHtmlColor(style.FillForeColor));
                template.Replace("#{BORDER_THICKNESS}", SizeInMM(style.BorderThickness, style.BorderSizeUnits).ToString(CultureInfo.InvariantCulture));
                template.Replace("#{BORDER_COLOR}", "FF" + Util.ToHtmlColor(style.BorderColor));

                //Fill in the UI values under ExtendedData, so we can read from this element if we need to go back to Edit Style UI
                template.Replace("#{MG_RESOURCE_ID}", fsId.ToString());
                template.Replace("#{MG_FEATURE_CLASS}", className);
                template.Replace("#{MG_FILL_PATTERN}", style.FillPattern.ToString());
                template.Replace("#{MG_BORDER_PATTERN}", style.BorderPattern.ToString());
                template.Replace("#{MG_LINE_PATTERN}", style.LinePattern.ToString());
                template.Replace("#{MG_LABEL_FONT_SIZE}", style.LabelFontSize.ToString(CultureInfo.InvariantCulture));
                template.Replace("#{MG_LABEL_FONT_UNITS}", style.LabelSizeUnits.ToString());
                template.Replace("#{MG_LABEL_FORECOLOR}", Util.ToHtmlColor(style.LabelForeColor));
                template.Replace("#{MG_LABEL_BACKCOLOR}", Util.ToHtmlColor(style.LabelBackColor));
                template.Replace("#{MG_BOLD}", style.LabelBold.ToString().ToLower());
                template.Replace("#{MG_ITALIC}", style.LabelItalic.ToString().ToLower());
                template.Replace("#{MG_UNDERLINE}", style.LabelUnderline.ToString().ToLower());
                template.Replace("#{MG_MARKER_TYPE}", style.MarkerType.ToString());
                template.Replace("#{MG_MARKER_SIZE}", style.MarkerSize.ToString(CultureInfo.InvariantCulture));
                template.Replace("#{MG_MARKER_UNITS}", style.MarkerSizeUnits.ToString());
                template.Replace("#{MG_MARKER_COLOR}", Util.ToHtmlColor(style.MarkerColor));
                template.Replace("#{MG_LINE_THICKNESS}", style.LineThickness.ToString(CultureInfo.InvariantCulture));
                template.Replace("#{MG_LINE_UNITS}", style.LineSizeUnits.ToString());
                template.Replace("#{MG_LINE_COLOR}", Util.ToHtmlColor(style.LineColor));
                template.Replace("#{MG_FILL_BACK_COLOR}", Util.ToHtmlColor(style.FillBackColor));
                template.Replace("#{MG_FILL_FORE_COLOR}", Util.ToHtmlColor(style.FillForeColor));
                template.Replace("#{MG_FILL_FORE_TRANSPARENCY}", hexFgTransparency);
                template.Replace("#{MG_FILL_BACK_TRANSPARENCY}", hexBgTransparency);
                template.Replace("#{MG_BORDER_THICKNESS}", style.BorderThickness.ToString(CultureInfo.InvariantCulture));
                template.Replace("#{MG_BORDER_UNITS}", style.BorderSizeUnits.ToString());
                template.Replace("#{MG_BORDER_COLOR}", Util.ToHtmlColor(style.BorderColor));
                template.Replace("#{MG_LABEL_STYLE}", style.LabelBackStyle.ToString());

                return(template.ToString());
            }
        }