Skip to content

Commit cf0c767

Browse files
OSM; limit zoom levels, wrap tiles horizontally
1 parent 0cd84fb commit cf0c767

File tree

1 file changed

+45
-7
lines changed

1 file changed

+45
-7
lines changed

js/tracker.js

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,50 @@ function makeQuad(x, y, zoom) {
163163
return quad;
164164
}
165165

166+
// wraps tiles horizontally, returns x
167+
function wrapTiles(x, zoom) {
168+
var n = Math.pow(2,zoom);
169+
return (x<0) ? (n+(x%n))%n : x%n;
170+
}
171+
166172
// map type list
173+
// format: [ name, attr, minZoom, maxZoom, getTileUrl function ]
167174
var maptypes = {
168-
bing_os: ['Ordnance Survey (UK)','Bing.com & Ordnance Survey', function(xy,z) { return 'http://ecn.t'+(Math.round(Math.random()*3)+1)+'.tiles.virtualearth.net/tiles/r'+makeQuad(xy.x, xy.y, z)+'?g=2689&lbl=l1&productSet=mmOS'; }],
169-
osm: ['OSM','OpenStreetMaps.org', function(xy,z) { return 'http://'+['a','b','c'][Math.round(Math.random()*2)]+'.tile.openstreetmap.org/'+z+'/'+xy.x+'/'+xy.y+'.png'; }],
170-
osm_bw: ['OSM B&W','OSM Black & White', function(xy,z) { return 'http://'+['a','b','c','d','e'][Math.round(Math.random()*2)]+'.www.toolserver.org/tiles/bw-mapnik/'+z+'/'+xy.x+'/'+xy.y+'.png'; }],
171-
osm_toner: ['OSM Toner','Stamen.org Toner', function(xy,z) { return 'http://'+['a','b','c','d'][Math.round(Math.random()*2)]+'.tile.stamen.com/toner/'+z+'/'+xy.x+'/'+xy.y+'.png'; }],
172-
osm_watercolor: ['OSM Watercolor','Stamen.org Watercolor', function(xy,z) { return 'http://'+['a','b','c','d'][Math.round(Math.random()*2)]+'.tile.stamen.com/watercolor/'+z+'/'+xy.x+'/'+xy.y+'.png'; }],
175+
bing_os: [
176+
'Ordnance Survey (UK)',
177+
'Bing.com & Ordnance Survey',
178+
10,
179+
17,
180+
function(xy,z) { return 'http://ecn.t'+(Math.round(Math.random()*3)+1)+'.tiles.virtualearth.net/tiles/r'+makeQuad(xy.x, xy.y, z)+'?g=2689&lbl=l1&productSet=mmOS'; }
181+
],
182+
osm: [
183+
'OSM',
184+
'OpenStreetMaps.org',
185+
1,
186+
19,
187+
function(xy,z) { return 'http://'+['a','b','c'][Math.round(Math.random()*2)]+'.tile.openstreetmap.org/'+z+'/'+wrapTiles(xy.x,z)+'/'+xy.y+'.png'; }
188+
],
189+
osm_bw: [
190+
'OSM B&W',
191+
'OSM Black & White',
192+
1,
193+
16,
194+
function(xy,z) { return 'http://'+['a','b','c','d','e'][Math.round(Math.random()*2)]+'.www.toolserver.org/tiles/bw-mapnik/'+z+'/'+wrapTiles(xy.x,z)+'/'+xy.y+'.png'; }
195+
],
196+
osm_toner: [
197+
'OSM Toner',
198+
'Stamen.org Toner',
199+
1,
200+
18,
201+
function(xy,z) { return 'http://'+['a','b','c','d'][Math.round(Math.random()*2)]+'.tile.stamen.com/toner/'+z+'/'+wrapTiles(xy.x,z)+'/'+xy.y+'.png'; }
202+
],
203+
osm_watercolor: [
204+
'OSM Watercolor',
205+
'Stamen.org Watercolor',
206+
1,
207+
18,
208+
function(xy,z) { return 'http://'+['a','b','c','d'][Math.round(Math.random()*2)]+'.tile.stamen.com/watercolor/'+z+'/'+wrapTiles(xy.x,z)+'/'+xy.y+'.png'; }
209+
]
173210
}
174211

175212
// generate a list of names for the UI
@@ -201,9 +238,10 @@ function load() {
201238
// register custom map types
202239
for(var i in maptypes) {
203240
map.mapTypes.set(i, new google.maps.ImageMapType({
204-
getTileUrl: maptypes[i][2],
241+
getTileUrl: maptypes[i][4],
242+
minZoom: maptypes[i][2],
243+
maxZoom: maptypes[i][3],
205244
tileSize: new google.maps.Size(256, 256),
206-
maxZoom: 18,
207245
name: maptypes[i][0]
208246
}));
209247
}

0 commit comments

Comments
 (0)