diff --git a/web/js/dynmaputils.js b/web/js/dynmaputils.js index 69e9072d..3e625e38 100644 --- a/web/js/dynmaputils.js +++ b/web/js/dynmaputils.js @@ -142,27 +142,26 @@ var DynmapTileLayer = L.TileLayer.extend({ // Some helper functions. zoomprefix: function(amount) { - // amount == 0 -> '' - // amount == 1 -> 'z_' - // amount == 2 -> 'zz_' - return 'zzzzzzzzzzzzzzzzzzzzzz'.substr(0, amount) + (amount === 0 ? '' : '_'); + return 'zzzzzzzzzzzzzzzzzzzzzz'.substr(0, amount); }, getTileInfo: function(tilePoint, zoom) { // zoom: max zoomed in = this.options.maxZoom, max zoomed out = 0 // izoom: max zoomed in = 0, max zoomed out = this.options.maxZoom - // zoomoutlevel: 0 when izoom < mapzoomin, else izoom - mapzoomin (which ranges from 0 till mapzoomout) + // zoomoutlevel: izoom < mapzoomin -> 0, else -> izoom - mapzoomin (which ranges from 0 till mapzoomout) var izoom = this.options.maxZoom - zoom; var zoomoutlevel = Math.max(0, izoom - this.options.mapzoomin); var scale = 1 << zoomoutlevel; var zoomprefix = this.zoomprefix(zoomoutlevel); + var x = scale*tilePoint.x; + var y = scale*tilePoint.y; return { prefix: this.options.prefix, nightday: (this.options.nightandday && this.options.dynmap.serverday) ? '_day' : '', - scaledx: (scale*tilePoint.x) >> 5, - scaledy: (-scale*tilePoint.y) >> 5, + scaledx: x >> 5, + scaledy: y >> 5, zoom: this.zoomprefix(zoomoutlevel), - x: scale*tilePoint.x, - y: -scale*tilePoint.y + x: x, + y: y }; } }); diff --git a/web/js/flatmap.js b/web/js/flatmap.js index b7b8eb67..1694c0e0 100644 --- a/web/js/flatmap.js +++ b/web/js/flatmap.js @@ -1,6 +1,9 @@ var FlatProjection = DynmapProjection.extend({ fromLocationToLatLng: function(location) { - return new L.LatLng(-location.z, location.x, true); + return new L.LatLng( + -location.z / (8 << this.options.mapzoomout), + location.x / (8 << this.options.mapzoomout), + true); } }); @@ -10,40 +13,16 @@ var FlatMapType = DynmapTileLayer.extend({ maxZoom: 4 }, initialize: function(options) { - options.maxZoom = options.mapzoomin + options.world.extrazoomout; + options.maxzoomout = options.mapzoomout || options.world.extrazoomout; + options.maxZoom = options.mapzoomin + options.maxzoomout; L.Util.setOptions(this, options); - this.projection = new FlatProjection({extrazoom: this.options.world.extrazoomout}); + this.projection = new FlatProjection({mapzoomout: options.mapzoomout}); }, getTileName: function(tilePoint, zoom) { - var tileName; - var dnprefix = ''; - if(this.options.nightandday && this.options.dynmap.serverday) { - dnprefix = '_day'; - } - var extrazoom = this.options.world.extrazoomout; - if(zoom < extrazoom) { - var scale = 1 << (extrazoom-zoom); - var zprefix = "zzzzzzzzzzzz".substring(0, extrazoom-zoom); - if(this.options.bigmap) { - tileName = this.options.prefix + dnprefix + '_128/' + ((scale*tilePoint.x) >> 5) + '_' + ((scale*tilePoint.y) >> 5) + '/' + zprefix + "_" + (scale*tilePoint.x) + '_' + (scale*tilePoint.y) + '.png'; - } else { - tileName = zprefix + this.options.prefix + dnprefix + '_128_' + (scale*tilePoint.x) + '_' + (scale*tilePoint.y) + '.png'; - } - } - else { - if(this.options.bigmap) { - tileName = this.options.prefix + dnprefix + '_128/' + (tilePoint.x >> 5) + '_' + (tilePoint.y >> 5) + '/' + tilePoint.x + '_' + tilePoint.y + '.png'; - } else { - tileName = this.options.prefix + dnprefix + '_128_' + tilePoint.x + '_' + tilePoint.y + '.png'; - } - } - return tileName; - }, - calculateTileSize: function(zoom) { - var extrazoom = this.options.world.extrazoomout; - return (zoom < extrazoom) - ? 128 - : Math.pow(2, 7+zoom-extrazoom); + return namedReplace(this.options.bigmap + ? '{prefix}{nightday}_128/{scaledx}_{scaledy}/{zoom}_{x}_{y}.png' + : '{zoom}{prefix}{nightday}_128_{x}_{y}.png' + , this.getTileInfo(tilePoint, zoom)); } }); diff --git a/web/js/hdmap.js b/web/js/hdmap.js index da799d0e..2aa5add3 100644 --- a/web/js/hdmap.js +++ b/web/js/hdmap.js @@ -22,7 +22,17 @@ var HDMapType = DynmapTileLayer.extend({ this.projection = new HDProjection($.extend({map: this}, options)); }, getTileName: function(tilePoint, zoom) { - return namedReplace('{prefix}{nightday}/{scaledx}_{scaledy}/{zoom}{x}_{y}.png', this.getTileInfo(tilePoint, zoom)); + var info = this.getTileInfo(tilePoint, zoom); + // Y is inverted for HD-map. + info.y = -info.y; + info.scaledy = info.y >> 5; + return namedReplace('{prefix}{nightday}/{scaledx}_{scaledy}/{zoom}{x}_{y}.png', info); + }, + zoomprefix: function(amount) { + // amount == 0 -> '' + // amount == 1 -> 'z_' + // amount == 2 -> 'zz_' + return 'zzzzzzzzzzzzzzzzzzzzzz'.substr(0, amount) + (amount === 0 ? '' : '_'); } }); diff --git a/web/js/kzedmaps.js b/web/js/kzedmaps.js index d5c9ed0c..f5364f53 100644 --- a/web/js/kzedmaps.js +++ b/web/js/kzedmaps.js @@ -5,11 +5,11 @@ var KzedProjection = DynmapProjection.extend({ var dz = location.z; var px = dx + dz; var py = dx - dz - dy; - var scale = 2 << this.options.extrazoom; + var scale = 1 << this.options.mapzoomout; - var lat = px / scale - 64; - var lng = py / scale; - return new L.LatLng(-lat, lng, true); + var xx = (128 - px) / scale; + var yy = py / scale; + return new L.LatLng(xx, yy, true); } }); @@ -19,43 +19,35 @@ var KzedMapType = DynmapTileLayer.extend({ maxZoom: 4 }, initialize: function(options) { - options.maxZoom = options.mapzoomin + options.world.extrazoomout; + options.mapzoomout = options.mapzoomout || options.world.extrazoomout; + options.maxZoom = options.mapzoomin + options.mapzoomout; L.Util.setOptions(this, options); - this.projection = new KzedProjection({extrazoom: this.options.world.extrazoomout}); + this.projection = new KzedProjection({mapzoomout: this.options.mapzoomout}); }, getTileName: function(tilePoint, zoom) { - var tileSize = 128; - var tileName = ''; - var dnprefix = ''; - - if(this.options.nightandday && this.options.dynmap.serverday) { - dnprefix = '_day'; - } - var extrazoom = this.options.world.extrazoomout; - if (zoom <= extrazoom) { - var zpre = 'zzzzzzzzzzzzzzzz'.substring(0, extrazoom-zoom); - // Most zoomed out tiles. - var tilescale = 2 << (extrazoom-zoom); - if (this.options.bigmap) { - if(zoom < extrazoom) zpre = zpre + '_'; - tileName = 'z' + this.options.prefix + dnprefix + '/' + ((-tilePoint.x * tileSize*tilescale)>>12) + '_' + ((tilePoint.y * tileSize*tilescale) >> 12) + '/' + zpre + (-tilePoint.x * tileSize*tilescale) + '_' + (tilePoint.y * tileSize*tilescale) + '.png'; - } else { - tileName = zpre + 'z' + this.options.prefix + dnprefix + '_' + (-tilePoint.x * tileSize*tilescale) + '_' + (tilePoint.y * tileSize*tilescale) + '.png'; - } - } else { - if(this.options.bigmap) { - tileName = this.options.prefix + dnprefix + '/' + ((-tilePoint.x*tileSize) >> 12) + '_' + ((tilePoint.y*tileSize)>>12) + '/' + (-tilePoint.x*tileSize) + '_' + (tilePoint.y*tileSize) + '.png'; - } else { - tileName = this.options.prefix + dnprefix + '_' + (-tilePoint.x*tileSize) + '_' + (tilePoint.y*tileSize) + '.png'; - } - } - return tileName; + var info = this.getTileInfo(tilePoint, zoom); + return namedReplace(this.options.bigmap + ? '{prefix}{nightday}/{scaledx}_{scaledy}/{zoom}_{x}_{y}.png' + : '{zoom}{prefix}{nightday}_{x}_{y}.png' + , this.getTileInfo(tilePoint, zoom)); }, - calculateTileSize: function(zoom) { - var extrazoomout = this.options.dynmap.world.extrazoomout; - return (zoom <= extrazoomout) - ? 128 - : Math.pow(2, 6+zoom-extrazoomout); + getTileInfo: function(tilePoint, zoom) { + // Custom tile-info-calculation for KzedMap: *128 and >>12 + var izoom = this.options.maxZoom - zoom; + var zoomoutlevel = Math.max(0, izoom - this.options.mapzoomin); + var scale = 1 << zoomoutlevel; + var zoomprefix = this.zoomprefix(zoomoutlevel); + var x = -scale*tilePoint.x*128; + var y = scale*tilePoint.y*128; + return { + prefix: this.options.prefix, + nightday: (this.options.nightandday && this.options.dynmap.serverday) ? '_day' : '', + scaledx: x >> 12, + scaledy: y >> 12, + zoom: this.zoomprefix(zoomoutlevel), + x: x, + y: y + }; } });