Beispiel #1
0
        /// <summary>
        /// Extracts style information.
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public static Image2DStyle From(Image2D image, int layer)
        {
            Image2DStyle newStyle = new Image2DStyle();

            newStyle.MaxZoom = image.MaxZoom;
            newStyle.MinZoom = image.MinZoom;
            newStyle.Layer   = layer;
            return(newStyle);
        }
Beispiel #2
0
        /// <summary>
        /// Adds a new style and returns it's index.
        /// </summary>
        /// <param name="image"></param>
        /// <param name="layer"></param>
        /// <returns></returns>
        public ushort AddStyle(Image2D image, int layer)
        {
            Image2DStyle newStyle = Image2DStyle.From(image, layer);
            int          indexOf  = this.ImageStyles.IndexOf(newStyle);

            if (indexOf < 0)
            { // the style is not found yet.
                indexOf = this.ImageStyles.Count;
                this.ImageStyles.Add(newStyle);
            }
            return((ushort)indexOf);
        }
Beispiel #3
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 Image2DStyle))
            { // wrong type.
                return(false);
            }
            Image2DStyle other = (obj as Image2DStyle);

            return(this.Layer == other.Layer &
                   this.MaxZoom == other.MaxZoom &
                   this.MinZoom == other.MinZoom);
        }
        /// <summary>
        /// Converts this basic entry into a scene object.
        /// </summary>
        /// <param name="style"></param>
        /// <returns></returns>
        internal Image2D To(Image2DStyle style)
        {
            Image2D image = new Image2D();

            image.Left      = this.Left;
            image.Bottom    = this.Bottom;
            image.ImageData = this.ImageData;
            image.MaxZoom   = style.MaxZoom;
            image.MinZoom   = style.MinZoom;
            image.Right     = this.Right;
            image.Top       = this.Top;
            return(image);
        }
 /// <summary>
 /// Extracts style information.
 /// </summary>
 /// <param name="image"></param>
 /// <returns></returns>
 public static Image2DStyle From(Image2D image, int layer)
 {
     Image2DStyle newStyle = new Image2DStyle();
     newStyle.MaxZoom = image.MaxZoom;
     newStyle.MinZoom = image.MinZoom;
     newStyle.Layer = layer;
     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);
        }