Recent

Author Topic: LazMapViewer - use for Tracking  (Read 10262 times)

Adie

  • New Member
  • *
  • Posts: 13
LazMapViewer - use for Tracking
« on: September 28, 2021, 04:37:09 pm »
Hi All
Been using Lazarus for about 2 years now and very rarely (almost never) visit the forum.  I now want to develop a Vehicle Tracking add-on for my application.

Short overview.
The software manage Ready-Mixed Concrete production from Quote to Invoice.  The Admin part is still written in C++ but the Batching module that interface with the panel and scales manage the full batch process via 'recipe's' that are executed via the FastScript scripting engine.  I already used this in C++ so the port was quick and easy.  If I remember correctly I had some issues with the RemObjects Pascalscript.  The system basically reads the the panel 60 times per second and then update the ports on the PLC to start/stop the motors etc.etc.

The next step is to add a Truck tracking module to assist the batcher in planning the work.

I did a quick test with LazMapViewer and it seems as if it could become a very neat tracking system.  I no not need to do any routing (yet - hopefully never).

The requirement.
The system must trace the trucks as it receive the real time data and move the truck. We need to show more than one truck but only need to display one track at a time to keep the screen clear. We will do all deviations efficiencies etc directly from the 'gpx' created from the data separately.

There are some other requirements but it should be doable if the issues below can be resolved.

What I can not figure out to do:

A.  I need to click on a point to create an unique POI like Plant, Site etc with different pictures.  Mostly fixed POI's
B.  I need to click on an POI or Truck 'Image' to open additional info (Like the Right click in the sample but it must not keep creating new POIs)
C.  A 'Hint' must pop up if the mouse hover over the POI for quick user info.

In essence this all boils down to the the fact that there must be various images in an 'image list' ? and these images must be 'mouse accessible'.

Any ideas will be welcome.

Adie

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: LazMapViewer - use for Tracking
« Reply #1 on: September 28, 2021, 05:05:50 pm »
I had worked on an integrated imagelist recently, but I am not sure whether it was introduced at the right place. Let me think about it again. In the final solution, I think, TMapView should have an Images property, and the POI points will should an ImageIndex. The problem is only whether the points of a track should have that feature, too.

Adie

  • New Member
  • *
  • Posts: 13
Re: LazMapViewer - use for Tracking
« Reply #2 on: September 28, 2021, 07:22:40 pm »
Tx WP

In my books I always try to get the BASICs done and then do the 'Lipstiffy and Eyeshadow'.  This does not mean that the one is more important than the other but it ensure more reachable 'milestones'.  As the project progress the needs will shift as well. So the 'L&E' can go from Punk to Goth without sacrificing the underlying .......

Maybe the first thing is to decide where LazMapV is heading and what the developer (you?) want to achieve with the product.  At this point I can not see what the end goal was by looking at the samples. 

I think it will be a very usable base product for many projects if it can have different clickable POIs.  I am not sure about the need to add images to a Track. Color, YES.  Not sure if the map can handle multiple (selectable) tracks.  will look around later.

A

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: LazMapViewer - use for Tracking
« Reply #3 on: September 28, 2021, 07:30:57 pm »
Maybe the first thing is to decide where LazMapV is heading and what the developer (you?) want to achieve with the product.  At this point I can not see what the end goal was by looking at the samples. 
Don't ask me for my goals - there are none. I took over the project because it looked interesting and was abandoned by its original authors. I am adding things which look interesting to me and most of what is requested by users.

Adie

  • New Member
  • *
  • Posts: 13
Re: LazMapViewer - use for Tracking
« Reply #4 on: September 28, 2021, 08:07:12 pm »
GREAT, lets keep it simple then.

Give me pointers on how the get the POIs clickable and the link to Imagelist. 

That will do for me.  :D

A

Adie

  • New Member
  • *
  • Posts: 13
Re: LazMapViewer - use for Tracking
« Reply #5 on: September 28, 2021, 10:30:45 pm »
Hi wp

Based on the wiki:
<ExtraData can be used freely, for example to define the color of a track. An example how this could be done is found in unit mvExtraData, classes TDrawingExtraData and TTrackExtraData.>

If I try to set the color the app crash and the debugger tell me that ExtraData does not exist.

***** Code snip ****
procedure TGpxReader.ReadTrackSegment(ANode: TDOMNode; ATrack: TGpsTrack);
var
  gpsPt: TGpsPoint;
  nodeName: String;
begin
  gpsPt.ExtraData.Create();
  while ANode <> nil do begin
    nodeName := ANode.NodeName;
    if nodeName = 'trkpt' then begin
      gpsPt := ReadPoint(ANode);
// ** my code **
     with TDrawingExtraData( gpsPt.ExtraData) do begin
        Color := clRed;
     end;
// ** end **
      if gpsPt <> nil then
        ATrack.Points.Add(gpsPt);
    end;
    ANode := ANode.NextSibling;
  end;
end;
*** End***

Please note: I have no idea what I am doing.  First I just want to understand the lib to create tracks with different colors.

A




avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: LazMapViewer - use for Tracking
« Reply #6 on: September 29, 2021, 12:58:07 am »
The next step is to add a Truck tracking module
A little off topic, but if you are familiar with J1939 and SocketCAN, then you can read GPS and other real time data from truck it self, without a need for additional GPS device.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: LazMapViewer - use for Tracking
« Reply #7 on: September 29, 2021, 01:08:41 am »
I'm trying to extend the TGPSTrack with properties for line color and line width so that the ExtraData field is not needed. Give me some time.

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: LazMapViewer - use for Tracking
« Reply #8 on: September 29, 2021, 05:16:40 pm »
In the new version on CCR, you can specify a line color and line width (in millimeters) for each GpsTrack as properties LineColor and LineWidth, respectively. There's also a new sample project, ColoredTracks_Demo, which demonstrates how to use them.

Get the new version from svn, or download the snapshot from https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/lazmapviewer/.

Adie

  • New Member
  • *
  • Posts: 13
Re: LazMapViewer - use for Tracking
« Reply #9 on: September 29, 2021, 06:20:23 pm »
Hi Tanks but the NEW Color sample is not working.

Project file broken and if I try to include main in new project App just Hang before the Main Window is painted.

A

Adie

  • New Member
  • *
  • Posts: 13
Re: LazMapViewer - use for Tracking
« Reply #10 on: September 29, 2021, 06:28:41 pm »
Ok, I got it going.  The GPX was in the wrong place for the Color demo.

A

Adie

  • New Member
  • *
  • Posts: 13
Re: LazMapViewer - use for Tracking
« Reply #11 on: September 29, 2021, 06:32:25 pm »
Hi
OK, some other issues.  See my comment below with Adie inline.

procedure TMainForm.LoadGPXSampleFile;
const
  GPX_FILE_NAME = 'grand_canyon_trail.gpx';      // <<=====Adie====== Copied file to same folder
  // file 972150.gpx from https://www.summitpost.org/grand-canyon-in-a-day/972150
var
  reader: TGpxReader;
  b: TRealArea;
  i: Integer;
  id: Integer;
begin
  reader := TGpxReader.Create;
  try
    id := reader.LoadFromFile(GPX_FILE_NAME, MapView.GPSItems, b);

    FTrack := MapView.GpsItems.FindTrackByID(id);   // <<<======= Adie==== GPXITEMS ??

** End **


Adie

  • New Member
  • *
  • Posts: 13
Re: LazMapViewer - use for Tracking
« Reply #12 on: September 29, 2021, 06:38:06 pm »
Hi
I tried the same by just calling [ MapView.DefaultTrackColor ] and it did not work as desired because the 'engine' call the 'paint track' or something many times and does not allow two tracks with different colors.  All tracks change to the new color.

will do some test with the new lib.


 ********** Your code *********
procedure TMainForm.clbTrackColorChange(Sender: TObject);
begin
  MapView.DefaultTrackColor := clbTrackColor.Selected;
  { or:
  if FTrack <> nil then
  begin
    FTrack.LineColor := clbTrackColor.Selected;
    MapView.Engine.Redraw;
  end;
  }
end;
*** Your code ****



wp

  • Hero Member
  • *****
  • Posts: 11853
Re: LazMapViewer - use for Tracking
« Reply #13 on: September 29, 2021, 07:03:43 pm »
Sorry, I got confused because I also had a previous version of this demo on my disk, and committed the wrong version.

The delay when the program starts is not a hang but is caused by thread-support being turned off in these track demos. This is because the image is painted in tiles, and with thread-support it is possible that parts of the track are over-painted by another tile - quite confusing. I am sure this can be fixed by someone with experience in threads - patches are gladly accepted.

DefaultTrackColor is the standard color of a track. It is used by all tracks unless they provide their own color in Track.LineColor. In order to use individual track colors you must

- store the return value of the LoadFromFile method of the gpx reader; it is the ID of the track in the mapviewers list of GPSItems.
- use the new method FindTrackByID to find the track with this ID among the GPSItems. This returns the TGpsTrack instance loaded by the reader.
- set the LineColor of this object, and set its LineWidth (which is in millimeters, unlike the MapView.DefaultTrackWidth which is in pixels).

All this is shown in TMainForm.LoadGpxFile of the coloredtracks_demo.

loaded

  • Hero Member
  • *****
  • Posts: 824
Re: LazMapViewer - use for Tracking
« Reply #14 on: September 29, 2021, 07:35:06 pm »
I think wp is right about the thread. My guess is; With Imageview, yarn and Indy trio, a speed close to the display speed of leaflet running on the web can be achieved.
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

 

TinyPortal © 2005-2018