]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/gui/map/MffMapSource.java
Version 10, May 2010
[GpsPrune.git] / 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         /** File extensions */
18         private String[] _extensions = null;
19         /** Maximum zoom level */
20         private int _maxZoom = 0;
21
22         /**
23          * Constructor giving name, url and maximum zoom
24          * @param inName source name
25          * @param inUrl base url
26          * @param inMaxZoom maximum zoom level
27          */
28         public MffMapSource(String inName, String inUrl1, String inExt1,
29                 String inUrl2, String inExt2, int inMaxZoom)
30         {
31                 _name = inName;
32                 if (_name == null || _name.trim().equals("")) {_name = I18nManager.getText("mapsource.unknown");}
33                 _baseUrls = new String[2];
34                 _baseUrls[0] = fixBaseUrl(inUrl1);
35                 _baseUrls[1] = fixBaseUrl(inUrl2);
36                 _siteNames = new String[2];
37                 _siteNames[0] = fixSiteName(_baseUrls[0]);
38                 _siteNames[1] = fixSiteName(_baseUrls[1]);
39                 _extensions = new String[2];
40                 _extensions[0] = inExt1;
41                 _extensions[1] = inExt2;
42                 _maxZoom = inMaxZoom;
43         }
44
45         /**
46          * @return name
47          */
48         public String getName() {
49                 return _name;
50         }
51
52         /** Number of layers is always 2 for mff sources */
53         public int getNumLayers() {
54                 return 2;
55         }
56
57         /** Get base url for specified layer */
58         public String getBaseUrl(int inLayerNum) {
59                 return _baseUrls[inLayerNum];
60         }
61
62         /** site name without protocol or www. */
63         public String getSiteName(int inLayerNum) {
64                 return _siteNames[inLayerNum];
65         }
66
67         /**
68          * Make the URL to get the specified tile
69          */
70         public String makeURL(int inLayerNum, int inZoom, int inX, int inY)
71         {
72                 return _baseUrls[inLayerNum] + "z" + inZoom + "/row" + inY + "/" + inZoom + "_" + inX + "-" + inY + getFileExtension(inLayerNum);
73         }
74
75         /** Get right file extension for this layer */
76         public final String getFileExtension(int inLayerNum) {
77                 return _extensions[inLayerNum];
78         }
79
80         /**
81          * @return maximum zoom level
82          */
83         public final int getMaxZoomLevel()
84         {
85                 return _maxZoom;
86         }
87
88         /**
89          * @return semicolon-separated list of all fields
90          */
91         public String getConfigString()
92         {
93                 // TODO: Maybe a gui will be necessary for this one day
94                 return "not required";
95         }
96 }