Use higher-resolution tiles on retina displays

This commit is contained in:
Matthias Schiffer 2015-02-04 06:35:31 +01:00
parent 22615f90aa
commit e027f76d9b

View file

@ -1,7 +1,9 @@
var MinedMapLayer = L.GridLayer.extend({ var MinedMapLayer = L.GridLayer.extend({
initialize: function (mipmaps, layer) { initialize: function (mipmaps, layer) {
this._mipmaps = mipmaps; this.mipmaps = mipmaps;
this._layer = layer; this.layer = layer;
this.zoomOffset = L.Browser.retina ? 1 : 0;
this.options.attribution = 'Generated by <a href="http://git.universe-factory.net/MinedMap/">MinedMap</a>'; this.options.attribution = 'Generated by <a href="http://git.universe-factory.net/MinedMap/">MinedMap</a>';
@ -18,16 +20,16 @@ var MinedMapLayer = L.GridLayer.extend({
tile.alt = ''; tile.alt = '';
var z = -coords.z; var z = -(coords.z + this.zoomOffset);
if (z < 0) if (z < 0)
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 && if (coords.x >= mipmap.info.minX && coords.x <= mipmap.info.maxX &&
coords.y >= mipmap.info.minZ && coords.y <= mipmap.info.maxZ && coords.y >= mipmap.info.minZ && coords.y <= mipmap.info.maxZ &&
mipmap.regions[coords.y-mipmap.info.minZ][coords.x-mipmap.info.minX]) 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) if (coords.z >= 0)
L.DomUtil.addClass(tile, 'overzoomed'); L.DomUtil.addClass(tile, 'overzoomed');
@ -44,12 +46,14 @@ var MinedMapLayer = L.GridLayer.extend({
}, },
_getTileSize: function () { _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) if (zoom > 0)
return Math.round(map.getZoomScale(map.getZoom(), 0) * 512); return Math.round(map.getZoomScale(zoom, 0) * base);
else else
return 512; return base;
}, },
_onTileRemove: function (e) { _onTileRemove: function (e) {