Fix tile updating

This commit is contained in:
James Lyne 2021-08-22 23:03:43 +01:00
parent 94ecd3f495
commit ca9009e33f
2 changed files with 25 additions and 45 deletions

View File

@ -80,17 +80,6 @@ var DynmapTileLayer = L.TileLayer.extend({
_loadQueue: [], _loadQueue: [],
_loadingTiles: [], _loadingTiles: [],
getTileUrl: function(coords) {
var tileName = this.getTileName(coords),
url = this._cachedTileUrls[tileName];
if (!url) {
this._cachedTileUrls[tileName] = url = this.options.dynmap.getTileUrl(tileName);
}
return url;
},
createTile: function(coords, done) { createTile: function(coords, done) {
var me = this, var me = this,
tile = document.createElement('img'); tile = document.createElement('img');
@ -188,6 +177,24 @@ var DynmapTileLayer = L.TileLayer.extend({
L.TileLayer.prototype._removeTile.call(this, key); L.TileLayer.prototype._removeTile.call(this, key);
}, },
getTileUrl: function(coords, timestamp) {
return this.getTileUrlFromName(this.getTileName(coords), timestamp);
},
getTileUrlFromName(tileName, timestamp) {
var url = this._cachedTileUrls[tileName];
if (!url) {
this._cachedTileUrls[tileName] = url = this.options.dynmap.getTileUrl(tileName);
}
if(typeof timestamp !== 'undefined') {
url += (url.indexOf('?') === -1 ? '?timestamp=' + timestamp : '&timestamp=' + timestamp);
}
return url;
},
getProjection: function() { getProjection: function() {
return this.projection; return this.projection;
}, },
@ -207,26 +214,18 @@ var DynmapTileLayer = L.TileLayer.extend({
next.src = next.url; next.src = next.url;
}, },
onTileUpdated: function(tile, tileName) {
var src = this.dynmap.getTileUrl(tileName);
tile.attr('src', src);
tile.show();
},
getTileName: function(coords) { getTileName: function(coords) {
throw "getTileName not implemented"; throw "getTileName not implemented";
}, },
updateNamedTile: function(name) { updateNamedTile: function(name, timestamp) {
var tile = this._namedTiles[name]; var tile = this._namedTiles[name];
delete this._cachedTileUrls[name];
if (tile) {
this.updateTile(tile);
}
},
updateTile: function(tile) { if (tile) {
this._loadTile(tile, tile.tilePoint, this._map.getZoom()); tile.url = this.getTileUrlFromName(name, timestamp);
this._loadQueue.push(tile);
this._tickLoadQueue();
}
}, },
// Some helper functions. // Some helper functions.

View File

@ -695,7 +695,7 @@ DynMap.prototype = {
swtch(update.type, { swtch(update.type, {
tile: function() { tile: function() {
me.onTileUpdated(update.name,update.timestamp); me.maptype.updateNamedTile(update.name, update.timestamp);
}, },
playerjoin: function() { playerjoin: function() {
$(me).trigger('playerjoin', [ update.playerName ]); $(me).trigger('playerjoin', [ update.playerName ]);
@ -742,25 +742,6 @@ DynMap.prototype = {
} }
return tile; return tile;
}, },
onTileUpdated: function(tileName,timestamp) {
var me = this;
var prev = this.registeredTiles[tileName];
var a_b = true;
if (prev && (prev.indexOf('upd=0') > 0))
a_b = false;
var url = me.options.url.tiles;
if (a_b) {
if (url.indexOf('?') > 0) {
this.registeredTiles[tileName] = url + escape(me.world.name + '/' + tileName) + '&upd=0';
}
else {
this.registeredTiles[tileName] = url + escape(me.world.name + '/' + tileName) + '?upd=0';
}
}
else
this.registeredTiles[tileName] = url + me.world.name + '/' + tileName;
me.maptype.updateNamedTile(tileName);
},
addPlayer: function(update) { addPlayer: function(update) {
var me = this; var me = this;
var player = me.players[update.account] = { var player = me.players[update.account] = {