Recent

Author Topic: TMapViewer  (Read 82035 times)

wp

  • Hero Member
  • *****
  • Posts: 7517
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: 7517
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: 167
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: 7517
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: 167
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: 7517
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

 

TinyPortal © 2005-2018