Пример #1
0
        public override void RegisterType(
            string ruleName,
            TypesRegistry typesRegistry,
            bool insertAsFirst)
        {
            // if the type was already registered, skip it
            if (typesRegistry.LineTypeRegistrations.ContainsKey(ruleName))
            {
                return;
            }

            LineTypeRegistration typeRegistration;

            string typeName = null;

            if (Style.HasParameter("typename"))
            {
                typeName = Style.GetParameter("typename");
            }
            else
            {
                typeName = Style.GetParameter("rulename");
            }

            // is it a standard Garmin type?
            if (typesRegistry.GarminLineTypesDictionary.HasType(typeName))
            {
                int standardType = typesRegistry.GarminLineTypesDictionary.GetType(typeName);
                typeRegistration = typesRegistry.RegisterStandardLineType(standardType, ruleName);
            }
            else
            {
                typeRegistration          = typesRegistry.RegisterNewLineType(ruleName);
                typeRegistration.TypeName = typeName;
            }

            IList <string> colors = Style.GetParameter <IList <string> > ("colors");

            foreach (string color in colors)
            {
                typeRegistration.Pattern.AddColor(color);
            }

            typeRegistration.Width       = Style.GetParameter <int> ("width", 2);
            typeRegistration.BorderWidth = Style.GetParameter <int> ("borderwidth", 0);

            if (Style.HasParameter("pattern"))
            {
                string   pattern      = Style.GetParameter("pattern");
                string[] patternLines = pattern.Split('|');

                foreach (string patternLine in patternLines)
                {
                    typeRegistration.Pattern.PatternLines.Add(patternLine);
                }
            }

            if (Style.HasParameter("label"))
            {
                LabelExpressionParser labelExpressionParser = new LabelExpressionParser();
                typeRegistration.Label = labelExpressionParser.Parse(Style.GetParameter("label"), 0);
            }

            typeRegistration.MinLevel = Math.Max(12, Style.MinZoomFactor);
            typeRegistration.MaxLevel = Math.Min(24, Style.MaxZoomFactor);

            this.TypeRegistration = typeRegistration;
        }
Пример #2
0
        public override void RegisterType(
            string ruleName,
            TypesRegistry typesRegistry,
            bool insertAsFirst)
        {
            // if the type was already registered, skip it
            if (typesRegistry.PointTypeRegistrations.ContainsKey(ruleName))
            {
                return;
            }

            PointTypeRegistration typeRegistration;

            string typeName = null;

            if (Style.HasParameter("typename"))
            {
                typeName = Style.GetParameter("typename");
            }
            else
            {
                typeName = Style.GetParameter("rulename");
            }

            // is it a standard Garmin type?
            if (typesRegistry.GarminPointTypesDictionary.HasType(typeName))
            {
                int standardType = typesRegistry.GarminPointTypesDictionary.GetType(typeName);
                typeRegistration = typesRegistry.RegisterStandardPointType(standardType, ruleName);
            }
            else
            {
                typeRegistration          = typesRegistry.RegisterNewPointType(ruleName);
                typeRegistration.TypeName = typeName;
            }

            if (Style.HasParameter("iconurl"))
            {
                string    iconUrl   = Style.GetParameter("iconurl");
                WebClient webClient = new WebClient();
                byte[]    imageData = webClient.DownloadData(iconUrl);

                MemoryStream memoryStream = new MemoryStream(imageData);
                Bitmap       iconImage    = (Bitmap)Bitmap.FromStream(memoryStream);

                Dictionary <int, int> colorsIndexed = new Dictionary <int, int>();

                for (int y = 0; y < iconImage.Height; y++)
                {
                    StringBuilder patternLine = new StringBuilder();

                    for (int x = 0; x < iconImage.Width; x++)
                    {
                        Color color      = iconImage.GetPixel(x, y);
                        int   colorRgb   = color.ToArgb();
                        int   colorIndex = 0;

                        // if we found a new color
                        if (false == colorsIndexed.ContainsKey(colorRgb))
                        {
                            typeRegistration.Pattern.AddColor((colorRgb & 0xffffff).ToString("x", CultureInfo.InvariantCulture));
                            colorsIndexed.Add(colorRgb, colorsIndexed.Count);
                        }

                        colorIndex = colorsIndexed[colorRgb];
                        patternLine.Append(colorIndex);
                    }

                    typeRegistration.Pattern.PatternLines.Add(patternLine.ToString());
                }
            }
            else if (Style.HasParameter("patternurl"))
            {
                Match match = regexWikiLink.Match(Style.GetParameter("patternurl"));

                typeRegistration.Pattern = typesRegistry.GetPattern(match.Groups["patternname"].Value);
            }

            if (Style.HasParameter("label"))
            {
                LabelExpressionParser labelExpressionParser = new LabelExpressionParser();
                typeRegistration.Label = labelExpressionParser.Parse(Style.GetParameter("label"), 0);
            }

            typeRegistration.MinLevel = Math.Max(12, Style.MinZoomFactor);
            typeRegistration.MaxLevel = Math.Min(24, Style.MaxZoomFactor);

            this.TypeRegistration = typeRegistration;
        }