Recent

Author Topic: TMapViewer  (Read 85367 times)

wp

  • Hero Member
  • *****
  • Posts: 7970
Re: TMapViewer
« Reply #135 on: May 16, 2020, 08:04:58 pm »
This is a very useful component and I could only try it out now. :( I even got it right to display points in different colours depending on the ELE value. But what I could not get right is to display the NAME as a label. I saw in the examples that there were some attempts with the ADrawer TextOut and TextExtent functions/procedures but they are not working and I guess therefore commented out. Trying to use them crash the application with lots of Access Violations. Anyone any other ideas on how one could display the labels?
It's been some time since I was in the depths of this component... Normally it is enough to "add" a TGpsPoint to the GpsItems of the MapView, and the drawing engine will take care of the drawing. This is the code from the demo program where a point can be marked by a right click:
Code: Pascal  [Select][+][-]
  1. procedure TMainForm.MapViewMouseUp(Sender: TObject; Button: TMouseButton;
  2.   Shift: TShiftState; X, Y: Integer);
  3. var
  4.   rPt: TRealPoint;
  5.   gpsPt: TGpsPoint;
  6.   gpsName: String;
  7. begin
  8.   if (Button = mbRight) then begin
  9.     if not InputQuery('Name of GPS location', 'Please enter name', gpsName) then
  10.       exit;
  11.     rPt := MapView.ScreenToLonLat(Point(X, Y));
  12.     gpsPt := TGpsPoint.CreateFrom(rPt);
  13.     gpsPt.Name := gpsName;
  14.     MapView.GpsItems.Add(gpsPt, _CLICKED_POINTS_);
  15.   end;
  16. end;

The points added this way are marked by a "+". If you assign a bitmap to the POIImage property of the MapView it will be drawn instead. However, there is even more. The TGpsPoint has a general property "ExtraData" which can be used for any purpose to provide further parameters how the POI is drawn. The package comes with the TDrawingExtraData in unit mvExtraData which provides access to the color of the POI and which is automatically respected by the map viewer. For additional parameters you must provide a handler for the OndrawGPSPoint event where you can read the extra data and draw a symbol accordingly.

Since this sounds maybe a bit complicated I just extended the demo project (in folder "examples") with complete routines for it, everything happens in the OnMouseUp and OnDrawGPSPoint events. Go to page "Config" of the demo and select "custom drawing" in the POI mode box. Then right-click somewhere in the map, a dialog will appear in which you can select how the POI is to be displayed.

The new version is in the trunk svn repository of ccr, or, if you do not use svn, download the snapshot from https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/lazmapviewer/. It is NOT yet available through OPM.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Adromir

  • New member
  • *
  • Posts: 6
Re: TMapViewer
« Reply #136 on: May 20, 2020, 03:22:26 pm »
I was trying to Install the TMapViewer to my Lazarus Installation but I havent been really succesfull to do so. First I went to an error, that the Package couldnt be compiled due to a missing Unit, which I solved by Adding FCL to the Package dependencies. But Now I am trying to open the Demo project and all I am getting is "Can't find component class TMVGeoName. It wasn't registered by RegisterClass and no lfm was found". Can someone please help me to solve this? Installing via OPM also fails because of the Missing FCL dependency

wp

  • Hero Member
  • *****
  • Posts: 7970
Re: TMapViewer
« Reply #137 on: May 20, 2020, 03:27:21 pm »
I hope you are talking about the LazMapViewer package, there are others on which LazMapViewer is based but they are outdated and not maintained.

The easiest way to install the package is to open Online Package Manage (from the Package menu), scroll down a bit and check the "LazMapViewer" item, click install, follow the instructions and wail until the IDE is rebuilt and restarted.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

sstvmaster

  • Full Member
  • ***
  • Posts: 190
Re: TMapViewer
« Reply #138 on: May 20, 2020, 06:45:15 pm »
The same error here with 2.0.8/3.0.4, tried to install via OPM.

Edit:  Also with fixes/fixes.
« Last Edit: May 20, 2020, 06:52:36 pm by sstvmaster »
Windows 10 (64 bit)
Lazarus: 2.0.10 / Trunk x32

wp

  • Hero Member
  • *****
  • Posts: 7970
Re: TMapViewer
« Reply #139 on: May 20, 2020, 08:05:33 pm »
Yes, the new package structure again... I uploaded a fix to CCR (https://sourceforge.net/projects/lazarus-ccr/files/LazMapViewer/lazmapviewer-v0.2.2.1.zip/download) and asked GetMem to update the version in OPM.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

sstvmaster

  • Full Member
  • ***
  • Posts: 190
Re: TMapViewer
« Reply #140 on: May 20, 2020, 08:40:36 pm »
Thanks wp, manual installation works fine, thumbs up!
Windows 10 (64 bit)
Lazarus: 2.0.10 / Trunk x32

wp

  • Hero Member
  • *****
  • Posts: 7970
Re: TMapViewer
« Reply #141 on: May 20, 2020, 10:17:21 pm »
As GetMem wrote in the OPM thread, the new version is now distributed by OPM as well.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Adromir

  • New member
  • *
  • Posts: 6
Re: TMapViewer
« Reply #142 on: May 21, 2020, 12:00:12 am »
Thank you, installing and using it works like a charm now. Just wondering, is it possible to draw a circle on the map around a location with a certain radius? That would be exactly the feature I need for my project

mpknap

  • Full Member
  • ***
  • Posts: 155
Re: TMapViewer
« Reply #143 on: October 07, 2020, 06:04:31 pm »
How to load and display coordinates on map,  from SQLITE file?
« Last Edit: October 07, 2020, 06:08:56 pm by mpknap »

cpalx

  • Hero Member
  • *****
  • Posts: 647
Re: TMapViewer
« Reply #144 on: October 07, 2020, 07:00:53 pm »
@mpknap

you hace some examples in the same directory of Tmapviwer files

mpknap

  • Full Member
  • ***
  • Posts: 155
Re: TMapViewer
« Reply #145 on: October 07, 2020, 08:03:49 pm »
@mpknap

you hace some examples in the same directory of Tmapviwer files

I can't see anything from DB / SQLITE there. Are we writing about it?
https://sourceforge.net/projects/lazarus-ccr/files/LazMapViewer/

wp

  • Hero Member
  • *****
  • Posts: 7970
Re: TMapViewer
« Reply #146 on: October 07, 2020, 09:46:44 pm »
You are right, the sample application does work with a database. But it shows how you can draw a marker at given coorindates in the map. So, you only must extract your coordinates from the database and follow the sample code.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

mpknap

  • Full Member
  • ***
  • Posts: 155
Re: TMapViewer
« Reply #147 on: October 08, 2020, 10:42:30 am »
You are right, the sample application does work with a database. But it shows how you can draw a marker at given coorindates in the map. So, you only must extract your coordinates from the database and follow the sample code.

this work fine and dispaly points :
Code: Pascal  [Select][+][-]
  1. procedure TMainForm.Button1Click(Sender: TObject);
  2.  var
  3.   ds: TDataset;
  4.   team,latt, lonn: TField;
  5.   x, y: double;
  6.   gpsPt: TGpsPoint;
  7.   a,b : string;
  8. begin
  9.   SQLQuery1.SQL.Clear;
  10.   dbgrid1.Clear;
  11.   SQLite3Connection1.DatabaseName :=
  12.     'C:\DataCenter\Data\AF_2019_01_0101_00_00do2019_01_0215_38_08.sqlite';
  13.   SQLite3Connection1.Connected := True;
  14.   SQLTransaction1.DataBase := SQLite3Connection1;
  15.   SQLQuery1.DataBase := SQLite3Connection1;
  16.   SQLQuery1.PacketRecords := 500000;
  17.  
  18.   SQLTransaction1.Active := True;
  19.  
  20.   SQLQuery1.SQL.Text := 'SELECT latitude,lonngitude, user_id from detections ';
  21.   SQLQuery1.Close;
  22.   SQLQuery1.Open;
  23.   DataSource1.DataSet := SQLQuery1;
  24.  
  25.   DBGrid1.DataSource := DataSource1;
  26.   DBGrid1.AutoFillColumns := true;
  27.  
  28.   ds := DBGrid1.Datasource.Dataset;
  29.   ds.DisableControls;
  30.  
  31.   try
  32.     latt := ds.FieldByName('latitude').;
  33.     lonn := ds.FieldByName('lonngitude');
  34.  
  35.     team := ds.FieldByName('user_id');
  36.     ds.First;
  37.     while not ds.EOF do
  38.     begin
  39.        gpsPt := TGpsPoint.Create(strtofloat(stringReplace(lonn.AsString, '.', ',',
  40.        [rfReplaceAll])), strtofloat(stringReplace(latt.AsString, '.',      ',', [rfReplaceAll])));
  41.  
  42.        gpsPt.Name := team.AsString;
  43.         MapView.GpsItems.Add(gpsPt, 0);
  44.        ds.Next;
  45.     end;
  46.     a:=ds.FieldByName();
  47.   finally
  48.  
  49.     ds.EnableControls;
  50.   end;
  51. end;  


« Last Edit: October 09, 2020, 09:33:40 pm by mpknap »

sstvmaster

  • Full Member
  • ***
  • Posts: 190
Re: TMapViewer
« Reply #148 on: December 19, 2020, 08:09:11 pm »
Error in "example_with_addons": LazRGBGraphics not found. It is available here: https://sourceforge.net/projects/lazarus-ccr/files/LazRGBGraphics/ but very old.

Tested with Laz 2.0.10 and Trunk (r64230)
Windows 10 (64 bit)
Lazarus: 2.0.10 / Trunk x32

wp

  • Hero Member
  • *****
  • Posts: 7970
Re: TMapViewer
« Reply #149 on: December 19, 2020, 09:45:57 pm »
Oh, I think I understand. Recently I had to set up my new computer and noticed that the rgbgraphics package needed by MapViewer was not found. I thought that the development version is the one on ccr and I selected it without thinking... Your comment reminds me that there is another version, and now I know that it is in OPM with a different name. What a mess!

Since OPM is the primary package source now I think I should revert it to the OPM name. But on the other hand where does this OPM version come from? I am pretty sure that it is a CodeTyphon import because there are "ct9999" comments in two files. Luckily the files are identical except for two little changes in the non-ccr versions which easily can be merged.

So, what to do? The problem is that there are two packages with the same content but different names. The one on the popular OPM server is from a source to which we do not have access. I'd prefer to replace this package by the one from ccr which we can maintain although the package seems to be abondoned by its original author. This will present users with package not found errors, however. On the other hand, rgbgraphics is a runtime package and needs no installation. I am rather sure that it should be possible to distribute both packages in OPM. I'll have to contact GetMem...
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

 

TinyPortal © 2005-2018