LazMapViewer: Refactor map provider identification. Issue #38279, patch by regs.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7947 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-12-30 10:31:41 +00:00
parent 9d506bfa25
commit 49db2e4ea8
2 changed files with 73 additions and 53 deletions

View File

@ -717,11 +717,12 @@ function TMapViewerEngine.ReadProvidersFromXML(AFileName: String;
lcName: String; lcName: String;
begin begin
lcName := LowerCase(AName); lcName := LowerCase(AName);
case lcName of if lcName = LowerCase(SVR_LETTER) then
'letter': Result := @GetLetterSvr; Result := @GetSvrLetter
'yahoo': Result := @GetYahooSvr; else if lcName = LowerCase(SVR_BASE1) then
else Result := nil; Result := @GetSvrBase1
end; else
Result := nil;
end; end;
function GetValStr(AName: String): TGetValStr; function GetValStr(AName: String): TGetValStr;
@ -729,12 +730,14 @@ function TMapViewerEngine.ReadProvidersFromXML(AFileName: String;
lcName: String; lcName: String;
begin begin
lcName := Lowercase(AName); lcName := Lowercase(AName);
case lcName of if lcName = LowerCase(STR_QUADKEY) then
'quadkey': Result := @GetQuadKey; Result := @GetStrQuadKey
'yahooy': Result := @GetYahooY; else if lcName = LowerCase(STR_YAHOOY) then
'yahooz': Result := @GetYahooZ; Result := @GetStrYahooY
else Result := nil; else if lcName = LowerCase(STR_YAHOOZ) then
end; Result := @GetStrYahooZ
else
Result := nil;
end; end;
function GetAttrValue(ANode: TDOMNode; AttrName: String): String; function GetAttrValue(ANode: TDOMNode; AttrName: String): String;
@ -880,25 +883,25 @@ begin
// opeName, Url, MinZoom, MaxZoom, NbSvr, GetSvrStr, GetXStr, GetYStr, GetZStr // opeName, Url, MinZoom, MaxZoom, NbSvr, GetSvrStr, GetXStr, GetYStr, GetZStr
MapWin.MapProvider := AddMapProvider('OpenStreetMap Mapnik', MapWin.MapProvider := AddMapProvider('OpenStreetMap Mapnik',
'http://%serv%.tile.openstreetmap.org/%z%/%x%/%y%.png', 'http://%serv%.tile.openstreetmap.org/%z%/%x%/%y%.png',
0, 19, 3, @GetLetterSvr); 0, 19, 3, @GetSvrLetter);
AddMapProvider('Open Cycle Map', AddMapProvider('Open Cycle Map',
'http://%serv%.tile.opencyclemap.org/cycle/%z%/%x%/%y%.png', 'http://%serv%.tile.opencyclemap.org/cycle/%z%/%x%/%y%.png',
0, 18, 3, @getLetterSvr); 0, 18, 3, @GetSvrLetter);
AddMapProvider('Open Topo Map', AddMapProvider('Open Topo Map',
'http://%serv%.tile.opentopomap.org/%z%/%x%/%y%.png', 'http://%serv%.tile.opentopomap.org/%z%/%x%/%y%.png',
0, 19, 3, @getLetterSvr); 0, 19, 3, @GetSvrLetter);
AddMapProvider('Virtual Earth Bing', AddMapProvider('Virtual Earth Bing',
'http://ecn.t%serv%.tiles.virtualearth.net/tiles/r%x%?g=671&mkt=en-us&lbl=l1&stl=h&shading=hill', 'http://ecn.t%serv%.tiles.virtualearth.net/tiles/r%x%?g=671&mkt=en-us&lbl=l1&stl=h&shading=hill',
1, 19, 8, nil, @GetQuadKey); 1, 19, 8, nil, @GetStrQuadKey);
AddMapProvider('Virtual Earth Road', AddMapProvider('Virtual Earth Road',
'http://r%serv%.ortho.tiles.virtualearth.net/tiles/r%x%.png?g=72&shading=hill', 'http://r%serv%.ortho.tiles.virtualearth.net/tiles/r%x%.png?g=72&shading=hill',
1, 19, 4, nil, @GetQuadKey); 1, 19, 4, nil, @GetStrQuadKey);
AddMapProvider('Virtual Earth Aerial', AddMapProvider('Virtual Earth Aerial',
'http://a%serv%.ortho.tiles.virtualearth.net/tiles/a%x%.jpg?g=72&shading=hill', 'http://a%serv%.ortho.tiles.virtualearth.net/tiles/a%x%.jpg?g=72&shading=hill',
1, 19, 4, nil, @GetQuadKey); 1, 19, 4, nil, @GetStrQuadKey);
AddMapProvider('Virtual Earth Hybrid', AddMapProvider('Virtual Earth Hybrid',
'http://h%serv%.ortho.tiles.virtualearth.net/tiles/h%x%.jpg?g=72&shading=hill', 'http://h%serv%.ortho.tiles.virtualearth.net/tiles/h%x%.jpg?g=72&shading=hill',
1, 19, 4, nil, @GetQuadKey); 1, 19, 4, nil, @GetStrQuadKey);
if (HERE_AppID <> '') and (HERE_AppCode <> '') then begin if (HERE_AppID <> '') and (HERE_AppCode <> '') then begin
// Registration required to access HERE maps: // Registration required to access HERE maps:
@ -909,19 +912,19 @@ begin
HERE1 := 'http://%serv%.base.maps.api.here.com/maptile/2.1/maptile/newest/'; HERE1 := 'http://%serv%.base.maps.api.here.com/maptile/2.1/maptile/newest/';
HERE2 := '/%z%/%x%/%y%/256/png8?app_id=' + HERE_AppID + '&app_code=' + HERE_AppCode; HERE2 := '/%z%/%x%/%y%/256/png8?app_id=' + HERE_AppID + '&app_code=' + HERE_AppCode;
AddMapProvider('Here Maps', HERE1 + 'normal.day' + HERE2, AddMapProvider('Here Maps', HERE1 + 'normal.day' + HERE2,
1, 19, 4, @GetYahooSvr); 1, 19, 4, @GetSvrBase1);
AddMapProvider('Here Maps Grey', HERE1 + 'normal.day.grey' + HERE2, AddMapProvider('Here Maps Grey', HERE1 + 'normal.day.grey' + HERE2,
1, 19, 4, @GetYahooSvr); 1, 19, 4, @GetSvrBase1);
AddMapProvider('Here Maps Reduced', HERE1 + 'reduced.day' + HERE2, AddMapProvider('Here Maps Reduced', HERE1 + 'reduced.day' + HERE2,
1, 19, 4, @GetYahooSvr); 1, 19, 4, @GetSvrBase1);
AddMapProvider('Here Maps Transit', HERE1 + 'normal.day.transit' + HERE2, AddMapProvider('Here Maps Transit', HERE1 + 'normal.day.transit' + HERE2,
1, 19, 4, @GetYahooSvr); 1, 19, 4, @GetSvrBase1);
AddMapProvider('Here POI Maps', HERE1 + 'normal.day' + HERE2 + '&pois', AddMapProvider('Here POI Maps', HERE1 + 'normal.day' + HERE2 + '&pois',
1, 19, 4, @GetYahooSvr); 1, 19, 4, @GetSvrBase1);
AddMapProvider('Here Pedestrian Maps', HERE1 + 'pedestrian.day' + HERE2, AddMapProvider('Here Pedestrian Maps', HERE1 + 'pedestrian.day' + HERE2,
1, 19, 4, @GetYahooSvr); 1, 19, 4, @GetSvrBase1);
AddMapProvider('Here DreamWorks Maps', HERE1 + 'normal.day' + HERE2 + '&style=dreamworks', AddMapProvider('Here DreamWorks Maps', HERE1 + 'normal.day' + HERE2 + '&style=dreamworks',
1, 19, 4, @GetYahooSvr); 1, 19, 4, @GetSvrBase1);
end; end;
if (OpenWeatherMap_ApiKey <> '') then begin if (OpenWeatherMap_ApiKey <> '') then begin

View File

@ -77,21 +77,28 @@ type
end; end;
function GetLetterSvr(id: integer): String; function GetSvrLetter(id: integer): String;
function GetYahooSvr(id: integer): String; function GetSvrBase1(id: integer): String;
function GetYahooY(const Tile: TTileId): string; function GetStrYahooY(const Tile: TTileId): string;
function GetYahooZ(const Tile: TTileId): string; function GetStrYahooZ(const Tile: TTileId): string;
function GetQuadKey(const Tile: TTileId): string; function GetStrQuadKey(const Tile: TTileId): string;
const
SVR_LETTER = 'Letter';
SVR_BASE1 = 'Base1';
STR_YAHOOY = 'YahooY'; // Idea: Deprecate, as Yahoo Maps are dead
STR_YAHOOZ = 'YahooZ'; // Idea: Deprecate, as Yahoo Maps are dead
STR_QUADKEY = 'QuadKey';
implementation implementation
function GetLetterSvr(id: integer): String; function GetSvrLetter(id: integer): String;
begin begin
Result := Char(Ord('a') + id); Result := Char(Ord('a') + id);
end; end;
function GetQuadKey(const Tile: TTileId): string; function GetStrQuadKey(const Tile: TTileId): string;
var var
i, d, m: Longword; i, d, m: Longword;
begin begin
@ -110,17 +117,17 @@ begin
end; end;
end; end;
function GetYahooSvr(id: integer): String; function GetSvrBase1(id: integer): String;
Begin Begin
Result := IntToStr(id + 1); Result := IntToStr(id + 1);
end; end;
function GetYahooY(const Tile : TTileId): string; function GetStrYahooY(const Tile : TTileId): string;
begin begin
Result := IntToStr( -(Tile.Y - (1 shl Tile.Z) div 2) - 1); Result := IntToStr( -(Tile.Y - (1 shl Tile.Z) div 2) - 1);
end; end;
function GetYahooZ(const Tile : TTileId): string; function GetStrYahooZ(const Tile : TTileId): string;
Begin Begin
result := IntToStr(Tile.Z + 1); result := IntToStr(Tile.Z + 1);
end; end;
@ -305,28 +312,38 @@ begin
layerNode.SetAttribute('maxZoom', IntToStr(FMaxZoom[i])); layerNode.SetAttribute('maxZoom', IntToStr(FMaxZoom[i]));
layerNode.SetAttribute('serverCount', IntToStr(FNbSvr[i])); layerNode.SetAttribute('serverCount', IntToStr(FNbSvr[i]));
if FGetSvrStr[i] = @getLetterSvr then s := 'Letter' if FGetSvrStr[i] = @GetSvrLetter then
else if FGetSvrStr[i] = @GetYahooSvr then s := 'Yahoo' s := SVR_LETTER
else if FGetSvrstr[i] <> nil then s := 'unknown' else if FGetSvrStr[i] = @GetSvrBase1 then
else s := ''; s := SVR_BASE1
if s <> '' then layerNode.SetAttribute('serverProc', s); else
s := '';
if s <> '' then
layerNode.SetAttribute('serverProc', s);
if FGetXStr[i] = @GetQuadKey then s := 'QuadKey' if FGetXStr[i] = @GetStrQuadKey then
else if FGetXStr[i] <> nil then s := '(unknown)' s := STR_QUADKEY
else s := ''; else
if s <> '' then layerNode.SetAttribute('xProc', s); s := '';
if s <> '' then
layerNode.SetAttribute('xProc', s);
if FGetYStr[i] = @GetQuadKey then s := 'QuadKey' if FGetYStr[i] = @GetStrQuadKey then
else if FGetYStr[i] = @GetYahooY then s := 'YahooY' s := STR_QUADKEY
else if FGetYStr[i] <> nil then s := '(unknown)' else if FGetYStr[i] = @GetStrYahooY then
else s := ''; s := STR_YAHOOY
else
s := '';
if s <> '' then layerNode.SetAttribute('yProc', s); if s <> '' then layerNode.SetAttribute('yProc', s);
if FGetZStr[i] = @GetQuadKey then s := 'QuadKey' if FGetZStr[i] = @GetStrQuadKey then
else if FGetZStr[i] = @GetYahooZ then s := 'YahooZ' s := STR_QUADKEY
else if FGetZStr[i] <> nil then s := '(unknown)' else if FGetZStr[i] = @GetStrYahooZ then
else s := ''; s := STR_YAHOOZ
if s <> '' then layerNode.SetAttribute('zProc', s); else
s := '';
if s <> '' then
layerNode.SetAttribute('zProc', s);
end; end;
end; end;