File: CloudmadeMapSource.java

package info (click to toggle)
gpsprune 10-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,220 kB
  • ctags: 3,013
  • sloc: java: 22,662; sh: 23; makefile: 16; python: 15
file content (53 lines) | stat: -rw-r--r-- 1,549 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package tim.prune.gui.map;

/**
 * Class to act as a source for Cloudmade maps with a given style
 */
public class CloudmadeMapSource extends OsmMapSource
{
	/** Selected style number */
	private String _style = null;
	/** Server prefix including API-key unique to Prune application */
	private static final String SERVER_PREFIX = "tile.cloudmade.com/03d86b66f51f4a3b8c236ac06f2a2e57/";

	/**
	 * Constructor
	 * @param inName name to use for map source
	 * @param inStyle style, given as integer
	 * @param inMaxZoom maximum zoom level, 18 by default
	 */
	public CloudmadeMapSource(String inName, String inStyle, int inMaxZoom)
	{
		// Note: Could check style for valid integer value here
		super(inName, SERVER_PREFIX + inStyle + "/256/", null, inMaxZoom);
		_style = inStyle;
	}

	/**
	 * @return semicolon-separated list of all fields
	 */
	public String getConfigString()
	{
		return "c:" +  getName() + ";" + _style + ";" + getMaxZoomLevel();
	}

	/**
	 * Construct a new map source from its config string
	 * @param inConfigString string from Config, separated by semicolons
	 * @return new map source, or null if not parseable
	 */
	public static CloudmadeMapSource fromConfig(String inConfigString)
	{
		CloudmadeMapSource source = null;
		if (inConfigString.startsWith("c:"))
		{
			String[] items = inConfigString.substring(2).split(";");
			try {
				if (items.length == 3) {
					source = new CloudmadeMapSource(items[0], items[1], Integer.parseInt(items[2]));
				}
			} catch (NumberFormatException nfe) {}
		}
		return source;
	}
}