From e027f76d9b11721c9bf75313469df37e1d472a2c Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 4 Feb 2015 06:35:31 +0100 Subject: Use higher-resolution tiles on retina displays --- viewer/MinedMap.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/viewer/MinedMap.js b/viewer/MinedMap.js index a949cce..f6be634 100644 --- a/viewer/MinedMap.js +++ b/viewer/MinedMap.js @@ -1,7 +1,9 @@ var MinedMapLayer = L.GridLayer.extend({ initialize: function (mipmaps, layer) { - this._mipmaps = mipmaps; - this._layer = layer; + this.mipmaps = mipmaps; + this.layer = layer; + + this.zoomOffset = L.Browser.retina ? 1 : 0; this.options.attribution = 'Generated by MinedMap'; @@ -18,16 +20,16 @@ var MinedMapLayer = L.GridLayer.extend({ tile.alt = ''; - var z = -coords.z; + var z = -(coords.z + this.zoomOffset); if (z < 0) z = 0; - var mipmap = this._mipmaps[z]; + var mipmap = this.mipmaps[z]; if (coords.x >= mipmap.info.minX && coords.x <= mipmap.info.maxX && coords.y >= mipmap.info.minZ && coords.y <= mipmap.info.maxZ && mipmap.regions[coords.y-mipmap.info.minZ][coords.x-mipmap.info.minX]) - tile.src = 'data/'+this._layer+'/'+z+'/r.'+coords.x+'.'+coords.y+'.png'; + tile.src = 'data/'+this.layer+'/'+z+'/r.'+coords.x+'.'+coords.y+'.png'; if (coords.z >= 0) L.DomUtil.addClass(tile, 'overzoomed'); @@ -44,12 +46,14 @@ var MinedMapLayer = L.GridLayer.extend({ }, _getTileSize: function () { - var map = this._map, zoom = map.getZoom(); + var map = this._map, zoom = map.getZoom() + this.zoomOffset; + + var base = (L.Browser.retina ? 256 : 512); if (zoom > 0) - return Math.round(map.getZoomScale(map.getZoom(), 0) * 512); + return Math.round(map.getZoomScale(zoom, 0) * base); else - return 512; + return base; }, _onTileRemove: function (e) { -- cgit v1.2.3