im creating an application and i want to print the map in a plotter. It would be better to have a print preview and than a print, but i need to add other data to the map that will be printed, like a header and some other fields that will be filled in the printed map. Is there any function to send the map to crystal reports or any other way to achieve this?
Also, another solution is trying to save the map image on the map control into a disk image file, and then we can write our own printing logic to customize Header and other fields.
Any more questions please feel free to let me know.
I have another problem. If i save the image in the size of the map control everything is ok, but i dont want that the printing area to depend on the size of the map control. I use the following code to do the print to file
Dim widthArea As Integer = 725
Dim heightArea As Integer = 500
Dim bitmap As New Bitmap(widthArea, heightArea)
-> to print the map in the screen i use Dim bitmap as new bitmap(cint(map.width),cint(map.height))
For Each layeroverlay As LayerOverlay In map.Overlays
Dim point As PointShape = map.CurrentExtent.GetCenterPoint
Dim oRect As RectangleShape = New RectangleShape((point.X - widthArea / 2), (point.Y + heightArea / 2), (point.X + widthArea / 2), (point.Y - heightArea / 2))
-> to print the map in the screen i use Dim oRect RectangleShape = map.currentextent
I read the code you provided; I think the width area and height area at the very beginning should be the screen pixel, right? If so, then I think the oRect calculation should be something wrong by mixing with screen pixel and world coordinate, following is my updated code. Besides, did you set the DrawingArea for the PrinterGeoCanvas which is used to clip the drawing rectangle?
Dim widthArea As Integer = 725 Dim heightArea As Integer = 500 Dim bitmap As New Bitmap(widthArea, heightArea) 'to print the map in the screen i use Dim bitmap as new bitmap(cint(map.width),cint(map.height))
For Each layeroverlay As LayerOverlay In map.Overlays Dim point As PointShape = map.CurrentExtent.GetCenterPoint Dim centerPointF As ScreenPointF = ExtentHelper.ToScreenCoordinate(map.CurrentExtent, point, map.Width, map.Height)
Dim oRect As RectangleShape = New RectangleShape((centerPointF.X - widthArea / 2), (centerPointF.Y + heightArea / 2), (centerPointF.X + widthArea / 2), (centerPointF.Y - heightArea / 2)) Dim worldExtentULPoint As PointShape = ExtentHelper.ToWorldCoordinate(map.CurrentExtent, oRect.UpperLeftPoint.X, CurrentExtent, oRect.UpperLeftPoint.Y, map.Width, map.Height) Dim worldExtentLRPoint As PointShape = ExtentHelper.ToWorldCoordinate(map.CurrentExtent, oRect.LowerRightPoint.X, CurrentExtent, oRect.LowerRightPoint.Y, map.Width, map.Height) Dim oRectWorld As RectangleShape = New RectangleShape(worldExtentULPoint, worldExtentLRPoint)
'to print the map in the screen i use Dim oRect RectangleShape = map.currentextent For Each layer As Layer In layeroverlay.Layers PrinterGeoCanvas.BeginDrawing(bitmap, oRectWorld, GeographyUnit.DecimalDegree) layer.Open() layer.Draw(PrinterGeoCanvas, labelsInLayers) layer.Close() PrinterGeoCanvas.EndDrawing() Next Next
Any more questions please feel free to let me know.
Thanks Yale, i got a maxY smaller than minY so i did a small change in the code. This works perfectly now. And gdiPlusGeoCanvas dont has a drawing area. Here is the working code
Dim centerPoint As PointShape = map.CurrentExtent.GetCenterPoint Dim centerPointF As ScreenPointF = ExtentHelper.ToScreenCoordinate(map.CurrentExtent, centerPoint, map.Width, map.Height)
Dim screenPointUL As ScreenPointF = New ScreenPointF((centerPointF.X - widthArea / 2), (centerPointF.Y - heightArea / 2)) Dim screenPointLR As ScreenPointF = New ScreenPointF((centerPointF.X + widthArea / 2), (centerPointF.Y + heightArea / 2))
Dim worldExtentULPoint As PointShape = ExtentHelper.ToWorldCoordinate(map.CurrentExtent, screenPointUL, map.Width, map.Height) Dim worldExtentLRPoint As PointShape = ExtentHelper.ToWorldCoordinate(map.CurrentExtent, screenPointLR, map.Width, map.Height) Dim oRectWorld As RectangleShape = New RectangleShape(worldExtentULPoint, worldExtentLRPoint)