X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fgui%2Fmap%2FCloudmadeMapSource.java;fp=tim%2Fprune%2Fgui%2Fmap%2FCloudmadeMapSource.java;h=0cc9b770056e4eb9d5b4d4767470b33a3c0c3e27;hb=c0387c124840c9407e040600fda88f3c3e8f6aa6;hp=0000000000000000000000000000000000000000;hpb=1ee49ae3c8ef3aa2e63eadd458531e5f8bd4f92c;p=GpsPrune.git diff --git a/tim/prune/gui/map/CloudmadeMapSource.java b/tim/prune/gui/map/CloudmadeMapSource.java new file mode 100644 index 0000000..0cc9b77 --- /dev/null +++ b/tim/prune/gui/map/CloudmadeMapSource.java @@ -0,0 +1,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; + } +}