Recent

Author Topic: TMapViewer  (Read 82126 times)

sstvmaster

  • Full Member
  • ***
  • Posts: 167
Re: TMapViewer
« Reply #105 on: April 28, 2019, 08:35:16 pm »
@wp thanks.

And i have found an bug in my TGPSListViewer.BtnCalcDistanceClick procedure.
If delete an entry in list the calculation is wrong because the list entries does not match
the actual list.

Code: Pascal  [Select][+][-]
  1. procedure TGPSListViewer.BtnCalcDistanceClick(Sender: TObject);
  2. type
  3.   TCoorRec = record
  4.     Lon: Double;
  5.     Lat: Double;
  6.     Name: String;
  7.   end;
  8. var
  9.   i, iChecked: Integer;
  10.   rPt: TRealPoint;
  11.   TCoorArr: array[0..1] of TCoorRec;
  12.   item: TListItem;
  13. begin
  14.   // count checked items
  15.   iChecked := 0;
  16.   for i:=0 to ListView.Items.Count - 1 do begin
  17.     if ListView.Items.Item[i].Checked then Inc(iChecked);
  18.   end;
  19.   //
  20.   if iChecked <> 2 then begin
  21.     ShowMessage('Please select 2 items to calculate the distance.');
  22.   end
  23.   else begin
  24.     iChecked := 0;
  25.     for i:=0 to ListView.Items.Count - 1 do begin
  26.       if ListView.Items.Item[i].Checked then begin
  27.         item := ListView.Items[i];
  28.         if TryStrToGps(item.SubItems[2], rPt.Lon) and TryStrToGps(item.SubItems[1], rPt.Lat) then
  29.         begin
  30.           TCoorArr[iChecked].Lon := rPt.Lon;
  31.           TCoorArr[iChecked].Lat := rPt.Lat;
  32.           TCoorArr[iChecked].Name:= item.SubItems[0];
  33.           Inc(iChecked);
  34.         end;
  35.       end;
  36.     end;
  37.     // show distance between selected items
  38.     ShowMessage('Distance between ' + TCoorArr[0].Name + ' and ' + TCoorArr[1].Name + ' is: ' +
  39.     Format('%.2n %s.', [
  40.       CalcGeoDistance(
  41.         TCoorArr[0].Lat,
  42.         TCoorArr[0].Lon,
  43.         TCoorArr[1].Lat,
  44.         TCoorArr[1].Lon,
  45.         DistanceUnit
  46.       ),
  47.       DistanceUnit_Names[DistanceUnit]
  48.       ]));
  49.   end;
  50. end;
  51.  
Windows 10 (64 bit)
Lazarus: 2.0.10 / Trunk x32

sstvmaster

  • Full Member
  • ***
  • Posts: 167
Re: TMapViewer
« Reply #106 on: April 28, 2019, 10:41:11 pm »
@wp
1.
In mvmapviewer.pas, line 165 to 217, is CopyPixels really needed as you have fixed this?

2.
could this help to fix MacOS?

mvMapViewer.pas from line 794:
Code: Pascal  [Select][+][-]
  1.   {$IFDEF WINDOWS}
  2.   //rawImg.Description.Init_BPP24_B8G8R8_BIO_TTB(AWidth, AHeight);
  3.   rawImg.Description.Init_BPP32_B8G8R8_BIO_TTB(AWidth, AHeight);
  4.   {$ELSE}
  5.   rawImg.Description.Init_BPP32_A8R8G8B8_BIO_TTB(AWidth, AHeight);
  6.   {$ENDIF}
  7.  
« Last Edit: April 28, 2019, 10:43:20 pm by sstvmaster »
Windows 10 (64 bit)
Lazarus: 2.0.10 / Trunk x32

wp

  • Hero Member
  • *****
  • Posts: 7529
Re: TMapViewer
« Reply #107 on: April 28, 2019, 11:11:39 pm »
And i have found an bug in my TGPSListViewer.BtnCalcDistanceClick procedure.
If delete an entry in list the calculation is wrong because the list entries does not match
the actual list.
Fixed.

In mvmapviewer.pas, line 165 to 217, is CopyPixels really needed as you have fixed this?
The comment and bugtracker say that it is a workaround for a bug fixed after 1.8.4, i.e. the first release version having the fix must be Laz 2.0.0. This is too near for removal - otherwise all users having older versions are excluded from LazMapViewer. Look here in the forum at all the Linux users forced by their distro to ancient versions, and when a fix is already in the source there is really no reason to force them to an upgrade.

Quote
could this help to fix MacOS?

mvMapViewer.pas from line 794:
Code: Pascal  [Select][+][-]
  1.   {$IFDEF WINDOWS}
  2.   //rawImg.Description.Init_BPP24_B8G8R8_BIO_TTB(AWidth, AHeight);
  3.   rawImg.Description.Init_BPP32_B8G8R8_BIO_TTB(AWidth, AHeight);
  4.   {$ELSE}
  5.   rawImg.Description.Init_BPP32_A8R8G8B8_BIO_TTB(AWidth, AHeight);
  6.   {$ENDIF}
  7.  
I don't have access to a Mac, so I cannot check. Again: Any help is welcome, I cannot focus too much on this component. And there's still the issue with the memory leak once the viewport is dragged or the zoom has been changed (https://forum.lazarus.freepascal.org/index.php/topic,12674.msg307870.html).
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

sstvmaster

  • Full Member
  • ***
  • Posts: 167
Re: TMapViewer
« Reply #108 on: April 28, 2019, 11:55:10 pm »
i know that about the memory leak, i'll try to solve it. thanks again.
Windows 10 (64 bit)
Lazarus: 2.0.10 / Trunk x32

VTwin

  • Hero Member
  • *****
  • Posts: 927
  • Former Turbo Pascal 3 user
Re: TMapViewer
« Reply #109 on: April 29, 2019, 05:23:43 pm »
2.
could this help to fix MacOS?

mvMapViewer.pas from line 794:
Code: Pascal  [Select][+][-]
  1.   {$IFDEF WINDOWS}
  2.   //rawImg.Description.Init_BPP24_B8G8R8_BIO_TTB(AWidth, AHeight);
  3.   rawImg.Description.Init_BPP32_B8G8R8_BIO_TTB(AWidth, AHeight);
  4.   {$ELSE}
  5.   rawImg.Description.Init_BPP32_A8R8G8B8_BIO_TTB(AWidth, AHeight);
  6.   {$ENDIF}
  7.  

Yes, that did the trick. Thanks!

The Google Hybrid/Physical maps are displaying very dark, almost black. The Ovi maps throw an ESocketError exception: 'Host name resolution for \"c.maptile.maps.svc.ovi.com\" failed'. Maybe a cross-platform path error?

All the rest of the maps display fine. :)

« Last Edit: April 29, 2019, 05:27:13 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

macOS 10.13.6: Lazarus 2.0.8 (64 bit Cocoa, also fixes and trunk)
Ubuntu 18.04.3: Lazarus 2.0.8 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.8 (64 bit on VBox)

wp

  • Hero Member
  • *****
  • Posts: 7529
Re: TMapViewer
« Reply #110 on: April 29, 2019, 05:32:28 pm »
Good.

I discovered the Google maps recently, the black maps seem to be overlays of the base maps. Could not yet figure out how to accomplish this.

The OviMaps links are outdated. They refer to Nokia maps which no longer exist. I should remove them from the code.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

VTwin

  • Hero Member
  • *****
  • Posts: 927
  • Former Turbo Pascal 3 user
Re: TMapViewer
« Reply #111 on: April 29, 2019, 05:59:22 pm »
Good.

I discovered the Google maps recently, the black maps seem to be overlays of the base maps. Could not yet figure out how to accomplish this.

The OviMaps links are outdated. They refer to Nokia maps which no longer exist. I should remove them from the code.

Got it. Thanks for the info.

Ah yes, I remember deleting the Nokia url from my code a while back. I use a very simple scheme to display lat, lon locations by opening browser urls for: acme, bing, google, here, openstreetmap, and wikimapia. It works pretty well, but TMapViewer is way cooler.  8-)

Edit: I think Nokia is now Here (https://wego.here.com/).
« Last Edit: April 29, 2019, 06:18:58 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

macOS 10.13.6: Lazarus 2.0.8 (64 bit Cocoa, also fixes and trunk)
Ubuntu 18.04.3: Lazarus 2.0.8 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.8 (64 bit on VBox)

wp

  • Hero Member
  • *****
  • Posts: 7529
Re: TMapViewer
« Reply #112 on: April 29, 2019, 07:51:35 pm »
I think Nokia is now Here (https://wego.here.com/).
Fine. But the problem is that we need to find out the exact url to these maps including the conventions how to provide longitude, latitude and zoom level. See TMapViewerEngine.RegisterProviders:
Code: Pascal  [Select][+][-]
  1.   AddMapProvider('Ovi Normal',
  2.     'http://%serv%.maptile.maps.svc.ovi.com/maptiler/v2/maptile/newest/normal.day/%z%/%x%/%y%/256/png8',
  3.     0, 20, 5, @GetLetterSvr);  
where %serv%, %x%, %y%, %z% are replaced by service-specific parameters for server, x (longitude), y (latitude) and zoom label

Google maps, for example, are downloaded by this URL: 'http://mt0.google.com/vt/lyrs=m@145&v=w2.104&x=1203&y=1538&z=12'

could this help to fix MacOS?

mvMapViewer.pas from line 794:
Code: Pascal  [Select][+][-]
  1.   {$IFDEF WINDOWS}
  2.   //rawImg.Description.Init_BPP24_B8G8R8_BIO_TTB(AWidth, AHeight);
  3.   rawImg.Description.Init_BPP32_B8G8R8_BIO_TTB(AWidth, AHeight);
  4.   {$ELSE}
  5.   rawImg.Description.Init_BPP32_A8R8G8B8_BIO_TTB(AWidth, AHeight);
  6.   {$ENDIF}
  7.  
Yes, that did the trick.

A very simple question to you: What is the define to identify Mac? The code above crashes Linux which does not like the Alpha channel byte.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

VTwin

  • Hero Member
  • *****
  • Posts: 927
  • Former Turbo Pascal 3 user
Re: TMapViewer
« Reply #113 on: April 29, 2019, 08:36:54 pm »
I think Nokia is now Here (https://wego.here.com/).
Fine. But the problem is that we need to find out the exact url to these maps including the conventions how to provide longitude, latitude and zoom level. See TMapViewerEngine.RegisterProviders:
Code: Pascal  [Select][+][-]
  1.   AddMapProvider('Ovi Normal',
  2.     'http://%serv%.maptile.maps.svc.ovi.com/maptiler/v2/maptile/newest/normal.day/%z%/%x%/%y%/256/png8',
  3.     0, 20, 5, @GetLetterSvr);  
where %serv%, %x%, %y%, %z% are replaced by service-specific parameters for server, x (longitude), y (latitude) and zoom label

Google maps, for example, are downloaded by this URL: 'http://mt0.google.com/vt/lyrs=m@145&v=w2.104&x=1203&y=1538&z=12'

A very simple question to you: What is the define to identify Mac? The code above crashes Linux which does not like the Alpha channel byte.

Is this helpful? Tab delimited list of some I found:

Code: Pascal  [Select][+][-]
  1. MapURLs =
  2.     'http://mapper.acme.com/?ll=%s,%s&z=15&t=T' + cTab +
  3.     'http://bing.com/maps/default.aspx?cp=%s~%s&lvl=15&style=h' + cTab +
  4.     'https://copernix.io/#?where=%s,%s,14&?query=&?map_type=roadmap' + cTab +
  5.     'https://copernix.io/#?where=%s,%s,14&?query=&?map_type=hybrid' + cTab +
  6.     'http://maps.google.com/maps?ll=%s,%s&z=16&t=h' + cTab +
  7.     'http://maps.google.com/maps?ll=%s,%s&z=16&t=p' + cTab +
  8.     'https://wego.here.com/location/?map=%s,%s,15,satellite' + cTab +
  9.     'https://www.mapquest.com/latlng/%s,%s?zoom=14&maptype=map'  + cTab +
  10.     'https://www.mapquest.com/latlng/%s,%s?zoom=14&maptype=sat' + cTab +
  11.     'https://www.openstreetmap.org/?#map=15/%s/%s&layers=Q' + cTab +
  12.     'https://www.waze.com/livemap/?zoom=14&lat=%s&lon=%s' + cTab +
  13.     'http://wikimapia.org/#lat=%s&lon=%s&z=15&m=b';

The zoom levels are fixed (14 to 16), but easy enough to change. Note that copernix uses [%s,%s] = [lon,lat], the rest are [lat,lon]. All decimal degrees.

{$IFDEF DARWIN}

I don't follow the AddMapProvider format at the moment, but I'll take a closer look at the code.

EDIT: I guess now that the above urls are not helpful. :( I'll try to poke around for something useful.
« Last Edit: April 29, 2019, 10:10:27 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

macOS 10.13.6: Lazarus 2.0.8 (64 bit Cocoa, also fixes and trunk)
Ubuntu 18.04.3: Lazarus 2.0.8 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.8 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 927
  • Former Turbo Pascal 3 user
Re: TMapViewer
« Reply #114 on: April 29, 2019, 11:15:46 pm »
I recall looking into the Google Maps api quite a few years ago, when they were making it freely available. At some point they tightened up access, and they may be rather sticky now:

https://developers.google.com/maps/faq?csw=1#tos_tiles

and may require an api key. Is there any chance that Google is blocking by blacking out the satellite image?

OpenStreetMap is friendly, but still has restrictions on use of their servers: 

https://operations.osmfoundation.org/policies/tiles/

I guess any end application would have to look closely at the legalese. :(

« Last Edit: April 29, 2019, 11:55:50 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

macOS 10.13.6: Lazarus 2.0.8 (64 bit Cocoa, also fixes and trunk)
Ubuntu 18.04.3: Lazarus 2.0.8 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.8 (64 bit on VBox)

avra

  • Hero Member
  • *****
  • Posts: 2000
    • Additional info
Re: TMapViewer
« Reply #115 on: April 29, 2019, 11:30:19 pm »
OpenStreetMap is friendly, but still has restrictions on use of their servers
You can download OSM maps and render them locally. You can not do that with Google Maps.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

VTwin

  • Hero Member
  • *****
  • Posts: 927
  • Former Turbo Pascal 3 user
Re: TMapViewer
« Reply #116 on: April 29, 2019, 11:49:37 pm »
OpenStreetMap is friendly, but still has restrictions on use of their servers
You can download OSM maps and render them locally. You can not do that with Google Maps.

It looks to me that TMapViewer downloads rendered tiles though, as opposed to vector and raster data. Is that not the case?
« Last Edit: April 29, 2019, 11:52:07 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

macOS 10.13.6: Lazarus 2.0.8 (64 bit Cocoa, also fixes and trunk)
Ubuntu 18.04.3: Lazarus 2.0.8 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.8 (64 bit on VBox)

wp

  • Hero Member
  • *****
  • Posts: 7529
Re: TMapViewer
« Reply #117 on: April 30, 2019, 12:04:51 am »
Yes. You can find them as png in the cache folder of the demo application.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

VTwin

  • Hero Member
  • *****
  • Posts: 927
  • Former Turbo Pascal 3 user
Re: TMapViewer
« Reply #118 on: April 30, 2019, 12:07:41 am »
Yes. You can find them as png in the cache folder of the demo application.

Nice!
“Talk is cheap. Show me the code.” -Linus Torvalds

macOS 10.13.6: Lazarus 2.0.8 (64 bit Cocoa, also fixes and trunk)
Ubuntu 18.04.3: Lazarus 2.0.8 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.8 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 927
  • Former Turbo Pascal 3 user
Re: TMapViewer
« Reply #119 on: April 30, 2019, 12:11:03 am »
This may not be useful, as you have already included such a function, but this is a slightly different distance function I use:

Code: Pascal  [Select][+][-]
  1. { LatLongToDistance
  2.   Uses the Haversine formula to calculate the great-circle distance between
  3.   two points. Bearing is the initial bearing. Uses mean spherical earth radius.
  4.   Distance is in meters, angles are in radians. Earth model is FAI (Fédération
  5.   Aéronautique Internationale) Sphere.
  6.   Ref:
  7.     http://www.movable-type.co.uk/scripts/latlong.html
  8.     http://edwilliams.org/gccalc.htm}
  9. procedure LatLongToDistance(const lat0, long0, lat1, long1: double;
  10.   var dist, bearing: double);
  11. var
  12.   R: double = 6371000.0; // Earth radius in meters
  13.   dlat, dlong, slat, slong, a, c, x, y: double;
  14. begin
  15.   // dist
  16.   dlat := lat1 - lat0;
  17.   dlong := long1 - long0;
  18.   slat := Sin(0.5 * dlat);
  19.   slong := Sin(0.5 * dlong);
  20.   a := slat * slat + Cos(lat0) * Cos(lat1) * slong * slong;
  21.   c := 2.0 * ArcTan2(Sqrt(a), Sqrt(1.0-a));
  22.   dist := R * c;
  23.   // bearing
  24.   y := Sin(dlong) * Cos(lat1);
  25.   x := Cos(lat0) * Sin(lat1) - Sin(lat0) * Cos(lat1) * Cos(dlong);
  26.   bearing := ArcTan2(y, x);
  27. end;    

« Last Edit: April 30, 2019, 12:26:28 am by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

macOS 10.13.6: Lazarus 2.0.8 (64 bit Cocoa, also fixes and trunk)
Ubuntu 18.04.3: Lazarus 2.0.8 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.8 (64 bit on VBox)

 

TinyPortal © 2005-2018