summaryrefslogtreecommitdiffstats
path: root/viewer
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-02-03 20:15:58 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-02-03 20:15:58 +0100
commit4d9f29afaba5f0eddf34ac73614b36fabd0d5353 (patch)
tree1e3129a5a24c7f2f0969eb37c602f193f2a9f09f /viewer
parent0162c236faa324b94ac61c9680c2a88e1915f0cc (diff)
downloadMinedMap-4d9f29afaba5f0eddf34ac73614b36fabd0d5353.tar
MinedMap-4d9f29afaba5f0eddf34ac73614b36fabd0d5353.zip
Add mipmap support to allow zooming out
Diffstat (limited to 'viewer')
-rw-r--r--viewer/MinedMap.js35
-rw-r--r--viewer/index.html2
2 files changed, 22 insertions, 15 deletions
diff --git a/viewer/MinedMap.js b/viewer/MinedMap.js
index c8a41df..a949cce 100644
--- a/viewer/MinedMap.js
+++ b/viewer/MinedMap.js
@@ -1,7 +1,6 @@
var MinedMapLayer = L.GridLayer.extend({
- initialize: function (info, regions, layer) {
- this._info = info;
- this._regions = regions;
+ initialize: function (mipmaps, layer) {
+ this._mipmaps = mipmaps;
this._layer = layer;
this.options.attribution = 'Generated by <a href="http://git.universe-factory.net/MinedMap/">MinedMap</a>';
@@ -19,10 +18,19 @@ var MinedMapLayer = L.GridLayer.extend({
tile.alt = '';
- if (coords.x >= this._info.minX && coords.x <= this._info.maxX &&
- coords.y >= this._info.minZ && coords.y <= this._info.maxZ &&
- this._regions[coords.y-this._info.minZ][coords.x-this._info.minX])
- tile.src = 'data/'+this._layer+'/0/r.'+coords.x+'.'+coords.y+'.png';
+ var z = -coords.z;
+ if (z < 0)
+ z = 0;
+
+ 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';
+
+ if (coords.z >= 0)
+ L.DomUtil.addClass(tile, 'overzoomed');
return tile;
},
@@ -70,24 +78,23 @@ window.createMap = function () {
var xhr = new XMLHttpRequest();
xhr.onload = function () {
var res = JSON.parse(this.responseText),
- info = res.info,
- regions = res.regions,
+ mipmaps = res.mipmaps,
spawn = res.spawn;
var map = L.map('map', {
center: [-spawn.z, spawn.x],
zoom: 0,
- minZoom: 0,
+ minZoom: -(mipmaps.length-1),
maxZoom: 3,
crs: L.CRS.Simple,
maxBounds: [
- [-512*(info.maxZ+1), 512*info.minX],
- [-512*info.minZ, 512*(info.maxX+1)],
+ [-512*(mipmaps[0].info.maxZ+1), 512*mipmaps[0].info.minX],
+ [-512*mipmaps[0].info.minZ, 512*(mipmaps[0].info.maxX+1)],
],
});
- var mapLayer = new MinedMapLayer(info, regions, 'map');
- var lightLayer = new MinedMapLayer(info, regions, 'light');
+ var mapLayer = new MinedMapLayer(mipmaps, 'map');
+ var lightLayer = new MinedMapLayer(mipmaps, 'light');
mapLayer.addTo(map);
diff --git a/viewer/index.html b/viewer/index.html
index 44681d0..245806e 100644
--- a/viewer/index.html
+++ b/viewer/index.html
@@ -22,7 +22,7 @@
background: #333;
}
- img.leaflet-tile {
+ img.overzoomed {
image-rendering: -moz-crisp-edges;
image-rendering: -o-crisp-edges;
image-rendering: -webkit-optimize-contrast;