Recent

Author Topic: LazMapViewer - Lines between realpoints  (Read 1517 times)

Arctic_Eddie

  • Jr. Member
  • **
  • Posts: 91
LazMapViewer - Lines between realpoints
« on: August 07, 2022, 07:51:09 pm »
I've been using the viewer package from the OPM for a ham radio propagation project. The purpose is to display the path from a sending station (TX) using WSPR (Weak Signal Propagation Report) and all those hearing the signal (RX) and reporting the spot to the WSPR website. There is one problem trying to draw lines from the TX station to all RX stations. The only thing that has worked so far is the below code.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.DisplayTrack( trpt1, trpt2 :TRealPoint );
  2. var
  3.      rxpt, txpt         :TPoint;
  4. begin
  5.      // Display a line between the TX and Rx stations
  6.      WSPRMap.DrawingEngine.PenWidth:=1;
  7.      WSPRMap.DrawingEngine.PenColor:=clRed;
  8.      txpt := WSPRMap.LonLatToScreen( trpt1 );      // TX screen point
  9.      rxpt := WSPRMap.LonLatToScreen( trpt2 );      // RX screen point
  10.      WSPRMap.DrawingEngine.Line(txpt.x,txpt.y,rxpt.x,rxpt.y);
  11. end;
  12.  

The problem is that when the map is zoomed or panned then the drawing engine deletes the tracks and they have to be displayed again. So my question is: what method should be used to draw these lines whereby the engine is aware of the change and redraws them?


wp

  • Hero Member
  • *****
  • Posts: 10030
Re: LazMapViewer - Lines between realpoints
« Reply #1 on: August 07, 2022, 11:04:19 pm »
Don't paint outside the paint cycle - that's a general rule, not related to the MapViewer. Because each control must be able to repaint itself at any time if the operating system requires that.

The "official" way to add a line to the mapview is to add a TGpsTrack to the GpsItems list of the MapViewer. The MapViewer "knows" what a track is and how to draw it because a track consists of discrete points connected by straight lines.

If the endpoints of your line are close to each other it is sufficient to simply add the endpoints to the track. When the line covers a large distance, however, you must divide the line into several segements and add these to the track as well; this way it is guaranteed that the line is curved due to the spherical projection of the grand circle between start and end point.

In the attachment you find a simple example for adding such a segmented "line" to the mapviewer.

Arctic_Eddie

  • Jr. Member
  • **
  • Posts: 91
Re: LazMapViewer - Lines between realpoints
« Reply #2 on: August 07, 2022, 11:27:11 pm »
Thank you so much. I'll add that to my project tomorrow.

I have other questions but will put them in a separate post.

Arctic_Eddie

  • Jr. Member
  • **
  • Posts: 91
LazMapViewer - Lines between realpoints
« Reply #3 on: August 08, 2022, 02:01:57 pm »
Unfortunately, the compile failed in the same way as your ADrawer example. The error list is shown below. I'm missing something common in both situations.
Code: Pascal  [Select][+][-]
  1. Compile Project, Target: bin\x86_64-win64\mapviewer_line_demo.exe: Exit code 1, Errors: 4, Hints: 2
  2. Hint: Start of reading config file C:\lazarus\fpc\3.2.0\bin\x86_64-win64\fpc.cfg
  3. Hint: End of reading config file C:\lazarus\fpc\3.2.0\bin\x86_64-win64\fpc.cfg
  4. main.pas(55,12) Error: identifier idents no member "LineColor"
  5. main.pas(56,12) Error: identifier idents no member "LineWidth"
  6. main.pas(63,46) Error: Identifier not found "TRealPoint"
  7. main.pas(82,23) Error: Identifier not found "RealPoint"
  8.  

wp

  • Hero Member
  • *****
  • Posts: 10030
Re: LazMapViewer - Lines between realpoints
« Reply #4 on: August 08, 2022, 05:57:18 pm »
Ah, I see - you seem to be using the OPM version which is not in sync with the development version. Please install the version from ccr; either by using svn, or get the snapshot from https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/lazmapviewer/

Arctic_Eddie

  • Jr. Member
  • **
  • Posts: 91
Re: LazMapViewer - Lines between realpoints
« Reply #5 on: August 08, 2022, 07:03:43 pm »
What do I need to remove of the OPM version?

wp

  • Hero Member
  • *****
  • Posts: 10030
Re: LazMapViewer - Lines between realpoints
« Reply #6 on: August 08, 2022, 07:18:13 pm »
Not absolutely necessary since the IDE always used the version that was installed last. But if you want to do it: Check LazMapViewer in OPM, then click "Uninstall".

In order to install the new ccr version unzip the snapshot to some folder, then, in the IDE, go to "Package" > "Open package file (.lpk)" > navigate to the folder with the ccr version > open "lazmapviewerpkg.lpk" > "Use" > "Install". If you use the add-on packages in your project you must also install the other lpk files in the same way.

Arctic_Eddie

  • Jr. Member
  • **
  • Posts: 91
Re: LazMapViewer - Lines between realpoints
« Reply #7 on: August 08, 2022, 07:28:15 pm »
It was the other three lpk files that concerned me. I do not use them knowingly but will find out. I'll uninstall the old LazMapViewer and install the new one as you suggested.

Arctic_Eddie

  • Jr. Member
  • **
  • Posts: 91
Re: LazMapViewer - Lines between realpoints
« Reply #8 on: August 08, 2022, 08:39:01 pm »
The BGA object was causing a problem so I uninstalled it and now your line demo works. However, when trying to use your example below, I get several failures.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.MapView1DrawGpsPoint(Sender: TObject;
  2.   ADrawer: TMvCustomDrawingEngine; APoint: TGpsPoint);
  3. const
  4.   R = 8;
  5. var
  6.   p: TPoint;
  7. begin
  8.   // Screen coordinates of the GPS point
  9.   p := MapView1.LonLatToScreen(APoint.RealPoint);
  10.  
  11.   // Draw a blue circle
  12.   ADrawer.PenColor := clBlack;
  13.   ADrawer.BrushColor := clBlue;
  14.   ADrawer.BrushStyle := bsSolid;
  15.   ADrawer.Ellipse(p.X-R, p.Y-R, P.X+R, p.Y+R);
  16.  
  17.   // Draw the point label
  18.   ADrawer.BrushStyle := bsClear;
  19.   ADrawer.FontName := 'SegoeUI';
  20.   ADrawer.FontSize := 16;
  21.   ADrawer.FontStyle := [fsBold];
  22.   ADrawer.TextOut(
  23.     p.X - ADrawer.TextWidth(APoint.Name) div 2,
  24.     p.Y + R + 4,
  25.     APoint.Name
  26.   );
  27. end;
The ellipse function is unknown and causes a SIGSEGV fault. If I skip over that the blue circle does not draw anything as the TextWidth function returns a zero. If I substituted a real value, 20, it still does not draw. As soon as I click anything in my program, I get another SIGSEGV fault. Is this example not compatible with the dev version?

wp

  • Hero Member
  • *****
  • Posts: 10030
Re: LazMapViewer - Lines between realpoints
« Reply #9 on: August 08, 2022, 11:50:34 pm »
I am aware of crashes on Linux due to the GPS points and tracks painting, but not on Windows (which you seem to have).

That the drawer's Ellipse method is unknown could indicate that your new version is not correctly installed. Try this: Open "Tools" > "Configure Build Lazarus" and check the boxes "Clean all" and "Switch after building to automatically". Then click "Build".

Or: Open "Package" > "Install/Uninstall packages", and select the "lazmapviewerpkg.lpk" in the left listbox. When you scroll down the "Package Info" box you should see the path from where the package is used. Is this the path into which you unzipped the download? If not repeat the installation as described in the previous message.

Arctic_Eddie

  • Jr. Member
  • **
  • Posts: 91
Re: LazMapViewer - Lines between realpoints
« Reply #10 on: August 09, 2022, 12:30:59 am »
I'm using an Acer desktop running Win10/21H2, 12GB of RAM and a 512GB SSD drive. I did both of your suggestions and it used my downloaded snapshot from the link you gave. However, both faults are still present in that example but everything else run fine. I also discovered that LineWidth appears to be in millimeters. I noticed the type was Double so tried 0.5 and settled on 0.3. It also affected the size of the lines in the + mark.

Would like to be able to use multiple colors for the tracks as a hundred spot reports all in red is a little overwhelming. One method that comes to mind is to have maybe 16 versions of _LINE_ and sprinkle the spots randomly into these groups with each having a different color. Would that be feasible?

PS
ADrawer.TextWidth(APoint.Name); does not work either. It always returns zero. I tried 20 but it did not help. Is ADrawer.BrushStyle := bsClear; feasible. Maybe I can't see it because it's invisible.
 
« Last Edit: August 09, 2022, 12:39:15 am by Arctic_Eddie »

wp

  • Hero Member
  • *****
  • Posts: 10030
Re: LazMapViewer - Lines between realpoints
« Reply #11 on: August 09, 2022, 01:21:48 am »
The attached modified demo of the previous post contains your OnDrawGpsPoint handler (right-click somewhere to add a gps point) - it is working correctly for me (Win 11, 64bit, Laz main/fpc 3.2.2/64bit and 32 bit). Setting a breakpoint after the line w := ADrawer.TextWidth(APoint.Name) allows to read a non-zero TextWidth.

I am rather clueless now...

[EDIT]
Adding the forgotten project...
« Last Edit: August 09, 2022, 07:17:49 pm by wp »

Arctic_Eddie

  • Jr. Member
  • **
  • Posts: 91
Re: LazMapViewer - Lines between realpoints
« Reply #12 on: August 09, 2022, 01:38:49 am »
I don't see the attachment.

After attempting to run the earlier example, and fail, I get a crash even closing my form.

PS
I'm also using Laz 2.0.12. Perhaps that's the problem.
« Last Edit: August 09, 2022, 01:53:38 am by Arctic_Eddie »

Arctic_Eddie

  • Jr. Member
  • **
  • Posts: 91
Re: LazMapViewer - Lines between realpoints
« Reply #13 on: August 09, 2022, 07:07:17 pm »
I set a breakpoint at the Ellipse procedure then "Step-Into" to see where it was going. Strangely, it goes to intfbasewinapi.inc to this point.
Code: Pascal  [Select][+][-]
  1. function TWidgetSet.CreateFontIndirectEx(const LogFont: TLogFont;
  2.   const LongFontName: string): HFONT;
  3. begin
  4.   // this functions is needed, because the fontname in TLogFont is limited to
  5.   // 32 characters. If the interface does not support long font names, it can
  6.   // simple omit this function
  7.   Result := CreateFontIndirect(LogFont);
  8. end;
  9.  
Nothing makes any sense at that point and I wonder what fonts have to do with drawing an ellipse.

wp

  • Hero Member
  • *****
  • Posts: 10030
Re: LazMapViewer - Lines between realpoints
« Reply #14 on: August 09, 2022, 07:21:15 pm »
I don't see the attachment.
Sorry...  Added it to the previous post now.

I'm also using Laz 2.0.12. Perhaps that's the problem.
No. Installed the ccr-mapviewer version in Laz 2.0.12., and that mapviewer-line sample project is working correctly here, too (well... there is another issue because when the gps point title is painted over the map tile boundary it is overpainted by the neighbouring tile - but this is a different story.)

 

TinyPortal © 2005-2018