//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Default constructor. */ public MapCollection() { SetMapObjectType(COLLECTION); MultiPline = null; MultiPoint = null; MultiRegion = null; }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * get a map multipoint object at given index. */ private MapMultiPoint GetMapMultiPoint(RecordIndex recordIndex) { MapMultiPoint mapMultiPoint = new MapMultiPoint { SymbolType = { Shape = recordIndex.Param1, Color = recordIndex.Param2, Size = recordIndex.Param3 }, Bounds = { X = recordIndex.MinX / DOUBLE_PRECISION, Y = recordIndex.MinY / DOUBLE_PRECISION, Width = (recordIndex.MaxX - recordIndex.MinX) / DOUBLE_PRECISION, Height = (recordIndex.MaxY - recordIndex.MinY) / DOUBLE_PRECISION } }; int numberOfPoints = DataReader.ReadInt(_reader); mapMultiPoint.Points = new GeoLatLng[numberOfPoints]; for (int i = 0; i < numberOfPoints; i++) { int x = DataReader.ReadInt(_reader); int y = DataReader.ReadInt(_reader); mapMultiPoint.Points[i] = new GeoLatLng(y / DOUBLE_PRECISION, x / DOUBLE_PRECISION); } return(mapMultiPoint); }
/// <summary> /// Converts a MapMultiPoint into a Geometry object. /// </summary> /// <param name="shape">A Bing Maps MapMultiPoint object</param> /// <returns>A Geometry representation of the MapMultiPoint object</returns> public static Geometry ToGeometry(this MapMultiPoint shape) { if (shape is MapPolyline) { return((shape as MapPolyline).ToGeometry()); } else if (shape is MapPolygon) { return((shape as MapPolygon).ToGeometry()); } return(null); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Copy constructor. * @param mapCollection map object copy from. */ public MapCollection(MapCollection mapCollection) : base(mapCollection) { SetMapObjectType(COLLECTION); MultiPline = null; MultiPoint = null; MultiRegion = null; if (mapCollection.MultiPline != null) { MultiPline = new MapMultiPline(mapCollection.MultiPline); } if (mapCollection.MultiPoint != null) { MultiPoint = new MapMultiPoint(mapCollection.MultiPoint); } if (mapCollection.MultiRegion != null) { MultiRegion = new MapMultiRegion(mapCollection.MultiRegion); } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- 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); } } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * get a map multipoint object at given index. */ private MapMultiPoint GetMapMultiPoint(RecordIndex recordIndex) { MapMultiPoint mapMultiPoint = new MapMultiPoint { SymbolType = { Shape = recordIndex.Param1, Color = recordIndex.Param2, Size = recordIndex.Param3 }, Bounds = { X = recordIndex.MinX/DOUBLE_PRECISION, Y = recordIndex.MinY/DOUBLE_PRECISION, Width = (recordIndex.MaxX - recordIndex.MinX)/DOUBLE_PRECISION, Height = (recordIndex.MaxY - recordIndex.MinY)/DOUBLE_PRECISION } }; int numberOfPoints = DataReader.ReadInt(_reader); mapMultiPoint.Points = new GeoLatLng[numberOfPoints]; for (int i = 0; i < numberOfPoints; i++) { int x = DataReader.ReadInt(_reader); int y = DataReader.ReadInt(_reader); mapMultiPoint.Points[i] = new GeoLatLng(y / DOUBLE_PRECISION, x / DOUBLE_PRECISION); } return mapMultiPoint; }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Set the multipoint part the collection. * @param multiPoint the multipoint part the collection. */ public void SetMultiPoint(MapMultiPoint multiPoint) { MultiPoint = multiPoint; }