Exemple #1
0
        /// <summary>
        /// Extracts style information.
        /// </summary>
        /// <param name="polygon"></param>
        /// <param name="layer"></param>
        /// <returns></returns>
        public static Polygon2DStyle From(Polygon2D polygon, int layer)
        {
            Polygon2DStyle newStyle = new Polygon2DStyle();

            newStyle.Color   = polygon.Color;
            newStyle.MaxZoom = polygon.MaxZoom;
            newStyle.MinZoom = polygon.MinZoom;
            newStyle.Fill    = polygon.Fill;
            newStyle.Width   = polygon.Width;
            newStyle.Layer   = layer;
            return(newStyle);
        }
Exemple #2
0
        /// <summary>
        /// Adds a new style and returns it's index.
        /// </summary>
        /// <param name="polygon"></param>
        /// <param name="layer"></param>
        /// <returns></returns>
        public ushort AddStyle(Polygon2D polygon, int layer)
        {
            Polygon2DStyle newStyle = Polygon2DStyle.From(polygon, layer);
            int            indexOf  = this.PolygonStyles.IndexOf(newStyle);

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

            return(this.Layer == other.Layer &
                   this.MaxZoom == other.MaxZoom &
                   this.MinZoom == other.MinZoom &
                   this.Color == other.Color &
                   this.Layer == other.Layer &
                   this.Width == other.Width &
                   this.Fill == other.Fill);
        }
        /// <summary>
        /// Converts this basic entry into a scene object.
        /// </summary>
        /// <param name="style"></param>
        /// <returns></returns>
        internal Polygon2D To(Polygon2DStyle style)
        {
            Polygon2D polygon = new Polygon2D();

            polygon.Color   = style.Color;
            polygon.Fill    = style.Fill;
            polygon.MaxZoom = style.MaxZoom;
            polygon.MinZoom = style.MinZoom;
            polygon.Width   = style.Width;
            polygon.X       = this.X;
            polygon.Y       = this.Y;

            polygon.MinX = int.MaxValue;
            polygon.MaxX = int.MinValue;
            for (int idx = 0; idx < polygon.X.Length; idx++)
            {
                if (polygon.X[idx] > polygon.MaxX)
                {
                    polygon.MaxX = polygon.X[idx];
                }
                if (polygon.X[idx] < polygon.MinX)
                {
                    polygon.MinX = polygon.X[idx];
                }
            }
            polygon.MinY = int.MaxValue;
            polygon.MaxY = int.MinValue;
            for (int idx = 0; idx < polygon.Y.Length; idx++)
            {
                if (polygon.Y[idx] > polygon.MaxY)
                {
                    polygon.MaxY = polygon.Y[idx];
                }
                if (polygon.Y[idx] < polygon.MinY)
                {
                    polygon.MinY = polygon.Y[idx];
                }
            }
            return(polygon);
        }
 /// <summary>
 /// Extracts style information.
 /// </summary>
 /// <param name="polygon"></param>
 /// <param name="layer"></param>
 /// <returns></returns>
 public static Polygon2DStyle From(Polygon2D polygon, int layer)
 {
     Polygon2DStyle newStyle = new Polygon2DStyle();
     newStyle.Color = polygon.Color;
     newStyle.MaxZoom = polygon.MaxZoom;
     newStyle.MinZoom = polygon.MinZoom;
     newStyle.Fill = polygon.Fill;
     newStyle.Width = polygon.Width;
     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);
        }