Ejemplo n.º 1
0
        public void ParseElevationSample()
        {
            string expression = @"name ++ ""sdsd"" ++ ele ""($1f $elevation)""";

            LabelExpressionParser parser           = new LabelExpressionParser();
            LabelExpression       parsedExpression = parser.Parse(expression, 0);

            int i = 0;

            Assert.IsInstanceOfType(typeof(OsmKeyLabelExpressionElement), parsedExpression.Elements [i]);
            OsmKeyLabelExpressionElement osmKeyLabelExpressionElement = (OsmKeyLabelExpressionElement)parsedExpression.Elements[i++];

            Assert.AreEqual("name", osmKeyLabelExpressionElement.KeyName);
            Assert.IsNull(osmKeyLabelExpressionElement.ConditionalElement);

            Assert.IsInstanceOfType(typeof(FormatLabelExpressionElement), parsedExpression.Elements [i]);
            FormatLabelExpressionElement formatLabelExpressionElement = (FormatLabelExpressionElement)parsedExpression.Elements[i++];

            Assert.AreEqual("sdsd", formatLabelExpressionElement.Format);

            Assert.IsInstanceOfType(typeof(OsmKeyLabelExpressionElement), parsedExpression.Elements [i]);
            osmKeyLabelExpressionElement = (OsmKeyLabelExpressionElement)parsedExpression.Elements[i++];
            Assert.AreEqual("ele", osmKeyLabelExpressionElement.KeyName);
            Assert.IsInstanceOfType(typeof(FormatLabelExpressionElement), osmKeyLabelExpressionElement.ConditionalElement);
            formatLabelExpressionElement = (FormatLabelExpressionElement)osmKeyLabelExpressionElement.ConditionalElement;
            Assert.AreEqual("($1f $elevation)", formatLabelExpressionElement.Format);
        }
Ejemplo n.º 2
0
        public void ParseValidExamples(string expression, int expectedElementsCount)
        {
            LabelExpressionParser parser           = new LabelExpressionParser();
            LabelExpression       parsedExpression = parser.Parse(expression, 0);

            Assert.AreEqual(expectedElementsCount, parsedExpression.ElementsCount);
        }
Ejemplo n.º 3
0
        public void ParseRelationLabel()
        {
            string expression = @"relation:name";

            LabelExpressionParser parser           = new LabelExpressionParser();
            LabelExpression       parsedExpression = parser.Parse(expression, 0);

            int i = 0;

            Assert.IsInstanceOfType(typeof(OsmKeyLabelExpressionElement), parsedExpression.Elements[i]);
            OsmKeyLabelExpressionElement osmKeyLabelExpressionElement = (OsmKeyLabelExpressionElement)parsedExpression.Elements[i++];

            Assert.AreEqual("relation:name", osmKeyLabelExpressionElement.KeyName);
            Assert.IsNull(osmKeyLabelExpressionElement.ConditionalElement);
        }
Ejemplo n.º 4
0
        public void BuildLabelWithRelationTagsAndConditionals()
        {
            const string expression = @"relation:name ""blabla""";

            LabelExpressionParser parser           = new LabelExpressionParser();
            LabelExpression       parsedExpression = parser.Parse(expression, 0);

            OsmObjectMother mother = new OsmObjectMother();

            mother
            .AddRelation();

            MapMakerSettings mapMakerSettings = new MapMakerSettings();
            string           label            = parsedExpression.BuildLabel(mapMakerSettings, mother.CurrentObject, mother.CurrentRelation);

            Assert.AreEqual(String.Empty, label);
        }
Ejemplo n.º 5
0
        public void BuildVariousLabels(string labelExpression, string expectedLabel)
        {
            LabelExpressionParser parser           = new LabelExpressionParser();
            LabelExpression       parsedExpression = parser.Parse(labelExpression, 0);

            OsmObjectMother mother = new OsmObjectMother();

            mother
            .AddRelation()
            .Tag("name", "Relation")
            .AddWay(5)
            .Tag("name", "Way")
            .AddToRelation("friend");

            MapMakerSettings mapMakerSettings = new MapMakerSettings();
            string           label            = parsedExpression.BuildLabel(mapMakerSettings, mother.CurrentObject, mother.CurrentRelation);

            Assert.AreEqual(expectedLabel, label);
        }
Ejemplo n.º 6
0
        public void BuildElevationSample()
        {
            MapMakerSettings mapMakerSettings = new MapMakerSettings();

            mapMakerSettings.CharactersConversionDictionary.AddConversion('Č', "C");
            mapMakerSettings.CharactersConversionDictionary.AddConversion('č', "c");

            const string expression = @"name ++ "" sdsd"" ++ ele "" ($1f$elevation)""";

            LabelExpressionParser parser           = new LabelExpressionParser();
            LabelExpression       parsedExpression = parser.Parse(expression, 0);

            OsmNode osmNode = new OsmNode(1, 10, 10);

            osmNode.SetTag("name", "Veliki vrh Čačka");
            osmNode.SetTag("ele", "1433");

            string label = parsedExpression.BuildLabel(mapMakerSettings, osmNode, null);

            Assert.AreEqual("Veliki vrh Cacka sdsd (~[0x1f]1433)", label);
        }
Ejemplo n.º 7
0
        public void BuildLabelWithRelationTags()
        {
            const string expression = @"relation:name ++ name";

            LabelExpressionParser parser           = new LabelExpressionParser();
            LabelExpression       parsedExpression = parser.Parse(expression, 0);

            OsmObjectMother mother = new OsmObjectMother();

            mother
            .AddRelation()
            .Tag("name", "My name is Relation")
            .AddWay(5)
            .Tag("name", "My name is Way")
            .AddToRelation("friend");

            MapMakerSettings mapMakerSettings = new MapMakerSettings();
            string           label            = parsedExpression.BuildLabel(mapMakerSettings, mother.CurrentObject, mother.CurrentRelation);

            Assert.AreEqual("My name is RelationMy name is Way", label);
        }
Ejemplo n.º 8
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;
        }
Ejemplo n.º 9
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;
        }