Recent

Author Topic: Lazmapviewer: cached files  (Read 778 times)

MarkMLl

  • Hero Member
  • *****
  • Posts: 8504
Lazmapviewer: cached files
« on: August 28, 2025, 11:11:48 am »
I have a form containing a map viewer, a treeview and a small number of extra panels (later populated by frames containing memos for status output), with extensive use of vertical and horizontal splitters to organise things.

I find that if I change the map source (e.g. OpenStreetMap to OpenTopoMap) or use the OS to delete the cached map tiles before the program starts, one of the splitters starts off in an "unexpected" position. So far I've not managed to track this down, but suspect that it's something to do with LMV and its designated client height and width.

This is on Linux with KDE and gtk2 using FPC 3.2.2. However I'm still on an old copy of Lazarus (2.2.6) so raise this as a general question rather than expecting a definite answer (and am definitely not expecting anybody to put effort into it on my behalf).

During the main form's creation handler, it sets the map source and then sets Active true. Is there any way to pause at this point and determine whether all tiles for the designated centre point and zoom have been successfully cached?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

wp

  • Hero Member
  • *****
  • Posts: 13210
Re: Lazmapviewer: cached files
« Reply #1 on: August 28, 2025, 04:47:28 pm »
suspect that it's something to do with LMV and its designated client height and width.
TMapView has no AutoSize property, i.e. keeps the size given to it by outside procedures.

During the main form's creation handler, it sets the map source and then sets Active true. Is there any way to pause at this point and determine whether all tiles for the designated centre point and zoom have been successfully cached?
There is no built-in way for that. Of course, nothing is impossible: Based on the Redraw method of the TMapViewerEngine you should write a procedure which calculates which tiles are needed for the current viewpoint; and then you should hook into the OnTiledownloaded event which files whenever a tile has been downloaded, and wait until all expected tiles are available.

Or, if you want it simpler, just use a global Sleep during which the MapView is hidden. On my system, a delay of 700 ms does not make a noticable flicker when a map of 1200x800 px appears.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   MapView1.Active := True;
  4.   Sleep(700);   // adjust so that no flicker of the map is visible when the form is displayed
  5. end;

MarkMLl

  • Hero Member
  • *****
  • Posts: 8504
Re: Lazmapviewer: cached files
« Reply #2 on: August 29, 2025, 09:03:29 am »
Thanks, much my conclusions. As you say that autosize (or whatever) is in a predecessor class.

This is really only cosmetic, and the possibilities- as I see them- are either to start at maximum-zoom with a delay to load the (known) number of tiles required (after which splitters etc. are set up) or to monitor the cache directory and pause until nothing is being written. In either case the risk of something going wrong due to e.g. the Internet connection being slow far outweighs the original problem.

Thanks for the confirmation that I wasn't overlooking anything obvious,

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018