public void TestDomainColorNamed() { // parses the MapCSS. AstParserRuleReturnScope <object, IToken> result = this.TestMapCSSParsing( "OsmSharp.UI.Unittests.Data.MapCSS.color-named.mapcss"); // Test the very minimum; no errors during parsing says a lot already! var tree = result.Tree as Antlr.Runtime.Tree.CommonTree; Assert.NotNull(tree); Assert.AreEqual(2, tree.ChildCount); // parse into domain. MapCSSFile file = MapCSSDomainParser.Parse(tree); Assert.IsNotNull(file); Assert.AreEqual(1, file.Rules.Count); Assert.AreEqual(1, file.Rules[0].Declarations.Count); Assert.IsInstanceOf(typeof(DeclarationInt), file.Rules[0].Declarations[0]); // get color declaration. var declarationInt = file.Rules[0].Declarations[0] as DeclarationInt; Assert.IsNotNull(declarationInt); Assert.AreEqual(DeclarationIntEnum.Color, declarationInt.Qualifier); // instantiate color. var simpleColor = new SimpleColor(); simpleColor.Value = declarationInt.Eval((MapCSSObject)null); Assert.AreEqual("#FFFFFF", simpleColor.HexRgb); }
public void TestMetaSettingsCSS() { // create CSS. string css = "meta { " + " title: \"Parking lanes\"; /* title shown in the menu */ " + " icon: \"images/logo.png\"; /* small icon shown in the menu next to the title */ " + "} "; // parses the MapCSS. AstParserRuleReturnScope <object, IToken> result = this.TestMapCSSParsingString(css); // Test the very minimum; no errors during parsing says a lot already! var tree = result.Tree as Antlr.Runtime.Tree.CommonTree; Assert.NotNull(tree); Assert.AreEqual(1, tree.ChildCount); // parse into domain. MapCSSFile file = MapCSSDomainParser.Parse(tree); Assert.IsNotNull(file); Assert.AreEqual(0, file.Rules.Count); Assert.AreEqual("Parking lanes", file.Title); Assert.AreEqual("images/logo.png", file.Icon); }
/// <summary> /// Creates a new MapCSS interpreter from a stream. /// </summary> /// <param name="stream"></param> /// <param name="imageSource"></param> public MapCSSInterpreter(Stream stream, IMapCSSImageSource imageSource) { if (imageSource == null) { throw new ArgumentNullException("imageSource"); } _mapCSSFile = MapCSSFile.FromStream(stream); _mapCSSImageSource = imageSource; _geometryInterpreter = GeometryInterpreter.DefaultInterpreter; }
/// <summary> /// Creates a new MapCSS interpreter. /// </summary> /// <param name="mapCSSFile"></param> /// <param name="imageSource"></param> public MapCSSInterpreter(MapCSSFile mapCSSFile, IMapCSSImageSource imageSource) { if (imageSource == null) { throw new ArgumentNullException("imageSource"); } _mapCSSFile = mapCSSFile; _mapCSSImageSource = imageSource; _geometryInterpreter = GeometryInterpreter.DefaultInterpreter; }
/// <summary> /// Creates a new MapCSS interpreter from a string. /// </summary> /// <param name="css"></param> /// <param name="imageSource"></param> /// <param name="geometryInterpreter"></param> public MapCSSInterpreter(string css, IMapCSSImageSource imageSource, GeometryInterpreter geometryInterpreter) { if (imageSource == null) { throw new ArgumentNullException("imageSource"); } if (geometryInterpreter == null) { throw new ArgumentNullException("geometryInterpreter"); } _mapCSSFile = MapCSSFile.FromString(css); _mapCSSImageSource = imageSource; _geometryInterpreter = geometryInterpreter; }
/// <summary> /// Creates a new MapCSS interpreter. /// </summary> /// <param name="mapCSSFile"></param> /// <param name="imageSource"></param> /// <param name="geometryInterpreter"></param> public MapCSSInterpreter(MapCSSFile mapCSSFile, IMapCSSImageSource imageSource, GeometryInterpreter geometryInterpreter) { if (imageSource == null) { throw new ArgumentNullException("imageSource"); } if (geometryInterpreter == null) { throw new ArgumentNullException("geometryInterpreter"); } _mapCSSFile = mapCSSFile; _mapCSSImageSource = imageSource; _geometryInterpreter = geometryInterpreter; }
public void TestDomainDefault() { // parses the MapCSS. AstParserRuleReturnScope <object, IToken> result = this.TestMapCSSParsing( "OsmSharp.UI.Unittests.Data.MapCSS.default.mapcss"); // Test the very minimum; no errors during parsing says a lot already! var tree = result.Tree as Antlr.Runtime.Tree.CommonTree; Assert.NotNull(tree); Assert.AreEqual(54, tree.ChildCount); // parse into domain. MapCSSFile file = MapCSSDomainParser.Parse(tree); Assert.IsNotNull(file); }
public MapCSSVectorTileStyler(Stream stream) { var _mapCSSFile = MapCSSFile.FromStream(stream); _keysForNodes = new HashSet <string>(); _keysForWays = new HashSet <string>(); _keysForRelations = new HashSet <string>(); _keysForLines = new HashSet <string>(); _keysForAreas = new HashSet <string>(); if (_mapCSSFile != null && _mapCSSFile.Rules != null) { foreach (var rule in _mapCSSFile.Rules) { foreach (var selector in rule.Selectors) { if (selector.SelectorRule == null) { // there is no selector rule, not irrelevant tags, no short-list of relevant tags possible. switch (selector.Type) { case SelectorTypeEnum.Node: _keysForNodes = null; break; case SelectorTypeEnum.Way: _keysForWays = null; break; case SelectorTypeEnum.Relation: _keysForRelations = null; break; case SelectorTypeEnum.Line: _keysForLines = null; break; case SelectorTypeEnum.Area: _keysForAreas = null; break; } } else { // there might be relevant tags in this selector rule. switch (selector.Type) { case SelectorTypeEnum.Node: selector.SelectorRule.AddRelevantKeysTo(_keysForNodes); break; case SelectorTypeEnum.Way: selector.SelectorRule.AddRelevantKeysTo(_keysForWays); break; case SelectorTypeEnum.Relation: selector.SelectorRule.AddRelevantKeysTo(_keysForRelations); break; case SelectorTypeEnum.Line: selector.SelectorRule.AddRelevantKeysTo(_keysForLines); break; case SelectorTypeEnum.Area: selector.SelectorRule.AddRelevantKeysTo(_keysForAreas); break; } } } } } _unsuccesfullWays = new HashSet <TagsCollectionBase>(); _succesfullWays = new Dictionary <TagsCollectionBase, List <MapCSSRuleProperties> >(); }