]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/gui/map/CloudmadeMapSource.java
Version 14, October 2012
[GpsPrune.git] / tim / prune / gui / map / CloudmadeMapSource.java
1 package tim.prune.gui.map;
2
3 /**
4  * Class to act as a source for Cloudmade maps with a given style
5  */
6 public class CloudmadeMapSource extends OsmMapSource
7 {
8         /** Selected style number */
9         private String _style = null;
10         /** Server prefix including API-key unique to GpsPrune application */
11         private static final String SERVER_PREFIX = "[abc].tile.cloudmade.com/03d86b66f51f4a3b8c236ac06f2a2e57/";
12
13         /**
14          * Constructor
15          * @param inName name to use for map source
16          * @param inStyle style, given as integer
17          * @param inMaxZoom maximum zoom level, 18 by default
18          */
19         public CloudmadeMapSource(String inName, String inStyle, int inMaxZoom)
20         {
21                 // Note: Could check style for valid integer value here
22                 super(inName, SERVER_PREFIX + inStyle + "/256/", null, inMaxZoom);
23                 _style = inStyle;
24         }
25
26         /**
27          * @return semicolon-separated list of all fields
28          */
29         public String getConfigString()
30         {
31                 return "c:" +  getName() + ";" + _style + ";" + getMaxZoomLevel();
32         }
33
34         /**
35          * Construct a new map source from its config string
36          * @param inConfigString string from Config, separated by semicolons
37          * @return new map source, or null if not parseable
38          */
39         public static CloudmadeMapSource fromConfig(String inConfigString)
40         {
41                 CloudmadeMapSource source = null;
42                 if (inConfigString.startsWith("c:"))
43                 {
44                         String[] items = inConfigString.substring(2).split(";");
45                         try {
46                                 if (items.length == 3) {
47                                         source = new CloudmadeMapSource(items[0], items[1], Integer.parseInt(items[2]));
48                                 }
49                         } catch (NumberFormatException nfe) {}
50                 }
51                 return source;
52         }
53
54         /**
55          * @return style as string, only required to populate edit dialog
56          */
57         public String getStyle()
58         {
59                 return _style;
60         }
61 }