Firstly, please correct me if this is not the place to post WebOSMaps issues (I did scan the fora and could only find the WebGMaps headline.
Now to my issue: I am new to TMS Maps and have written a small testbed to help me find my way around the Component.
Under Delphi XE2 program control I set markers (from an Access Database of POI), then zoom to several coordinates, and save each ScreenShot as a PNG file. The problem is that I get several images (with the copyright notice embedded) and appropriate markers displayed, but no map details, i.e. a white background. Example attached.
I am thinking this is due to timing and that the map tiles take too long to load.
Any suggestions?
Cheers, Paul
Hi,
Thanks for the fast response, Bart.
I've tried this with my own App first, but have now replicated the problem within the WebOSMaps demo. The following code is attached to a button I added to the standard demo. I did try adding ProcessMessages with only partial success (see image). The code uses recursion to parse a quadtree, creating a map file at each level, and then generating four tiles from it, and so on until the maximum "depth of zoom" is reached. For the purposes of the demo version, I have stripped out the quadtree functionality, replacing it with simple calculations to define the centre of each map tile and zoomlevel.
Even with ProcessMessages none of the files is a complete image.
Cheers, Paul
procedure TFrmMain.BGenerateClick(Sender: TObject);
function GenerateActiveMap (Lat, Lon : Double; Zoom, MaxZoom : Integer; FilePath : String) : Boolean;
var
n : Integer;
LatNew, LonNew : Double;
FileName : String;
NewMap : Char;
Graphic: TGraphic;
begin
with WebOSMaps1 do begin
MapPanTo(Lat, Lon);
MapOptions.ZoomMap := Zoom;
// Application.ProcessMessages;
Graphic := WebOSMaps1.ScreenShot(itPng);
FileName := ChangeFileExt (ExtractFileName (FilePath), '');
if Trim(FileName) = '' then
FilePath := ExtractFilePath (FilePath) + 'index.png';
try
Graphic.SaveToFile(FilePath);
finally
Graphic.Free;
end;
end;
if Zoom >= MaxZoom then
Exit;
for n := 1 to 4 do begin
NewMap := Char ($60 + n);
case n of
1: begin
LatNew := Lat + 90 / (Zoom + 1);
LonNew := Lon - 180 / (Zoom + 1);
end;
2: begin
LatNew := Lat + 90 / (Zoom + 1);
LonNew := Lon + 180 / (Zoom + 1);
end;
3 : begin
LatNew := Lat - 90 / (Zoom + 1);
LonNew := Lon + 180 / (Zoom + 1);
end;
4 : begin
LatNew := Lat - 90 / (Zoom + 1);
LonNew := Lon - 180 / (Zoom + 1);
end;
end;
GenerateActiveMap (LatNew, LonNew, Zoom + 1, MaxZoom, ExtractFilePath (FilePath) + FileName + NewMap + '.png');
end;
end; {GenerateActiveMap}
var
MaxZoom : Integer;
begin
MaxZoom := 5;
with SavePictureDialog1 do begin
if Execute then begin
GenerateActiveMap (0.00, 0.00, 1, MaxZoom, ExtractFilePath (FileName));
end;
end;
end;
Image Link
Hi Paul,
Thanks for the analysis and conclusion, Bart. Makes sense...
I'd experimented with inserting a MessageDlg call between the "zoom" and the "screen shot", and it allows me to wait until the full image is present before saving the file. Not perfect but suffices for my "learning exercise".
Once I get into the full application (replacing MicroOLAP EasyMap VCL) I hope we'll have a more practical solution than "waiting for user input" :-)
Cheers, Paul