Recent

Author Topic: TMapViewer  (Read 103536 times)

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: TMapViewer
« Reply #75 on: January 23, 2019, 03:23:51 pm »
The proxy parameters are accessible via the DownloadEngine. This is a public property of the MapView component. However, it is returned only as its fundamental type, TMvCustomDownloadEngine. TMapView creates an instance of TMvDEFpc which has the proxy properties. So, I think casting the DownloadEngine to TMvDEFpc should work:

Code: Pascal  [Select][+][-]
  1. uses
  2.   mvDLEFpc;
  3.  
  4. procedure TForm1.FormCreate(Sender: TObject);
  5. begin
  6.   with TMvDEFpc(MapView1.DownloadEngine do begin
  7.     UseProxy := true;
  8.     ProxyHost := ...
  9.     ProxyPort := ...
  10.     ProxyUsername := ...
  11.     ProxyPassword := ...
  12.   end;
  13. end;

Note that this code requires at least fpc 3.2 or fpc trunk.

WimVan

  • Jr. Member
  • **
  • Posts: 85
Re: TMapViewer
« Reply #76 on: January 23, 2019, 05:25:19 pm »
Thanks, but I only have FC 3.0.4
I'll have to wait till the next update of Lazarus

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: TMapViewer
« Reply #77 on: January 23, 2019, 07:45:35 pm »
In the new revision on CCR, I published the property DownloadEngine and added a new package which contains the download engine based on Synapse. You can put a TMvDESynapse on the form and link it to the DownloadEngine property of the MapViewer. This new DownloadEngine exposes proxy parameters even for fpc 3.0.4. You simply can set up the proxy in the Object Inspector.

Disclaimer: Proxy not heavily tested, I don't need a proxy here.

The disadvantage is that you must install a second package, lazmapviewer_synapse which depends on the synapse package (if you don't have it already install it from OPM).

ps

  • Full Member
  • ***
  • Posts: 136
    • CSS
Re: TMapViewer
« Reply #78 on: February 22, 2019, 05:08:39 pm »
I'm new to this component but looks great. But I have big problem with performance (I have big monitors :) ) and UI must be smooth. Resizing, scrolling all is slow as hell.

Maybe due one big component and whole screen repainting. So I have created little test app for my new concept to rewrite painting logic. Instead use one Canvas I would like to divide into TILE_SIZE parts with own map buffer.

TMapViewer will have X*Y TGraphicsControl with own buffer with WIDTH and HEIGHT of TILE_SIZE. So for one TMapViewer we will need (Width div TILE_SIZE) + 2 . Two for offscreen rendering. Same for height.

Maybe each tile can have own thread for updating to prevent queue logic :) For smooth map moving there is TTimer with 60FPS update speed to prevent lags due high mouse move speeds. Please see attachment with little concept test app. What do you thing?
Small simple CSS/box model implementation: https://github.com/pst2d/csscontrols/tree/dev

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: TMapViewer
« Reply #79 on: February 22, 2019, 05:30:06 pm »
TMapView (of lazmapviewer) already does support tiled drawing. If you don't get good speed did you activate thread support? (UseThreads := true). Threads, however, are still leaking memory at the moment. Isn't the sample demo which comes with lazmapviewer sufficiently fast?
« Last Edit: February 22, 2019, 05:31:53 pm by wp »

ps

  • Full Member
  • ***
  • Posts: 136
    • CSS
Re: TMapViewer
« Reply #80 on: February 22, 2019, 05:41:03 pm »
This is from source code for painting (lazmapviewer):
Code: Pascal  [Select][+][-]
  1. procedure TMapView.Paint;
  2. var
  3.   bmp: TBitmap;
  4. begin
  5.   ...
  6.     bmp := TBitmap.Create;
  7.     try
  8.       bmp.SetSize(Buffer.Width, Buffer.Height);
  9.       bmp.LoadFromIntfImage(Buffer);
  10.       Canvas.Draw(0, 0, bmp);
  11.     finally
  12.       bmp.Free;
  13.     end;
  14.  ...
When I move screen 10 pixels left whole sceen must be invalidated? Or it it's possible move allready rendered screen to right and render only missing 10pixels? With even enabled DoubleBuffering POI is flickering.
I'm searching for smooth map scrolling like in web browser (or better) without too many complicated stuffs (OpenGL).
Small simple CSS/box model implementation: https://github.com/pst2d/csscontrols/tree/dev

ps

  • Full Member
  • ***
  • Posts: 136
    • CSS
Re: TMapViewer
« Reply #81 on: February 22, 2019, 05:46:46 pm »
Isn't the sample demo which comes with lazmapviewer sufficiently fast?
Here is example of moving lazmapviewer example on full screen (2560x1440) from left to right (so all tiles are cached): laz.jpg and frame rate is about 1-2 FPS. With TImage example is 60FPS with little or no cpu usage: timage.jpg
Small simple CSS/box model implementation: https://github.com/pst2d/csscontrols/tree/dev

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: TMapViewer
« Reply #82 on: February 22, 2019, 06:57:19 pm »
Feel free to improve it.

Awesome Programmer

  • Sr. Member
  • ****
  • Posts: 451
  • Programming is FUN only when it works :)
    • Cool Technology
Re: TMapViewer
« Reply #83 on: March 05, 2019, 06:01:18 pm »
 :o :o :o :o :o :o :o :o :o
I got an error while trying to compile a demo of TMapViewer.

It says that AllowRedirect is not a member of http and stops compiling.

am I using an old library file or something?

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: TMapViewer
« Reply #84 on: March 05, 2019, 06:06:24 pm »
am I using an old library file or something?
How should I know?

I mean: How should I know when you don't tell us anything about the versions that you use?
« Last Edit: March 05, 2019, 06:18:37 pm by wp »

stephanweber

  • New Member
  • *
  • Posts: 46
Is there also support for Opentopomap?
« Reply #85 on: March 18, 2019, 03:50:54 pm »
This would be great, because opentopomap gives you very beautiful maps, suitable for hiking.

Thanks, Stephan

Awesome Programmer

  • Sr. Member
  • ****
  • Posts: 451
  • Programming is FUN only when it works :)
    • Cool Technology
Re: TMapViewer
« Reply #86 on: March 26, 2019, 03:06:06 pm »
SetCenterLongLat is close to what you want.
Thanks for the tip. Here is my solution:

Code: [Select]
function TMapViewer.GetLongLatMap(AValue: TRealPoint): TIntPoint;
var
  shift: Extended;
  mx, my: Extended;
  res: Extended;
begin
  shift := 2 * pi * EARTH_RADIUS / 2.0;
  mx := AValue.X * shift / 180.0;
  my := ln( tan((90 - AValue.Y) * pi / 360.0 )) / (pi / 180.0);

  my := my * shift / 180.0;

  res := (2 * pi * EARTH_RADIUS) / (TILE_SIZE * IntPower(FZoom));

  Result.X := abs(Round((mx + shift) / res + FX)) + dx;
  Result.Y := abs(Round((my + shift) / res + FY)) + dy;
end;
dx, dy are the former local values ax, ay assigned in RepaintMap().

Would be nice to have intermediate steps of zoom by stretch drawing tiles. It's a pity that Maciej doesn't continue the project.

OMG!!! Your simple LONG/LAT to map's screen X,Y function works FLAWLESSLY... You don't understand how many days I was rolling my head over this; searching online for hints or clues, posting on forums for a little help, trying to hack the code, even trying other versions of TMapviewer.... NOTHING got me this close to finally finishing my project that I am working on. And I don't know how I missed your post on Lazarus forum.  :-[ I got Kcmapviewer working on my system but it lacked function to go from LONG/LAT to Screen X,Y. I simply copied your function and dropped it in KcMapViewer.pas. Then, Added it to the TMapViewer Class. Changed the function to accept also DX, DY from Repaintmap procedure. BAM!!! it works like it suppose to. Thank you so much, Ocye.  :) :) :) :) :) :D :D :D :D :D

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: Is there also support for Opentopomap?
« Reply #87 on: April 03, 2019, 11:12:06 am »
This would be great, because opentopomap gives you very beautiful maps, suitable for hiking.
OpenTopMap has been added as map provider to LazMapViewer in the recent commit.

sstvmaster

  • Sr. Member
  • ****
  • Posts: 299
Re: TMapViewer
« Reply #88 on: April 23, 2019, 07:20:17 pm »
Hi wp,

i want to get the map as image and then i want to print, How to do?
greetings Maik

Windows 10,
- Lazarus 2.2.6 (stable) + fpc 3.2.2 (stable)
- Lazarus 2.2.7 (fixes) + fpc 3.3.1 (main/trunk)

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: TMapViewer
« Reply #89 on: April 23, 2019, 10:10:45 pm »
In the new revision r6861, TMapView has three new methods which extract the complete current buffer bitmap:
- function SaveToImage(AClass: TRasterImageClass): TRasterImage;
- procedure SaveToFile(AClass: TRasterImageClass; const AFileName: String);
- procedure SaveToStream(AClass: TRasterImageClass; AStream: TStream);

The demo project has a new button "Save map to file" which shows how to save the map to a file. For printing you can create a jpeg or png image and send this to the printer. Of course, don't blow it up too much, it will become fuzzy.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. const
  3.   MARGIN = 200;
  4. var
  5.   png: TPortableNetworkGraphic;
  6.   w, h: Integer;
  7. begin
  8.   if not PrintDialog1.Execute then exit;
  9.  
  10.   png := MapView.SaveToImage(TPortableNetworkGraphic);
  11.   try
  12.     Printer.BeginDoc;
  13.     try
  14.       w := Printer.PageWidth - 2*MARGIN;
  15.       h := round(w * png.Height / png.Width);
  16.       Printer.Canvas.StretchDraw(Rect(MARGIN, MARGIN, MARGIN + w, MARGIN + h), png);
  17.     finally
  18.       Printer.EndDoc;
  19.     end;
  20.   finally
  21.     png.Free;
  22.   end;
  23. end;

 

TinyPortal © 2005-2018