LazMapViewer: Improved handling of download uri protocol.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8702 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2023-02-12 17:39:04 +00:00
parent f083df12eb
commit e343a8232f
3 changed files with 8 additions and 17 deletions

View File

@ -24,7 +24,6 @@ type
TMvCustomDownloadEngine = class(TComponent)
protected
function GetLocalFileName(const Url: String): String;
procedure InternalDownloadFile(const Url: String; AStream: TStream); virtual; abstract;
procedure LoadFromLocalFile(const AFileName: String; AStream: TStream);
public
@ -35,28 +34,20 @@ type
implementation
uses
StrUtils;
const
FILE_SCHEME = 'file://';
URIParser;
{ TMvCustomDownloadEngine }
procedure TMvCustomDownloadEngine.DownloadFile(const Url: string; AStream: TStream);
var
fn: String;
begin
if AnsiStartsText(FILE_SCHEME, Url) then
LoadFromLocalFile(GetLocalFileName(Url), AStream)
if URIToFileName(Url, fn) then
LoadFromLocalFile(fn, AStream)
else
InternalDownloadFile(Url, AStream);
end;
// Chops the "file://" off of a local file name.
// Note: Does not check whether the Url really begins with "file://".
function TMvCustomDownloadEngine.GetLocalFileName(const Url: String): String;
begin
Result := Copy(Url, Length(FILE_SCHEME) + 1, MaxInt);
end;
procedure TMvCustomDownloadEngine.LoadFromLocalFile(const AFileName: String;
AStream: TStream);
var

View File

@ -487,7 +487,7 @@ begin
Env := TEnvTile(Data);
Id := Env.Tile;
MapO := Env.Win.MapProvider;
if Assigned(MapO) then
if Assigned(MapO) and Assigned(Cache) then
begin
if not Cache.InCache(MapO, Id) then
begin
@ -500,7 +500,7 @@ begin
try
try
FDownloadEngine.DownloadFile(Url, lStream);
Cache.Add(MapO, Id, lStream);
if Assigned(Cache) then Cache.Add(MapO, Id, lStream);
except
end;
finally

View File

@ -61,7 +61,7 @@ Type
function GetCachePath: String;
function GetCenter: TRealPoint;
function GetDownloadEngine: TMvCustomDownloadEngine;
function GetDrawingEngine: TMvCustoMDrawingEngine;
function GetDrawingEngine: TMvCustomDrawingEngine;
function GetMapProvider: String;
function GetOnCenterMove: TNotifyEvent;
function GetOnChange: TNotifyEvent;