Esempio n. 1
0
        /// <summary>
        /// Adds a new style and returns it's index.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="layer"></param>
        /// <returns></returns>
        public ushort AddStyle(Text2D text, int layer)
        {
            Text2DStyle newStyle = Text2DStyle.From(text, layer);
            int         indexOf  = this.TextStyles.IndexOf(newStyle);

            if (indexOf < 0)
            { // the style is not found yet.
                indexOf = this.TextStyles.Count;
                this.TextStyles.Add(newStyle);
            }
            return((ushort)indexOf);
        }
Esempio n. 2
0
        /// <summary>
        /// Extracts style information.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="layer"></param>
        /// <returns></returns>
        public static Text2DStyle From(Text2D text, int layer)
        {
            Text2DStyle newStyle = new Text2DStyle();

            newStyle.Color      = text.Color;
            newStyle.MaxZoom    = text.MaxZoom;
            newStyle.MinZoom    = text.MinZoom;
            newStyle.HaloColor  = text.HaloColor;
            newStyle.HaloRadius = text.HaloRadius;
            newStyle.Size       = text.Size;
            newStyle.Layer      = layer;
            newStyle.Font       = text.Font;
            return(newStyle);
        }
        /// <summary>
        /// Converts a basic entry into a scene object.
        /// </summary>
        /// <param name="style"></param>
        /// <returns></returns>
        internal Text2D To(Text2DStyle style)
        {
            Text2D text = new Text2D();

            text.Color      = style.Color;
            text.HaloColor  = style.HaloColor;
            text.HaloRadius = style.HaloRadius;
            text.MaxZoom    = style.MaxZoom;
            text.MinZoom    = style.MinZoom;
            text.Size       = style.Size;

            text.Text = this.Text;
            text.X    = this.X;
            text.Y    = this.Y;
            return(text);
        }
Esempio n. 4
0
        /// <summary>
        /// Determines whether the the given object is equal to the current object.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (!(obj is Polygon2DStyle))
            { // wrong type.
                return(false);
            }
            Text2DStyle other = (obj as Text2DStyle);

            return(this.Layer == other.Layer &
                   this.MaxZoom == other.MaxZoom &
                   this.MinZoom == other.MinZoom &
                   this.Color == other.Color &
                   this.Layer == other.Layer &
                   this.HaloColor == other.HaloColor &
                   this.HaloRadius == other.HaloRadius &
                   this.Size == other.Size);
        }
 /// <summary>
 /// Extracts style information.
 /// </summary>
 /// <param name="text"></param>
 /// <param name="layer"></param>
 /// <returns></returns>
 public static Text2DStyle From(Text2D text, int layer)
 {
     Text2DStyle newStyle = new Text2DStyle();
     newStyle.Color = text.Color;
     newStyle.MaxZoom = text.MaxZoom;
     newStyle.MinZoom = text.MinZoom;
     newStyle.HaloColor = text.HaloColor;
     newStyle.HaloRadius = text.HaloRadius;
     newStyle.Size = text.Size;
     newStyle.Layer = layer;
     newStyle.Font = text.Font;
     return newStyle;
 }
        /// <summary>
        /// Deserializes the actual data.
        /// </summary>
        /// <param name="typeModel"></param>
        /// <param name="data"></param>
        /// <param name="boxes"></param>
        /// <returns></returns>
        protected override List <Scene2DEntry> DeSerialize(RuntimeTypeModel typeModel, byte[] data,
                                                           out List <BoxF2D> boxes)
        {
            // decompress if needed.
            Stream stream = null;

            if (_compress)
            {
                stream = new GZipStream(new MemoryStream(data), CompressionMode.Decompress);
            }
            else
            { // uncompressed stream.
                stream = new MemoryStream(data);
            }

            // create the memory stream.
            var collection = typeModel.Deserialize(stream, null,
                                                   typeof(PrimitivesCollection)) as PrimitivesCollection;

            if (collection == null)
            {
                throw new Exception("Could not deserialize primitives.");
            }

            // create the collection
            var primitives = new List <Scene2DEntry>();

            if (collection.Icons != null)
            {
                foreach (var primitive in collection.Icons)
                {
                    Icon2DStyle style = _styleIndex.IconStyles[primitive.StyleId];
                    Icon2D      icon  = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = icon
                    });
                }
            }
            if (collection.Images != null)
            {
                foreach (var primitive in collection.Images)
                {
                    Image2DStyle style = _styleIndex.ImageStyles[primitive.StyleId];
                    Image2D      image = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = image
                    });
                }
            }
            if (collection.Lines != null)
            {
                foreach (var primitive in collection.Lines)
                {
                    Line2DStyle style = _styleIndex.LineStyles[primitive.StyleId];
                    Line2D      line  = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = line
                    });
                }
            }
            if (collection.Points != null)
            {
                foreach (var primitive in collection.Points)
                {
                    Point2DStyle style = _styleIndex.PointStyles[primitive.StyleId];
                    Point2D      point = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = point
                    });
                }
            }
            if (collection.Polygons != null)
            {
                foreach (var primitive in collection.Polygons)
                {
                    Polygon2DStyle style   = _styleIndex.PolygonStyles[primitive.StyleId];
                    Polygon2D      polygon = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = polygon
                    });
                }
            }
            if (collection.Texts != null)
            {
                foreach (var primitive in collection.Texts)
                {
                    Text2DStyle style = _styleIndex.TextStyles[primitive.StyleId];
                    Text2D      text  = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = text
                    });
                }
            }
            if (collection.LineTexts != null)
            {
                foreach (var primitive in collection.LineTexts)
                {
                    LineText2DStyle style    = _styleIndex.LineTextStyles[primitive.StyleId];
                    LineText2D      lineText = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = lineText
                    });
                }
            }

            // build the boxes list.
            boxes = new List <BoxF2D>();
            for (int idx = 0; idx < primitives.Count; idx++)
            {
                boxes.Add(primitives[idx].Scene2DPrimitive.GetBox());
            }
            return(primitives);
        }