Пример #1
0
        public void CanParse()
        {
            // ARRANGE
            var provider = new StylesheetProvider(TestHelper.TestBaseMapcssFile, TestHelper.GetFileSystemService());

            // ACT & ASSERT
            var stylesheet = provider.Get();

            Assert.AreEqual(9, stylesheet.Count);

            var testStyle1 = MapCssHelper.GetStyles(stylesheet)[1];

            Assert.AreEqual(2, testStyle1.Selectors.Count);
            Assert.AreEqual(7, testStyle1.Declarations.Count);

            var testSelector1 = testStyle1.Selectors.First();

            Assert.AreEqual("man_made", testSelector1.Tag);
            Assert.AreEqual("tower", testSelector1.Value);
            Assert.AreEqual("=", testSelector1.Operation);

            var testSelector2 = testStyle1.Selectors.Last();

            Assert.AreEqual("building", testSelector2.Tag);
            Assert.AreEqual("OP_EXIST", testSelector2.Operation);

            var lastStyle = MapCssHelper.GetStyles(stylesheet)[7];

            Assert.AreEqual(2, lastStyle.Selectors.Count);
            Assert.AreEqual(1, lastStyle.Declarations.Count);
        }
Пример #2
0
        public void CanUseCanvas(string path, bool canUseExprTree)
        {
            // ARRANGE
            var stylesheet = MapCssHelper.GetStylesheetFromFile(path, canUseExprTree);
            var canvas     = new Canvas(TestHelper.GetObjectPool());

            // ACT
            var rule     = stylesheet.GetModelRule(canvas, MapConsts.MaxZoomLevel);
            var material = rule.Evaluate <string>("material");

            // ASSERT
            Assert.AreEqual("Terrain", material);
        }
Пример #3
0
        public void CanUseNode(bool canUseExprTree)
        {
            // ARRANGE
            var stylesheet = MapCssHelper.GetStylesheetFromContent("node[test] { z-index: 0.1}\n", canUseExprTree);

            // ACT
            var node = MapCssHelper.GetNode(new Dictionary <string, string>()
            {
                { "test", "yes" },
            }.ToTags());

            // ASSERT
            Assert.IsTrue(stylesheet.GetModelRule(node, MapConsts.MaxZoomLevel).IsApplicable);
        }
Пример #4
0
        public void CanUseZoomLevel(string zoomStr, int start, int end, int currentZoomLevel, bool expectedResult)
        {
            // ARRANGE
            var stylesheet = MapCssHelper.GetStylesheetFromContent(
                String.Format("area|{0}[level>0] {{ z-index: 0.1}}\n", zoomStr));

            var area = MapCssHelper.GetArea(new Dictionary <string, string>()
            {
                { "level", "1" }
            }.ToTags());

            // ACT
            var rule = stylesheet.GetModelRule(area, currentZoomLevel);

            // ASSERT
            Assert.IsTrue(rule.IsApplicable == expectedResult);
        }
Пример #5
0
        public void CanUseLess()
        {
            // ARRANGE
            var stylesheet = MapCssHelper.GetStylesheetFromContent("area[level<0] { z-index: 0.1}\n");

            // ACT
            var area1 = MapCssHelper.GetArea(new Dictionary <string, string>()
            {
                { "level", "-1" }
            }.ToTags());
            var area2 = MapCssHelper.GetArea(new Dictionary <string, string>()
            {
                { "level", "1" }
            }.ToTags());

            // ASSERT
            Assert.IsTrue(stylesheet.GetModelRule(area1, MapConsts.MaxZoomLevel).IsApplicable);
            Assert.IsFalse(stylesheet.GetModelRule(area2, MapConsts.MaxZoomLevel).IsApplicable);
        }
Пример #6
0
        public void CanUseNotEqual()
        {
            // ARRANGE
            var stylesheet = MapCssHelper.GetStylesheetFromContent("area[landuse!=forest] { z-index: 0.1}\n");

            // ACT
            var area1 = MapCssHelper.GetArea(new Dictionary <string, string>()
            {
                { "landuse", "forest" }
            }.ToTags());
            var area2 = MapCssHelper.GetArea(new Dictionary <string, string>()
            {
                { "landuse", "grass" }
            }.ToTags());

            // ASSERT
            Assert.IsFalse(stylesheet.GetModelRule(area1, MapConsts.MaxZoomLevel).IsApplicable);
            Assert.IsTrue(stylesheet.GetModelRule(area2, MapConsts.MaxZoomLevel).IsApplicable);
        }
Пример #7
0
        public void CanUseSingleValueInList(bool canUseExprTree)
        {
            // ARRANGE
            var stylesheet = MapCssHelper.GetStylesheetFromContent(
                "area[building] { behaviours:test1; non-important:test}", canUseExprTree);
            var building = MapCssHelper.GetArea(new Dictionary <string, string>()
            {
                { "building", "commercial" },
            }.ToTags());
            var rule = stylesheet.GetModelRule(building, MapConsts.MaxZoomLevel);

            // ACT
            var behaviours = rule.EvaluateList <string>("behaviours");

            // ASSERT
            var list = behaviours.ToList();

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual("test1", list[0]);
        }
Пример #8
0
        public void CanUseGradient()
        {
            // ARRANGE
            const string gradientString = "gradient(#f4f4f4, yellow 10%, green 20%)";
            var          stylesheet     = MapCssHelper
                                          .GetStylesheetFromContent(String.Format("node[test] {{ facade: {0};}}\n", gradientString));

            // ACT
            var node = MapCssHelper.GetNode(new Dictionary <string, string>()
            {
                { "test", "yes" },
            }.ToTags());

            // ASSERT
            var rule           = stylesheet.GetModelRule(node, MapConsts.MaxZoomLevel);
            var facadeGradient = rule.Evaluate <string>("facade");

            Assert.IsNotEmpty(facadeGradient);
            Assert.AreEqual(gradientString, facadeGradient);
        }
Пример #9
0
        public void CanEvaluateGradient()
        {
            // ARRANGE
            var stylesheet = MapCssHelper
                             .GetStylesheetFromContent(String.Format("node[test] {{ facade: eval(gradient(tag('colour')));}}\n"));

            // ACT
            var node = MapCssHelper.GetNode(new Dictionary <string, string>()
            {
                { "test", "yes" },
                { "colour", "#0fff8f" },
            }.ToTags());

            // ASSERT
            var rule           = stylesheet.GetModelRule(node, MapConsts.MaxZoomLevel);
            var facadeGradient = rule.Evaluate <string>("facade");

            Assert.IsNotEmpty(facadeGradient);
            Assert.AreEqual("gradient(#0fff8f, #0fff8f 50%, #099956)", facadeGradient);
        }
Пример #10
0
        public void CanUseAndSelectors(bool canUseExprTree)
        {
            // ARRANGE
            var stylesheet = MapCssHelper.GetStylesheetFromContent("way[waterway][name],way[waterway] { z-index: 0.1}\n", canUseExprTree);

            // ACT
            var way1 = MapCssHelper.GetWay(
                new Dictionary <string, string>()
            {
                { "waterway", "river" },
                { "name", "spree" }
            }.ToTags());
            var way2 = MapCssHelper.GetWay(new Dictionary <string, string>()
            {
                { "name", "some name" }
            }.ToTags());

            // ASSERT
            Assert.IsTrue(stylesheet.GetModelRule(way1, MapConsts.MaxZoomLevel).IsApplicable);
            Assert.IsFalse(stylesheet.GetModelRule(way2, MapConsts.MaxZoomLevel).IsApplicable);
        }
Пример #11
0
        public void CanGetMissing(string path, bool canUseExprTree)
        {
            // ARRANGE
            var stylesheet = MapCssHelper.GetStylesheetFromFile(path, canUseExprTree);

            var area = new Area
            {
                Id     = 1,
                Points = new List <GeoCoordinate>(),
                Tags   = new Dictionary <string, string>()
                {
                    { "building", "residential" },
                }.ToTags()
            };

            // ACT
            var rule = stylesheet.GetModelRule(area, MapConsts.MaxZoomLevel);

            // ASSERT
            Assert.AreEqual(0, rule.GetLevels());
        }
Пример #12
0
        public void CanUseSimpleEvaluate(string path, bool canUseExprTree)
        {
            // ARRANGE
            var model = new Area
            {
                Id   = 1,
                Tags = new Dictionary <string, string>()
                {
                    { "building:levels", "5" }
                }.ToTags()
            };

            var stylesheet      = MapCssHelper.GetStylesheetFromFile(path, canUseExprTree);
            var evalDeclaration = MapCssHelper.GetStyles(stylesheet)[3].Declarations.First();

            // ACT
            var evalResult = evalDeclaration.Value.Evaluator.Walk <float>(model);

            // ASSERT
            Assert.AreEqual(15, evalResult);
        }
Пример #13
0
        public void CanGetColorByName(string path, bool canUseExprTree)
        {
            // ARRANGE
            var stylesheet = MapCssHelper.GetStylesheetFromFile(path, canUseExprTree);

            var buildingWithColorName = new Area
            {
                Id     = 1,
                Points = new List <GeoCoordinate>(),
                Tags   = new Dictionary <string, string>()
                {
                    { "building", "yes" },
                }.ToTags()
            };

            // ACT
            var rule = stylesheet.GetModelRule(buildingWithColorName, MapConsts.MaxZoomLevel);

            // ASSERT
            Assert.AreEqual(ColorUtils.FromName("salmon"),
                            GetOriginalColorTypeObject(rule.GetFillUnityColor()));
        }
Пример #14
0
        public void CanPerformSimpleOperationWithTags(bool canUseExprTree)
        {
            // ARRANGE
            var model = new Area
            {
                Id   = 1,
                Tags = new Dictionary <string, string>()
                {
                    { "building:height", "20" },
                    { "roof:height", "5" },
                }.ToTags()
            };

            var stylesheet = MapCssHelper.GetStylesheetFromContent("area[building:height][roof:height] { height: eval(num(tag('building:height')) - num(tag('roof:height')));}\n", canUseExprTree);
            var rule       = stylesheet.GetModelRule(model, MapConsts.MaxZoomLevel);

            // ACT
            var evalResult = rule.GetHeight();

            // ASSERT
            Assert.AreEqual(15, evalResult);
        }
Пример #15
0
        public void CanMergeDeclarations(string path, bool canUseExprTree)
        {
            // ARRANGE
            var stylesheet = MapCssHelper.GetStylesheetFromFile(path, canUseExprTree);

            var area = new Area
            {
                Id     = 1,
                Points = new List <GeoCoordinate>()
                {
                    new GeoCoordinate(52.5212186, 13.4096926),
                    new GeoCoordinate(52.5210184, 13.4097473),
                    new GeoCoordinate(52.5209891, 13.4097538),
                    new GeoCoordinate(52.5209766, 13.4098037)
                },
                Tags = new Dictionary <string, string>()
                {
                    { "building", "residential" },
                    { "building:shape", "sphere" },
                    { "min_height", "100" },
                    { "building:levels", "5" },
                }.ToTags()
            };

            // ACT
            var rule = stylesheet.GetModelRule(area, MapConsts.MaxZoomLevel);


            // ASSERT
            Assert.IsTrue(rule.IsApplicable, "Unable to get declarations!");

            Assert.AreEqual("sphere", rule.Evaluate <string>("builder"), "Unable to merge declarations!");
            Assert.AreEqual(100, rule.Evaluate <float>("min_height"), "Unable to eval min_height from tag!");
            Assert.AreEqual(new Color32(250, 128, 114, 255), rule.GetFillUnityColor(), "Unable to merge declarations!");
            Assert.AreEqual("solid", rule.Evaluate <string>("behaviour"), "First rule isn't applied!");
            Assert.AreEqual("Concrete_Patterned", rule.Evaluate <string>("material"), "First rule isn't applied!");
            Assert.AreEqual(15, rule.Evaluate <float>("height"), "Unable to eval height from building:levels!");
        }
Пример #16
0
        public void CanApplyColorByRGB(string path, bool canUseExprTree)
        {
            // ARRANGE
            var stylesheet = MapCssHelper.GetStylesheetFromContent("area[building:color] { fill-color:eval(color(tag('building:color')));}", canUseExprTree);

            var buildingWithColorCode = new Area
            {
                Id     = 1,
                Points = new List <GeoCoordinate>(),
                Tags   = new Dictionary <string, string>()
                {
                    { "building", "commercial" },
                    { "building:color", "#cfc6b5" }
                }.ToTags()
            };

            // ACT
            var rule = stylesheet.GetModelRule(buildingWithColorCode, MapConsts.MaxZoomLevel);

            // ASSERT
            Assert.AreEqual(ColorUtils.FromUnknown("#cfc6b5"),
                            GetOriginalColorTypeObject(rule.GetFillUnityColor()));
        }