Fixed nightday and making use of options.mapzoomin and options.mapzoomout.

This commit is contained in:
FrozenCow 2011-07-24 14:56:23 +02:00
parent 9f19ccf50c
commit 4f75bf691a
5 changed files with 58 additions and 52 deletions

View File

@ -124,15 +124,47 @@ var DynmapTileLayer = L.TileLayer.extend({
this._removeOtherTiles(tileBounds);
}
},
calculateTileSize: function(zoom) {
/*calculateTileSize: function(zoom) {
return this.options.tileSize;
},*/
calculateTileSize: function(zoom) {
// zoomoutlevel: 0 when izoom > mapzoomin, else mapzoomin - izoom (which ranges from 0 till mapzoomin)
var izoom = this.options.maxZoom - zoom;
var zoominlevel = Math.max(0, this.options.mapzoomin - izoom);
return 128 << zoominlevel;
},
setTileSize: function(tileSize) {
this.options.tileSize = tileSize;
this._tiles = {};
this._createTileProto();
},
updateTileSize: function(zoom) {}
updateTileSize: function(zoom) {},
// Some helper functions.
zoomprefix: function(amount) {
// amount == 0 -> ''
// amount == 1 -> 'z_'
// amount == 2 -> 'zz_'
return 'zzzzzzzzzzzzzzzzzzzzzz'.substr(0, amount) + (amount === 0 ? '' : '_');
},
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)
var izoom = this.options.maxZoom - zoom;
var zoomoutlevel = Math.max(0, izoom - this.options.mapzoomin);
var scale = 1 << zoomoutlevel;
var zoomprefix = this.zoomprefix(zoomoutlevel);
return {
prefix: this.options.prefix,
nightday: (this.options.nightandday && this.options.dynmap.serverday) ? '_day' : '',
scaledx: (scale*tilePoint.x) >> 5,
scaledy: (-scale*tilePoint.y) >> 5,
zoom: this.zoomprefix(zoomoutlevel),
x: scale*tilePoint.x,
y: -scale*tilePoint.y
};
}
});
function loadjs(url, completed) {
@ -215,8 +247,8 @@ function namedReplace(str, obj)
break;
}
if (variableBegin < variableEnd) {
var variableName = str.substring(variableBegin+1, variableEnd-1);
result += str.substring(startIndex, variableBegin-1);
var variableName = str.substring(variableBegin+1, variableEnd);
result += str.substring(startIndex, variableBegin);
result += obj[variableName];
} else /* found '{}' */ {
result += str.substring(startIndex, variableBegin-1);

View File

@ -17,7 +17,7 @@ var FlatMapType = DynmapTileLayer.extend({
getTileName: function(tilePoint, zoom) {
var tileName;
var dnprefix = '';
if(this.options.nightandday && this.dynmap.serverday) {
if(this.options.nightandday && this.options.dynmap.serverday) {
dnprefix = '_day';
}
var extrazoom = this.options.world.extrazoomout;

View File

@ -3,9 +3,10 @@ var HDProjection = DynmapProjection.extend({
var wtp = this.options.worldtomap;
var xx = wtp[0]*location.x + wtp[1]*location.y + wtp[2]*location.z;
var yy = wtp[3]*location.x + wtp[4]*location.y + wtp[5]*location.z;
var lat = xx / (8 << this.options.extrazoom);
var lng = (128-yy) / (8 << this.options.extrazoom);
return new L.LatLng(lat, lng, true);
return new L.LatLng(
xx / (1 << this.options.mapzoomout)
, (128-yy) / (1 << this.options.mapzoomout)
, true);
}
});
@ -13,37 +14,15 @@ var HDMapType = DynmapTileLayer.extend({
projection: undefined,
options: {
minZoom: 0,
maxZoom: 3
maxZoom: 0
},
initialize: function(options) {
options.maxZoom = options.mapzoomin + options.world.extrazoomout;
options.maxZoom = options.mapzoomin + options.mapzoomout;
L.Util.setOptions(this, options);
this.projection = new HDProjection({worldtomap: options.worldtomap})
this.projection = new HDProjection($.extend({map: this}, options));
},
getTileName: function(tilePoint, zoom) {
var tileName;
var dnprefix = '';
if(this.options.nightandday && this.options.dynmap.serverday) {
dnprefix = '_day';
}
var extrazoom = this.options.mapzoomout;
if(zoom < extrazoom) {
var scale = 1 << (extrazoom-zoom);
var zprefix = "zzzzzzzzzzzzzzzzzzzzzz".substring(0, extrazoom-zoom);
tileName = this.options.prefix + dnprefix + '/' + ((scale*tilePoint.x) >> 5) + '_' + ((-scale*tilePoint.y) >> 5) + '/' + zprefix + "_" + (scale*tilePoint.x) + '_' + (-scale*tilePoint.y) + '.png';
} else {
tileName = this.options.prefix + dnprefix + '/' + (tilePoint.x >> 5) + '_' + ((-tilePoint.y) >> 5) + '/' + tilePoint.x + '_' + (-tilePoint.y) + '.png';
}
return tileName;
},
calculateTileSize: function(zoom) {
var extrazoom = this.options.mapzoomout;
console.log(zoom <= extrazoom, zoom, extrazoom);
return (zoom <= extrazoom)
? 128
: Math.pow(2, 7+zoom-extrazoom);
return namedReplace('{prefix}{nightday}/{scaledx}_{scaledy}/{zoom}{x}_{y}.png', this.getTileInfo(tilePoint, zoom));
}
});

View File

@ -53,7 +53,7 @@ var KzedMapType = DynmapTileLayer.extend({
},
calculateTileSize: function(zoom) {
var extrazoomout = this.options.dynmap.world.extrazoomout;
return (zoom <= extrazoom)
return (zoom <= extrazoomout)
? 128
: Math.pow(2, 6+zoom-extrazoomout);
}

View File

@ -391,11 +391,18 @@ DynMap.prototype = {
}
me.servertime = update.servertime;
var oldday = me.serverday;
if(me.servertime > 23100 || me.servertime < 12900)
me.serverday = true;
else
me.serverday = false;
var newserverday = (me.servertime > 23100 || me.servertime < 12900);
if(me.serverday != newserverday) {
console.log('serverday changed', newserverday)
me.serverday = newserverday;
me.updateBackground();
if(me.maptype.options.nightandday) {
// Readd map.
me.map.removeLayer(me.maptype);
me.map.addLayer(me.maptype);
}
}
var newplayers = {};
$.each(update.players, function(index, playerUpdate) {
@ -438,18 +445,6 @@ DynMap.prototype = {
//var divs = $('div[rel]');
//divs.filter(function(i){return parseInt(divs[i].attr('rel')) > timestamp+me.options.messagettl;}).remove();
});
if(me.serverday != oldday) {
me.updateBackground();
var mtid = me.map.mapTypeId;
console.log('TODO: RENDER NIGHTANDDAY!!!')
/*if(me.map.mapTypes[mtid].nightandday) {
me.map.setMapTypeId('none');
window.setTimeout(function() {
me.map.setMapTypeId(mtid);
}, 0.1);
}*/
}
$(me).trigger('worldupdated', [ update ]);