From 49db2e4ea8ff2dc4c1357ce2fd730b5e7767e070 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Wed, 30 Dec 2020 10:31:41 +0000 Subject: [PATCH] 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 --- components/lazmapviewer/source/mvengine.pas | 53 +++++++------- .../lazmapviewer/source/mvmapprovider.pas | 73 ++++++++++++------- 2 files changed, 73 insertions(+), 53 deletions(-) diff --git a/components/lazmapviewer/source/mvengine.pas b/components/lazmapviewer/source/mvengine.pas index b42a74e54..069608920 100644 --- a/components/lazmapviewer/source/mvengine.pas +++ b/components/lazmapviewer/source/mvengine.pas @@ -717,11 +717,12 @@ function TMapViewerEngine.ReadProvidersFromXML(AFileName: String; lcName: String; begin lcName := LowerCase(AName); - case lcName of - 'letter': Result := @GetLetterSvr; - 'yahoo': Result := @GetYahooSvr; - else Result := nil; - end; + if lcName = LowerCase(SVR_LETTER) then + Result := @GetSvrLetter + else if lcName = LowerCase(SVR_BASE1) then + Result := @GetSvrBase1 + else + Result := nil; end; function GetValStr(AName: String): TGetValStr; @@ -729,12 +730,14 @@ function TMapViewerEngine.ReadProvidersFromXML(AFileName: String; lcName: String; begin lcName := Lowercase(AName); - case lcName of - 'quadkey': Result := @GetQuadKey; - 'yahooy': Result := @GetYahooY; - 'yahooz': Result := @GetYahooZ; - else Result := nil; - end; + if lcName = LowerCase(STR_QUADKEY) then + Result := @GetStrQuadKey + else if lcName = LowerCase(STR_YAHOOY) then + Result := @GetStrYahooY + else if lcName = LowerCase(STR_YAHOOZ) then + Result := @GetStrYahooZ + else + Result := nil; end; function GetAttrValue(ANode: TDOMNode; AttrName: String): String; @@ -880,25 +883,25 @@ begin // opeName, Url, MinZoom, MaxZoom, NbSvr, GetSvrStr, GetXStr, GetYStr, GetZStr MapWin.MapProvider := AddMapProvider('OpenStreetMap Mapnik', 'http://%serv%.tile.openstreetmap.org/%z%/%x%/%y%.png', - 0, 19, 3, @GetLetterSvr); + 0, 19, 3, @GetSvrLetter); AddMapProvider('Open Cycle Map', 'http://%serv%.tile.opencyclemap.org/cycle/%z%/%x%/%y%.png', - 0, 18, 3, @getLetterSvr); + 0, 18, 3, @GetSvrLetter); AddMapProvider('Open Topo Map', 'http://%serv%.tile.opentopomap.org/%z%/%x%/%y%.png', - 0, 19, 3, @getLetterSvr); + 0, 19, 3, @GetSvrLetter); 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', - 1, 19, 8, nil, @GetQuadKey); + 1, 19, 8, nil, @GetStrQuadKey); AddMapProvider('Virtual Earth Road', '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', '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', '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 // Registration required to access HERE maps: @@ -909,19 +912,19 @@ begin 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; AddMapProvider('Here Maps', HERE1 + 'normal.day' + HERE2, - 1, 19, 4, @GetYahooSvr); + 1, 19, 4, @GetSvrBase1); 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, - 1, 19, 4, @GetYahooSvr); + 1, 19, 4, @GetSvrBase1); 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', - 1, 19, 4, @GetYahooSvr); + 1, 19, 4, @GetSvrBase1); 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', - 1, 19, 4, @GetYahooSvr); + 1, 19, 4, @GetSvrBase1); end; if (OpenWeatherMap_ApiKey <> '') then begin diff --git a/components/lazmapviewer/source/mvmapprovider.pas b/components/lazmapviewer/source/mvmapprovider.pas index bab507f24..d2abb3afa 100644 --- a/components/lazmapviewer/source/mvmapprovider.pas +++ b/components/lazmapviewer/source/mvmapprovider.pas @@ -77,21 +77,28 @@ type end; -function GetLetterSvr(id: integer): String; -function GetYahooSvr(id: integer): String; -function GetYahooY(const Tile: TTileId): string; -function GetYahooZ(const Tile: TTileId): string; -function GetQuadKey(const Tile: TTileId): string; +function GetSvrLetter(id: integer): String; +function GetSvrBase1(id: integer): String; +function GetStrYahooY(const Tile: TTileId): string; +function GetStrYahooZ(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 -function GetLetterSvr(id: integer): String; +function GetSvrLetter(id: integer): String; begin Result := Char(Ord('a') + id); end; -function GetQuadKey(const Tile: TTileId): string; +function GetStrQuadKey(const Tile: TTileId): string; var i, d, m: Longword; begin @@ -110,17 +117,17 @@ begin end; end; -function GetYahooSvr(id: integer): String; +function GetSvrBase1(id: integer): String; Begin Result := IntToStr(id + 1); end; -function GetYahooY(const Tile : TTileId): string; +function GetStrYahooY(const Tile : TTileId): string; begin Result := IntToStr( -(Tile.Y - (1 shl Tile.Z) div 2) - 1); end; -function GetYahooZ(const Tile : TTileId): string; +function GetStrYahooZ(const Tile : TTileId): string; Begin result := IntToStr(Tile.Z + 1); end; @@ -305,28 +312,38 @@ begin layerNode.SetAttribute('maxZoom', IntToStr(FMaxZoom[i])); layerNode.SetAttribute('serverCount', IntToStr(FNbSvr[i])); - if FGetSvrStr[i] = @getLetterSvr then s := 'Letter' - else if FGetSvrStr[i] = @GetYahooSvr then s := 'Yahoo' - else if FGetSvrstr[i] <> nil then s := 'unknown' - else s := ''; - if s <> '' then layerNode.SetAttribute('serverProc', s); + if FGetSvrStr[i] = @GetSvrLetter then + s := SVR_LETTER + else if FGetSvrStr[i] = @GetSvrBase1 then + s := SVR_BASE1 + else + s := ''; + if s <> '' then + layerNode.SetAttribute('serverProc', s); - if FGetXStr[i] = @GetQuadKey then s := 'QuadKey' - else if FGetXStr[i] <> nil then s := '(unknown)' - else s := ''; - if s <> '' then layerNode.SetAttribute('xProc', s); + if FGetXStr[i] = @GetStrQuadKey then + s := STR_QUADKEY + else + s := ''; + if s <> '' then + layerNode.SetAttribute('xProc', s); - if FGetYStr[i] = @GetQuadKey then s := 'QuadKey' - else if FGetYStr[i] = @GetYahooY then s := 'YahooY' - else if FGetYStr[i] <> nil then s := '(unknown)' - else s := ''; + if FGetYStr[i] = @GetStrQuadKey then + s := STR_QUADKEY + else if FGetYStr[i] = @GetStrYahooY then + s := STR_YAHOOY + else + s := ''; if s <> '' then layerNode.SetAttribute('yProc', s); - if FGetZStr[i] = @GetQuadKey then s := 'QuadKey' - else if FGetZStr[i] = @GetYahooZ then s := 'YahooZ' - else if FGetZStr[i] <> nil then s := '(unknown)' - else s := ''; - if s <> '' then layerNode.SetAttribute('zProc', s); + if FGetZStr[i] = @GetStrQuadKey then + s := STR_QUADKEY + else if FGetZStr[i] = @GetStrYahooZ then + s := STR_YAHOOZ + else + s := ''; + if s <> '' then + layerNode.SetAttribute('zProc', s); end; end;