Пример #1
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 21JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Add a map text to the drawing list.
         * @param mapText
         */

        private void AddMapName(MapText mapText)
        {
            GeoLatLngBounds mapTextBounds = mapText.Bounds;

            for (int i = 0; i < _mapNameHolder.Count; i++)
            {
                GeoLatLngBounds storedMapTextBounds =
                    ((MapText)_mapNameHolder[i]).Bounds;
                if (storedMapTextBounds.Intersects(mapTextBounds))
                {
                    return;
                }
            }
            if (_mapSize.Contains(mapTextBounds))
            {
                _mapNameHolder.Add(mapText);
            }
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 14JAN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * clip the a pline.
         * @param input the pline to be clipped.
         * @return the clipped pline.
         */

        public ArrayList ClipPline(GeoLatLng[] input)
        {
            ArrayList clipped = new ArrayList();
            GeoLatLng p, prev = null;
            bool      isInsidePrev = false;

            clipped.Clear();
            for (int i = 0; i < input.Length; i++)
            {
                p = input[i];
                bool isInside = _rectBounds.Contains(p);
                if (isInside)
                {
                    if (!isInsidePrev && (((clipped.Count != 0) &&
                                           (!prev.Equals(clipped[clipped.Count - 1]))) ||
                                          ((clipped.Count == 0 && (prev != null)))))
                    {
                        clipped.Add(prev);
                    }
                    clipped.Add(p);
                }
                else if (isInsidePrev)
                {
                    clipped.Add(p);
                }
                else if (prev != null)
                {
                    GeoLatLngBounds rect = new GeoLatLngBounds(Math.Min(p.X, prev.X),
                                                               Math.Min(p.Y, prev.Y),
                                                               Math.Max(p.X, prev.X) - Math.Min(p.X, prev.X),
                                                               Math.Max(p.Y, prev.Y) - Math.Min(p.Y, prev.Y));

                    if (rect.Intersects(_rectBounds))
                    {
                        ArrayList line1 = new ArrayList();
                        line1.Add(prev);
                        line1.Add(p);

                        ArrayList line2 = new ArrayList();
                        line2.Add(new GeoLatLng(_rectBounds.Y, _rectBounds.X));
                        line2.Add(new GeoLatLng(
                                      (_rectBounds.Y + _rectBounds.Height),
                                      (_rectBounds.X + _rectBounds.Width)));

                        ArrayList line3 = new ArrayList();
                        line3.Add(new GeoLatLng((_rectBounds.Y + _rectBounds.Height),
                                                _rectBounds.X));
                        line3.Add(new GeoLatLng(
                                      _rectBounds.Y,
                                      (_rectBounds.X + _rectBounds.Width)));

                        if (IsLineInter(line1, line2) ||
                            IsLineInter(line1, line3))
                        {
                            clipped.Add(prev);
                            clipped.Add(p);
                        }
                    }
                }
                isInsidePrev = isInside;
                prev         = p;
            }

            return(clipped);
        }