Ejemplo n.º 1
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 21JUN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * draw a map object.
         * @param mapObject the map object to be drawing.
         * @param drawBoundary the drawing boundry.
         * @param zoomLevel the current zoomLevel.
         */
        public override void DrawMapObject(MapObject mapObject, GeoLatLngBounds drawBoundary,
                int zoomLevel)
        {
            GeoLatLng drawPt = new GeoLatLng();
            _sutherlandHodgman = new SutherlandHodgman(drawBoundary);
            _mapZoomLevel = zoomLevel;
            _mapCenterPt.X = drawBoundary.GetCenterX();
            _mapCenterPt.Y = drawBoundary.GetCenterY();
            bool pointFound = false;
            switch (mapObject.GetMapObjectType())
            {
                case MapObject.NONE:
                    break;
                case MapObject.POINT:
                    {
                        MapPoint mapPoint = (MapPoint)mapObject;
                        DrawPoint(mapPoint);
                        drawPt.X = mapPoint.Point.X;
                        drawPt.Y = mapPoint.Point.Y;
                        pointFound = true;
                    }
                    break;
                case MapObject.MULTIPOINT:
                    {
                        MapMultiPoint mapMultiPoint = (MapMultiPoint)mapObject;
                        for (int i = 0; i < mapMultiPoint.Points.Length; i++)
                        {
                            MapPoint mapPoint = new MapPoint
                                                    {
                                                        SymbolType = mapMultiPoint.SymbolType,
                                                        Point = new GeoLatLng(mapMultiPoint.Points[i])
                                                    };
                            DrawPoint(mapPoint);
                        }
                        for (int i = 0; i < mapMultiPoint.Points.Length; i++)
                        {
                            if (drawBoundary.Contains(mapMultiPoint.Points[i]))
                            {
                                drawPt.X = mapMultiPoint.Points[i].X;
                                drawPt.Y = mapMultiPoint.Points[i].Y;
                                pointFound = true;
                                break;
                            }
                        }

                    }
                    break;
                case MapObject.PLINE:
                    {
                        MapPline mapPline = (MapPline)mapObject;
                        DrawPline(mapPline.PenStyle, mapPline.Pline);
                        for (int i = 0; i < mapPline.Pline.GetVertexCount(); i++)
                        {
                            if (drawBoundary.Contains(mapPline.Pline.GetVertex(i)))
                            {
                                drawPt.X = mapPline.Pline.GetVertex(i).X;
                                drawPt.Y = mapPline.Pline.GetVertex(i).Y;
                                pointFound = true;
                                break;
                            }
                        }
                    }
                    break;
                case MapObject.MULTIPLINE:
                    {
                        MapMultiPline mapMultiPline = (MapMultiPline)mapObject;
                        for (int i = 0; i < mapMultiPline.Plines.Length; i++)
                        {
                            DrawPline(mapMultiPline.PenStyle,
                                    mapMultiPline.Plines[i]);
                            for (int j = 0; j < mapMultiPline.Plines[i].GetVertexCount(); j++)
                            {
                                if (drawBoundary.Contains(mapMultiPline.Plines[i].GetVertex(j)))
                                {
                                    drawPt.X = mapMultiPline.Plines[i].GetVertex(j).X;
                                    drawPt.Y = mapMultiPline.Plines[i].GetVertex(j).Y;
                                    pointFound = true;
                                    break;
                                }
                            }
                        }
                    }
                    break;
                case MapObject.REGION:
                    {
                        MapRegion mapRegion = (MapRegion)mapObject;
                        DrawRegion(mapRegion.PenStyle, mapRegion.BrushStyle,
                                mapRegion.Region);
                        drawPt.X = mapRegion.CenterPt.X;
                        drawPt.Y = mapRegion.CenterPt.Y;
                        pointFound = true;
                    }
                    break;
                case MapObject.MULTIREGION:
                    {
                        MapMultiRegion mapMultiRegion = (MapMultiRegion)mapObject;
                        for (int i = 0; i < mapMultiRegion.Regions.Length; i++)
                        {
                            DrawRegion(mapMultiRegion.PenStyle,
                                    mapMultiRegion.BrushStyle,
                                    mapMultiRegion.Regions[i]);

                        }
                        drawPt.X = mapMultiRegion.CenterPt.X;
                        drawPt.Y = mapMultiRegion.CenterPt.Y;
                        pointFound = true;
                    }
                    break;
                case MapObject.COLLECTION:
                    {
                        MapCollection mapCollection = (MapCollection)mapObject;
                        if (mapCollection.MultiRegion != null)
                        {
                            MapMultiRegion mapMultiRegion = mapCollection.MultiRegion;
                            for (int i = 0; i < mapMultiRegion.Regions.Length; i++)
                            {
                                DrawRegion(mapMultiRegion.PenStyle,
                                        mapMultiRegion.BrushStyle,
                                        mapMultiRegion.Regions[i]);
                            }
                        }
                        if (mapCollection.MultiPline != null)
                        {
                            MapMultiPline mapMultiPline = mapCollection.MultiPline;
                            for (int i = 0; i < mapMultiPline.Plines.Length; i++)
                            {
                                DrawPline(mapMultiPline.PenStyle,
                                        mapMultiPline.Plines[i]);
                            }
                        }
                        if (mapCollection.MultiPoint != null)
                        {
                            MapMultiPoint mapMultiPoint = mapCollection.MultiPoint;
                            for (int i = 0; i < mapMultiPoint.Points.Length; i++)
                            {
                                MapPoint mapPoint = new MapPoint
                                                        {
                                                            SymbolType = mapMultiPoint.SymbolType,
                                                            Point = new GeoLatLng(mapMultiPoint.Points[i])
                                                        };
                                DrawPoint(mapPoint);
                            }
                        }
                        pointFound = true;
                        drawPt.X = mapCollection.Bounds.X + mapCollection.Bounds.Width / 2;
                        drawPt.Y = mapCollection.Bounds.Y + mapCollection.Bounds.Height / 2;

                    }
                    break;
                case MapObject.TEXT:
                    {
                        MapText mapText = (MapText)mapObject;
                        drawPt.X = mapText.Point.X;
                        drawPt.Y = mapText.Point.Y;
                        pointFound = true;
                    }
                    break;
            }
            if (!mapObject.Name.ToLower().Equals("unknown") && pointFound)
            {
                MapText mapName = new MapText {Font = _font};
                mapName.SetForeColor(_fontColor);
                mapName.TextString = mapObject.Name;
                GeoPoint screenPt = FromLatLngToMapPixel(drawPt);
                mapName.Point.X = screenPt.X;
                mapName.Point.Y = screenPt.Y;
                mapName.Bounds.X = mapName.Point.X;
                mapName.Bounds.Y = mapName.Point.Y;
                if (_font != null)
                {
                    mapName.Bounds.Height = IMAGE_PATERN_WIDTH;
                    mapName.Bounds.Width = _font.CharsWidth(mapObject.Name.ToCharArray(), 0,
                            mapObject.Name.ToCharArray().Length);

                }
                AddMapName(mapName);

            }
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 21JUN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * draw a map object.
         * @param mapObject the map object to be drawing.
         * @param drawBoundary the drawing boundry.
         * @param zoomLevel the current zoomLevel.
         */
        public override void DrawMapObject(MapObject mapObject, GeoLatLngBounds drawBoundary,
                int zoomLevel)
        {
            GeoLatLng drawPt = new GeoLatLng();
            _sutherlandHodgman = new SutherlandHodgman(drawBoundary);
            _mapZoomLevel = zoomLevel;
            _mapCenterPt.X = drawBoundary.GetCenterX();
            _mapCenterPt.Y = drawBoundary.GetCenterY();
            bool pointFound = false;
            Point[] plinePoints=null;
            switch (mapObject.GetMapObjectType())
            {
                case MapObject.NONE:
                    break;
                case MapObject.POINT:
                    {
                        MapPoint mapPoint = (MapPoint)mapObject;
                        DrawPoint(mapPoint);
                        drawPt.X = mapPoint.Point.X;
                        drawPt.Y = mapPoint.Point.Y;
                        pointFound = true;
                    }
                    break;
                case MapObject.MULTIPOINT:
                    {
                        MapMultiPoint mapMultiPoint = (MapMultiPoint)mapObject;
                        for (int i = 0; i < mapMultiPoint.Points.Length; i++)
                        {
                            MapPoint mapPoint = new MapPoint
                            {
                                SymbolType = mapMultiPoint.SymbolType,
                                Point = new GeoLatLng(mapMultiPoint.Points[i])
                            };
                            DrawPoint(mapPoint);
                        }
                        for (int i = 0; i < mapMultiPoint.Points.Length; i++)
                        {
                            if (drawBoundary.Contains(mapMultiPoint.Points[i]))
                            {
                                drawPt.X = mapMultiPoint.Points[i].X;
                                drawPt.Y = mapMultiPoint.Points[i].Y;
                                pointFound = true;
                                break;
                            }
                        }

                    }
                    break;
                case MapObject.PLINE:
                    {
                        MapPline mapPline = (MapPline)mapObject;
                        plinePoints=DrawPline(mapPline.PenStyle, mapPline.Pline);
                        for (int i = 0; i < mapPline.Pline.GetVertexCount(); i++)
                        {
                            if (drawBoundary.Contains(mapPline.Pline.GetVertex(i)))
                            {
                                drawPt.X = mapPline.Pline.GetVertex(i).X;
                                drawPt.Y = mapPline.Pline.GetVertex(i).Y;
                                pointFound = true;
                                break;
                            }
                        }
                    }
                    break;
                case MapObject.MULTIPLINE:
                    {
                        MapMultiPline mapMultiPline = (MapMultiPline)mapObject;
                        for (int i = 0; i < mapMultiPline.Plines.Length; i++)
                        {
                            DrawPline(mapMultiPline.PenStyle,
                                    mapMultiPline.Plines[i]);
                            for (int j = 0; j < mapMultiPline.Plines[i].GetVertexCount(); j++)
                            {
                                if (drawBoundary.Contains(mapMultiPline.Plines[i].GetVertex(j)))
                                {
                                    drawPt.X = mapMultiPline.Plines[i].GetVertex(j).X;
                                    drawPt.Y = mapMultiPline.Plines[i].GetVertex(j).Y;
                                    pointFound = true;
                                    break;
                                }
                            }
                        }
                    }
                    break;
                case MapObject.REGION:
                    {
                        MapRegion mapRegion = (MapRegion)mapObject;
                        DrawRegion(mapRegion.PenStyle, mapRegion.BrushStyle,
                                mapRegion.Region);
                        drawPt.X = mapRegion.CenterPt.X;
                        drawPt.Y = mapRegion.CenterPt.Y;
                        pointFound = true;
                    }
                    break;
                case MapObject.MULTIREGION:
                    {
                        MapMultiRegion mapMultiRegion = (MapMultiRegion)mapObject;
                        for (int i = 0; i < mapMultiRegion.Regions.Length; i++)
                        {
                            DrawRegion(mapMultiRegion.PenStyle,
                                    mapMultiRegion.BrushStyle,
                                    mapMultiRegion.Regions[i]);

                        }
                        drawPt.X = mapMultiRegion.CenterPt.X;
                        drawPt.Y = mapMultiRegion.CenterPt.Y;
                        pointFound = true;
                    }
                    break;
                case MapObject.COLLECTION:
                    {
                        MapCollection mapCollection = (MapCollection)mapObject;
                        if (mapCollection.MultiRegion != null)
                        {
                            MapMultiRegion mapMultiRegion = mapCollection.MultiRegion;
                            for (int i = 0; i < mapMultiRegion.Regions.Length; i++)
                            {
                                DrawRegion(mapMultiRegion.PenStyle,
                                        mapMultiRegion.BrushStyle,
                                        mapMultiRegion.Regions[i]);
                            }
                        }
                        if (mapCollection.MultiPline != null)
                        {
                            MapMultiPline mapMultiPline = mapCollection.MultiPline;
                            for (int i = 0; i < mapMultiPline.Plines.Length; i++)
                            {
                                DrawPline(mapMultiPline.PenStyle,
                                        mapMultiPline.Plines[i]);
                            }
                        }
                        if (mapCollection.MultiPoint != null)
                        {
                            MapMultiPoint mapMultiPoint = mapCollection.MultiPoint;
                            for (int i = 0; i < mapMultiPoint.Points.Length; i++)
                            {
                                MapPoint mapPoint = new MapPoint
                                {
                                    SymbolType = mapMultiPoint.SymbolType,
                                    Point = new GeoLatLng(mapMultiPoint.Points[i])
                                };
                                DrawPoint(mapPoint);
                            }
                        }
                        pointFound = true;
                        drawPt.X = mapCollection.Bounds.X + mapCollection.Bounds.Width / 2;
                        drawPt.Y = mapCollection.Bounds.Y + mapCollection.Bounds.Height / 2;

                    }
                    break;
                case MapObject.TEXT:
                    {
                        MapText mapText = (MapText)mapObject;
                        drawPt.X = mapText.Point.X;
                        drawPt.Y = mapText.Point.Y;
                        pointFound = true;
                    }
                    break;
            }
            if (!(mapObject.Name.ToLower().Equals("unknown") || mapObject.Name.Length==0) && pointFound)
            {
                MapText mapName = new MapText { Font = _font };
                mapName.SetForeColor(_fontColor);
                mapName.TextString = mapObject.Name;
                GeoPoint screenPt = FromLatLngToMapPixel(drawPt);
                mapName.Point.X = screenPt.X;
                mapName.Point.Y = screenPt.Y;
                mapName.Bounds.X = mapName.Point.X;
                mapName.Bounds.Y = mapName.Point.Y;
                Font font = null;
                if (_font != null)
                {

                    font = (Font)_font.GetNativeFont();
                    SizeF sizeF = SharedGraphics2D.Graphics.MeasureString(mapName.TextString, font);
                    mapName.Bounds.Height = sizeF.Height;
                    mapName.Bounds.Width = sizeF.Width;

                }
                TextPosInfo textPosInfo = new TextPosInfo();
                textPosInfo._mapText = mapName;
                if(mapObject.GetMapObjectType()==MapObject.PLINE)
                {
                    if(plinePoints!=null)
                    {
                        GraphicsPath graphicsPath = new GraphicsPath();
                        graphicsPath.AddLines(plinePoints);
                        RectangleF []rectangleF;
                        double angle = GetAngle(plinePoints[0], plinePoints[plinePoints.Length - 1]);
                        if (angle < 180)
                        {
                            graphicsPath.Reverse();
                        }
                        angle = GetAngle(plinePoints[0], plinePoints[plinePoints.Length - 1]);

                        float rotateAngle = GetRotateAngle(angle);
                        rectangleF = SharedGraphics2D.Graphics.MeasureString(mapName.TextString, font,
                                                                                new SolidBrush(
                                                                                    Color.FromArgb(_fontColor)),
                                                                                TextPathAlign.Center,
                                                                                TextPathPosition.CenterPath, 100, rotateAngle,
                                                                                graphicsPath);

                        textPosInfo._graphicsPath = graphicsPath;
                        textPosInfo._rectangles = rectangleF;

                        if (rectangleF.Length == mapName.TextString.Length)
                        {

                            //RectangleF[] rectangleFs = new RectangleF[rectangleF.Length];
                            //Array.Copy(rectangleF, rectangleFs, rectangleF.Length);
                            //for (int i = 0; i < rectangleFs.Length;i++ )
                            //{
                            //    for(int j=0;j<rectangleF.Length;j++)
                            //    {
                            //        if(i!=j)
                            //        {
                            //            if(rectangleFs[i].IntersectsWith(rectangleF[j]))
                            //            {
                            //                return;
                            //            }
                            //        }
                            //    }
                            //}

                           AddMapName(textPosInfo);
                        }

                    }
                }else
                {
                    textPosInfo._graphicsPath = null;
                    textPosInfo._rectangles = new[]{new RectangleF((float)textPosInfo._mapText.Bounds.X, (float)textPosInfo._mapText.Bounds.Y,
                                                           (float)textPosInfo._mapText.Bounds.Width,
                                                           (float)textPosInfo._mapText.Bounds.Height)};
                    AddMapName(textPosInfo);
                }

            }
        }