Q&A - Question
MapToScreen inside GISPrintPage
RapK asked on June 27, 2018, keyword: Developer Kernel
I have placed a picture on the map by drag&drop. I paint this image in the TGIS_ViewerWnd.PaintExtraEvent. It's placed at the right position and drawn as it should. So far so good.
But I also want to print this at the right position. I handle this in TGIS_PrintManager.PrintPageEvent. In the Preview the image will still be drawn at the right position, since MapToScreen still returns the right information.
point := viewer.MapToScreen(FImageMapPos);
left := pr.TwipsToX(Floor(point.X * 15))
top := pr.TwipsToY(Floor(point.Y * 15))
Exact the same code is running when it comes to real printing, e.g. using the printer "Microsoft print to pdf". When I debug MapToScreen I observe, that its returning negative values for x and y. I already tried to use other printers, but a'm getting negative values for each and every one I've tried so far. Is this a bug, or am I doing something wrong? How can I get the right position for my image according to my map coordinates, so that it will be printed at the intended position?
the same code
I am Using DK 11
Alicja Karczewska (TatukGIS) replied May 28, 2018
f you want to place a picture according to map coordinates (FImageMapPos point),
define an additional layer on the top, and add the point with the picture as a symbol.
It guarantees that the picture will be placed and scaled properly.
Using MapToScreen while printing does not give the guarantee.
RapK replied June 04, 2018
Thank you for the answer.
How could I do that? can you please provide example code for this? Until now I did not find anything on thin in the documentation...
Best regards Raphael
RapK replied June 04, 2018
Hi I "managed" to do this with the following code:
procedure TfrmMain.GISDragDrop(Sender, Source: TObject; X, Y: Integer);
ll : TGIS_LayerVector ;
shp : TGIS_Shape ;
bmp := CreateLegendImg;
FLegendMapPos := GIS.ScreenToMap(TPoint.Create(X + (bmp.Width div 2), Y + (bmp.Height div 2))); // <-- CHECK!!!
ll := TGIS_LayerVector.Create ;
strPath := ChangeFileExt(System.IOUtils.TPath.GetTempFileName, '.bmp');
ll.Params.Marker.Symbol := SymbolList.Prepare( strPath + '?TRUE' ); // MakeTransparent -> TRUE
ll.Params.Marker.Size := - bmp.Width ; // <-- CHECK!!!
GIS.Add( ll ) ;
ll.CachedPaint := False ;
ll.Extent := GIS.Extent;
shp := TGIS_LayerVector( ll ).CreateShape( TGIS_ShapeType.Point ) ;
shp.Params.Marker.Color := TGIS_Color.Red;
shp.Params.Marker.OutlineColor := shp.Params.Marker.Color ;
shp.Lock( TGIS_Lock.Extent ) ;
So, I can drag&drop the selected part of the legend into the viewer. By dropping the legend it creates a new layer. There I place my point and and use the picture as marker symbol. I guess thats what you suggested?!
It looks good in the viewer and also in the preview (so was it with my first code). But as soon as I print this the image not only appears on wrong position but also far too small.
I guess the scaling problem has something todo with setting the markers size?!... And I have another minor issue. By setting the markers position it's placing the image centered to this point. Which ist not what I wanted here. Thats what the Hack for setting FLegendMapPos is for. How would I do this the right way? because this way its not working properly with every position, since this could be wrong parameters for ScreenToMap. But this is secondary. First It has to be placed and scaled well when printing!
Hope someone can help!
Tomasz Kosinski (TatukGIS) replied June 05, 2018
means pixels. Pixels on a printer are much smaller. You should use device independent measurement.
- TWIPS . Formula is bmp.Width * 1440 div 96
- Or use SizeAsText = bmp.Width.ToString +"dip"; for device independent pixels
RapK replied June 11, 2018
Thank you for the answer. Its a little bit greater when i set bmp.Width * 1440 div 96. But still far too small. In preview it looks still good, but on the pdf its still too small and still at the wrong position! As I told, on the preview it's at the right position, but not when it comes to printing!
Can you please help us to fix this?
I wanted to provide the whole application code or at least some images, but there's no such functionality?!
RapK replied June 26, 2018
Could you please provide some further support here?
Thanks in advance
Tomasz Kosinski (TatukGIS) replied June 26, 2018
For support request please contact support. We do not provide support in Q&A section.
Alicja Karczewska (TatukGIS) replied June 27, 2018
Prepare a short sample program with your problem and send it to our support. This way we have more possibilities to help.
RapK replied June 27, 2018
Ok. I will provide an example program next week as I work for another comany the rest of the week. Thanks for your reply
If you would like to answer the question please Sign In.
The Questions and Answers (Q & A) is intended to provide a means of communication between TatukGIS customers.
- Licensed users (with active maintenance play) of TatukGIS products may contribute to the Q & A content. Read-only access is available to anyone.
- Keep the content positive and professional.
- Be courteous to others by posting information when a question or issue asked on the Q & A is answered or resolved by other means (such as with help from TatukGIS technical support). Offer others at least a hint how the posted question was answered or the issue was resolved.
- The Q & A is not a replacement for TatukGIS technical support. TatukGIS team may or may not regularly follow or contribute content.