コード例 #1
0
        private MapItemPolygon AddPolygonWithInteriorRings(string itemTitle, Point[] polygon, List <Point[]> interiors)
        {
            if (polygon.Length < 3)
            {
                throw new ArgumentException("A polygon should contain at least 3 points");
            }

            if (polygon[0].Latitude != polygon[polygon.Length - 1].Latitude ||
                polygon[0].Longitude != polygon[polygon.Length - 1].Longitude)
            {
                throw new ArgumentException("The last and first points in a polygon should be the same");
            }

            List <Point> totalShape = new List <Point>(polygon);

            foreach (var interior in interiors)
            {
                if (interior.Length < 3)
                {
                    throw new ArgumentException("A interior should contain at least 3 points");
                }

                if (interior[0].Latitude != interior[interior.Length - 1].Latitude ||
                    interior[0].Longitude != interior[interior.Length - 1].Longitude)
                {
                    throw new ArgumentException("The last and first points in a interior should be the same");
                }

                totalShape.AddRange(new List <Point>(interior));
            }

            //-- To close off the polygon add the start point
            totalShape.Add(new Point(totalShape[0].Latitude, totalShape[0].Longitude));

            MapItemPolygon p = new MapItemPolygon(totalShape.ToArray())
            {
                T = itemTitle
            };

            Items.Add(p);
            return(p);
        }
コード例 #2
0
        private MapItemPolygon AddPolygon(string itemTitle, Point[] corners)
        {
            if (corners.Length < 3)
            {
                throw new ArgumentException("A polygon should contain at least 3 points");
            }

            if (corners[0].Latitude != corners[corners.Length - 1].Latitude ||
                corners[0].Longitude != corners[corners.Length - 1].Longitude)
            {
                throw new ArgumentException("The last and first points in a polygon should be the same");
            }

            MapItemPolygon p = new MapItemPolygon(corners)
            {
                T = itemTitle
            };

            Items.Add(p);
            return(p);
        }