Ticket #3971: OsmTileSource.java

File OsmTileSource.java, 3.4 KB (added by morb_au, 17 years ago)

Example source code that makes Nearmap work to zoom 24 and Mapnik remaining to zoom 18, based on the version in http://svn.openstreetmap.org/applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer

Line 
1package org.openstreetmap.gui.jmapviewer;
2
3import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
4
5public class OsmTileSource {
6
7 public static final String MAP_MAPNIK = "http://tile.openstreetmap.org";
8 public static final String MAP_OSMA = "http://tah.openstreetmap.org/Tiles";
9
10 public static abstract class AbstractOsmTileSource implements TileSource {
11 protected String NAME;
12 protected String BASE_URL;
13 public AbstractOsmTileSource(String name, String base_url)
14 {
15 NAME = name;
16 BASE_URL = base_url;
17 }
18
19 public String getName() {
20 return NAME;
21 }
22
23 public int getMaxZoom() {
24 return 24;
25 }
26
27 public int getMinZoom() {
28 return 0;
29 }
30
31 public String getExtension() {
32 return "png";
33 }
34
35 public String getTilePath(int zoom, int tilex, int tiley) {
36 return "/" + zoom + "/" + tilex + "/" + tiley + "." + getExtension();
37 }
38
39 public String getBaseUrl() {
40 return this.BASE_URL;
41 }
42
43 public String getTileUrl(int zoom, int tilex, int tiley) {
44 return this.getBaseUrl() + getTilePath(zoom, tilex, tiley);
45 }
46
47 @Override
48 public String toString() {
49 return getName();
50 }
51
52 public String getTileType() {
53 return "png";
54 }
55
56 }
57
58 public static class Mapnik extends AbstractOsmTileSource {
59 public Mapnik() {
60 super("Mapnik", MAP_MAPNIK);
61 }
62
63 public int getMaxZoom() {
64 return 18;
65 }
66
67 public TileUpdate getTileUpdate() {
68 return TileUpdate.IfNoneMatch;
69 }
70
71 }
72
73 public static class CycleMap extends AbstractOsmTileSource {
74
75 private static final String PATTERN = "http://%s.andy.sandbox.cloudmade.com/tiles/cycle";
76
77 private static final String[] SERVER = { "a", "b", "c" };
78
79 private int SERVER_NUM = 0;
80
81 public CycleMap() {
82 super("OSM Cycle Map", PATTERN);
83 }
84
85 @Override
86 public String getBaseUrl() {
87 String url = String.format(this.BASE_URL, new Object[] { SERVER[SERVER_NUM] });
88 SERVER_NUM = (SERVER_NUM + 1) % SERVER.length;
89 return url;
90 }
91
92 public int getMaxZoom() {
93 return 17;
94 }
95
96 public TileUpdate getTileUpdate() {
97 return TileUpdate.LastModified;
98 }
99
100 }
101
102 public static abstract class OsmaSource extends AbstractOsmTileSource {
103 String osmaSuffix;
104 public OsmaSource(String name, String osmaSuffix) {
105 super(name, MAP_OSMA);
106 this.osmaSuffix = osmaSuffix;
107 }
108
109 public int getMaxZoom() {
110 return 17;
111 }
112
113 @Override
114 public String getBaseUrl() {
115 return MAP_OSMA + "/" + osmaSuffix;
116 }
117
118 public TileUpdate getTileUpdate() {
119 return TileUpdate.IfModifiedSince;
120 }
121 }
122 public static class TilesAtHome extends OsmaSource {
123 public TilesAtHome() {
124 super("TilesAtHome", "tile");
125 }
126 }
127 public static class Maplint extends OsmaSource {
128 public Maplint() {
129 super("Maplint", "maplint");
130 }
131 }
132}