Ejemplo n.º 1
0
        /// <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;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates and parses mapcss from a stream.
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public static MapCSSFile FromStream(Stream stream)
        {
            // get the text from the embedded test file.
            var    reader = new StreamReader(stream);
            string s      = reader.ReadToEnd();

            return(MapCSSFile.FromString(s));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Parses the result of the MapCSSParser into the MapCSSFile domain object.
        /// </summary>
        /// <param name="treeObject"></param>
        /// <returns></returns>
        public static MapCSSFile Parse(object treeObject)
        {
            var tree = (treeObject as Antlr.Runtime.Tree.CommonTree);

            if (tree == null)
            {
                throw new ArgumentOutOfRangeException("treeObject", 
                    "Incorrect type: Antlr.Runtime.Tree.CommonTree expected!");
            }
            if (tree.ChildCount > 0)
            {
                // create the mapcss file.
                var file = new MapCSSFile();
                
                // loop over all children.
                foreach (CommonTree child in tree.Children)
                {
                    if (child.Text == "RULE")
                    {
                        if (child.ChildCount == 2 &&
                            child.Children[0].Text == "SIMPLE_SELECTOR" &&
                            child.Children[0].ChildCount == 1 &&
                            child.Children[0] is CommonTree &&
                            (child.Children[0] as CommonTree).Children[0].Text == "canvas")
                        { // this child represents the canvas rule.
                            MapCSSDomainParser.ParseCanvasRule(file, child as CommonTree);
                        }
                        else if (child.ChildCount == 2 &&
                            child.Children[0].Text == "SIMPLE_SELECTOR" &&
                            child.Children[0].ChildCount == 1 &&
                            child.Children[0] is CommonTree &&
                            (child.Children[0] as CommonTree).Children[0].Text == "meta")
                        { // this child represents the canvas rule.
                            MapCSSDomainParser.ParseMetaRule(file, child as CommonTree);
                        }
                        else
                        { // this child can only be a regular rule.
                            Rule rule =
                                MapCSSDomainParser.ParseRule(child as CommonTree);
                            file.Rules.Add(rule);
                        }
                    }
                }

                return file;
            }
            return null;
        }
Ejemplo n.º 4
0
        /// <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;

            this.PrepareForProcessing();
        }
Ejemplo n.º 5
0
        /// <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;

            this.PrepareForProcessing();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a new MapCSS interpreter from a stream.
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="imageSource"></param>
        /// <param name="geometryInterpreter"></param>
        public MapCSSInterpreter(Stream stream, IMapCSSImageSource imageSource, GeometryInterpreter geometryInterpreter)
        {
            if (imageSource == null) throw new ArgumentNullException("imageSource");
            if (geometryInterpreter == null) throw new ArgumentNullException("geometryInterpreter");

            _mapCSSFile = MapCSSFile.FromStream(stream);
            _mapCSSImageSource = imageSource;
            _geometryInterpreter = geometryInterpreter;
        }
Ejemplo n.º 7
0
        /// <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;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a new MapCSS interpreter from a string.
        /// </summary>
        /// <param name="css"></param>
        /// <param name="imageSource"></param>
        public MapCSSInterpreter(string css, IMapCSSImageSource imageSource)
        {
            if (imageSource == null) throw new ArgumentNullException("imageSource");

            _mapCSSFile = MapCSSFile.FromString(css);
            _mapCSSImageSource = imageSource;
            _geometryInterpreter = GeometryInterpreter.DefaultInterpreter;
        }
Ejemplo n.º 9
0
        /// <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 = FeatureInterpreter.DefaultInterpreter;

            this.PrepareForProcessing();
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Parses the canvas rule.
 /// </summary>
 /// <param name="ruleTree"></param>
 /// <returns></returns>
 private static void ParseCanvasRule(MapCSSFile file, CommonTree ruleTree)
 {
     if (ruleTree.ChildCount >= 2 &&
         ruleTree.Children[1] != null)
     { // loop over all declaration rules in canvas.
         foreach (CommonTree rule in (ruleTree.Children[1] as CommonTree).Children)
         {
             if (rule.Text == "DECLARATION" &&
                 rule.Children != null &&
                 rule.Children.Count > 0)
             { // parse the decalaration.
                 // support both JOSM's background-color and fill-color.
                 if (rule.Children[0].Text == "background-color")
                 { // parse the background color.
                     file.CanvasFillColor = MapCSSDomainParser.ParseColor(rule.Children[1] as CommonTree);
                 }
                 else if (rule.Children[0].Text == "fill-color")
                 { // parse the background color.
                     file.CanvasFillColor = MapCSSDomainParser.ParseColor(rule.Children[1] as CommonTree);
                 }
                 else if (rule.Children[0].Text == "default-points")
                 { // parse the default points-setting.
                     file.DefaultPoints = false;
                     if(rule.Children[1].Text == "true")
                     {
                         file.DefaultPoints = true;
                     }
                 }
                 else if (rule.Children[0].Text == "default-lines")
                 { // parse the default lines-setting.
                     file.DefaultLines = false;
                     if (rule.Children[1].Text == "true")
                     {
                         file.DefaultLines = true;
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Parses the meta rule.
 /// </summary>
 /// <param name="ruleTree"></param>
 /// <returns></returns>
 private static void ParseMetaRule(MapCSSFile file, CommonTree ruleTree)
 {
     if (ruleTree.ChildCount >= 2 &&
         ruleTree.Children[1] != null)
     { // loop over all declaration rules in canvas.
         foreach (CommonTree rule in (ruleTree.Children[1] as CommonTree).Children)
         {
             if (rule.Text == "DECLARATION" &&
                 rule.Children != null &&
                 rule.Children.Count > 0)
             { // parse the decalaration.
                 if (rule.Children[0].Text == "title")
                 { // parse the background color.
                     file.Title = MapCSSDomainParser.ParseURL(rule.Children[1].Text);
                 }
                 else if (rule.Children[0].Text == "icon")
                 { // parse the default points-setting.
                     file.Icon = MapCSSDomainParser.ParseURL(rule.Children[1].Text);
                 }
             }
         }
     }
 }