Fixed nightday and making use of options.mapzoomin and options.mapzoomout.
This commit is contained in:
parent
ea4aa7de97
commit
f0a043b41c
5 changed files with 58 additions and 52 deletions
|
|
@ -124,15 +124,47 @@ var DynmapTileLayer = L.TileLayer.extend({
|
||||||
this._removeOtherTiles(tileBounds);
|
this._removeOtherTiles(tileBounds);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
calculateTileSize: function(zoom) {
|
/*calculateTileSize: function(zoom) {
|
||||||
return this.options.tileSize;
|
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) {
|
setTileSize: function(tileSize) {
|
||||||
this.options.tileSize = tileSize;
|
this.options.tileSize = tileSize;
|
||||||
this._tiles = {};
|
this._tiles = {};
|
||||||
this._createTileProto();
|
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) {
|
function loadjs(url, completed) {
|
||||||
|
|
@ -215,8 +247,8 @@ function namedReplace(str, obj)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (variableBegin < variableEnd) {
|
if (variableBegin < variableEnd) {
|
||||||
var variableName = str.substring(variableBegin+1, variableEnd-1);
|
var variableName = str.substring(variableBegin+1, variableEnd);
|
||||||
result += str.substring(startIndex, variableBegin-1);
|
result += str.substring(startIndex, variableBegin);
|
||||||
result += obj[variableName];
|
result += obj[variableName];
|
||||||
} else /* found '{}' */ {
|
} else /* found '{}' */ {
|
||||||
result += str.substring(startIndex, variableBegin-1);
|
result += str.substring(startIndex, variableBegin-1);
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ var FlatMapType = DynmapTileLayer.extend({
|
||||||
getTileName: function(tilePoint, zoom) {
|
getTileName: function(tilePoint, zoom) {
|
||||||
var tileName;
|
var tileName;
|
||||||
var dnprefix = '';
|
var dnprefix = '';
|
||||||
if(this.options.nightandday && this.dynmap.serverday) {
|
if(this.options.nightandday && this.options.dynmap.serverday) {
|
||||||
dnprefix = '_day';
|
dnprefix = '_day';
|
||||||
}
|
}
|
||||||
var extrazoom = this.options.world.extrazoomout;
|
var extrazoom = this.options.world.extrazoomout;
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,10 @@ var HDProjection = DynmapProjection.extend({
|
||||||
var wtp = this.options.worldtomap;
|
var wtp = this.options.worldtomap;
|
||||||
var xx = wtp[0]*location.x + wtp[1]*location.y + wtp[2]*location.z;
|
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 yy = wtp[3]*location.x + wtp[4]*location.y + wtp[5]*location.z;
|
||||||
var lat = xx / (8 << this.options.extrazoom);
|
return new L.LatLng(
|
||||||
var lng = (128-yy) / (8 << this.options.extrazoom);
|
xx / (1 << this.options.mapzoomout)
|
||||||
return new L.LatLng(lat, lng, true);
|
, (128-yy) / (1 << this.options.mapzoomout)
|
||||||
|
, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -13,37 +14,15 @@ var HDMapType = DynmapTileLayer.extend({
|
||||||
projection: undefined,
|
projection: undefined,
|
||||||
options: {
|
options: {
|
||||||
minZoom: 0,
|
minZoom: 0,
|
||||||
maxZoom: 3
|
maxZoom: 0
|
||||||
},
|
},
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
options.maxZoom = options.mapzoomin + options.world.extrazoomout;
|
options.maxZoom = options.mapzoomin + options.mapzoomout;
|
||||||
L.Util.setOptions(this, options);
|
L.Util.setOptions(this, options);
|
||||||
this.projection = new HDProjection({worldtomap: options.worldtomap})
|
this.projection = new HDProjection($.extend({map: this}, options));
|
||||||
},
|
},
|
||||||
getTileName: function(tilePoint, zoom) {
|
getTileName: function(tilePoint, zoom) {
|
||||||
var tileName;
|
return namedReplace('{prefix}{nightday}/{scaledx}_{scaledy}/{zoom}{x}_{y}.png', this.getTileInfo(tilePoint, zoom));
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ var KzedMapType = DynmapTileLayer.extend({
|
||||||
},
|
},
|
||||||
calculateTileSize: function(zoom) {
|
calculateTileSize: function(zoom) {
|
||||||
var extrazoomout = this.options.dynmap.world.extrazoomout;
|
var extrazoomout = this.options.dynmap.world.extrazoomout;
|
||||||
return (zoom <= extrazoom)
|
return (zoom <= extrazoomout)
|
||||||
? 128
|
? 128
|
||||||
: Math.pow(2, 6+zoom-extrazoomout);
|
: Math.pow(2, 6+zoom-extrazoomout);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -391,11 +391,18 @@ DynMap.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
me.servertime = update.servertime;
|
me.servertime = update.servertime;
|
||||||
var oldday = me.serverday;
|
var newserverday = (me.servertime > 23100 || me.servertime < 12900);
|
||||||
if(me.servertime > 23100 || me.servertime < 12900)
|
if(me.serverday != newserverday) {
|
||||||
me.serverday = true;
|
console.log('serverday changed', newserverday)
|
||||||
else
|
me.serverday = newserverday;
|
||||||
me.serverday = false;
|
|
||||||
|
me.updateBackground();
|
||||||
|
if(me.maptype.options.nightandday) {
|
||||||
|
// Readd map.
|
||||||
|
me.map.removeLayer(me.maptype);
|
||||||
|
me.map.addLayer(me.maptype);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var newplayers = {};
|
var newplayers = {};
|
||||||
$.each(update.players, function(index, playerUpdate) {
|
$.each(update.players, function(index, playerUpdate) {
|
||||||
|
|
@ -439,18 +446,6 @@ DynMap.prototype = {
|
||||||
//divs.filter(function(i){return parseInt(divs[i].attr('rel')) > timestamp+me.options.messagettl;}).remove();
|
//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 ]);
|
$(me).trigger('worldupdated', [ update ]);
|
||||||
|
|
||||||
me.lasttimestamp = update.timestamp;
|
me.lasttimestamp = update.timestamp;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue