]> gitweb.fperrin.net Git - GpsPrune.git/blob - src/tim/prune/gui/map/MffMapSource.java
Version 20.4, May 2021
[GpsPrune.git] / src / tim / prune / gui / map / MffMapSource.java
1 package tim.prune.gui.map;
2
3 import tim.prune.I18nManager;
4
5 /**
6  * Class to provide a map source for maps-for-free sources
7  * These are double-layer sources with jpg and gif tiles
8  */
9 public class MffMapSource extends MapSource
10 {
11         /** Name for this source */
12         private String _name = null;
13         /** Base urls */
14         private String[] _baseUrls = null;
15         /** Site names */
16         private String[] _siteNames = null;
17         /** Maximum zoom level */
18         private int _maxZoom = 0;
19
20         /**
21          * Constructor giving name, url and maximum zoom
22          * @param inName source name
23          * @param inUrl base url
24          * @param inMaxZoom maximum zoom level
25          */
26         public MffMapSource(String inName, String inUrl1, String inExt1,
27                 String inUrl2, String inExt2, int inMaxZoom)
28         {
29                 _name = inName;
30                 if (_name == null || _name.trim().equals("")) {_name = I18nManager.getText("mapsource.unknown");}
31                 _baseUrls = new String[2];
32                 _baseUrls[0] = fixBaseUrl(inUrl1);
33                 _baseUrls[1] = fixBaseUrl(inUrl2);
34                 _siteNames = new String[2];
35                 _siteNames[0] = SiteNameUtils.convertUrlToDirectory(_baseUrls[0]);
36                 _siteNames[1] = SiteNameUtils.convertUrlToDirectory(_baseUrls[1]);
37                 _extensions = new String[2];
38                 _extensions[0] = inExt1;
39                 _extensions[1] = inExt2;
40                 _maxZoom = inMaxZoom;
41         }
42
43         /**
44          * @return name
45          */
46         public String getName() {
47                 return _name;
48         }
49
50         /** Number of layers is always 2 for mff sources */
51         public int getNumLayers() {
52                 return 2;
53         }
54
55         /** Get base url for specified layer */
56         public String getBaseUrl(int inLayerNum) {
57                 return _baseUrls[inLayerNum];
58         }
59
60         /** site name without protocol or www. */
61         public String getSiteName(int inLayerNum) {
62                 return _siteNames[inLayerNum];
63         }
64
65         /**
66          * Make the URL to get the specified tile
67          */
68         public String makeURL(int inLayerNum, int inZoom, int inX, int inY)
69         {
70                 return _baseUrls[inLayerNum] + "z" + inZoom + "/row" + inY + "/" + inZoom + "_" + inX + "-" + inY + "." + getFileExtension(inLayerNum);
71         }
72
73         /**
74          * @return maximum zoom level
75          */
76         public final int getMaxZoomLevel()
77         {
78                 return _maxZoom;
79         }
80
81         /**
82          * @return semicolon-separated list of all fields
83          */
84         public String getConfigString()
85         {
86                 // TODO: Maybe a gui will be necessary for this one day
87                 return "not required";
88         }
89 }