1
0
forked from MTSR/mapserver
mapserver/server/static/js/RealtimeTileLayer.js
NatureFreshMilk 542c5653ce js org
2019-01-29 08:57:35 +01:00

37 lines
1018 B
JavaScript

var RealtimeTileLayer = (function(){
'use strict';
function getTileSource(layerId, x,y,zoom,cacheBust){
return "api/tile/" + layerId + "/" + x + "/" + y + "/" + zoom + "?_=" + Date.now();
}
function getImageId(layerId, x, y, zoom){
return "tile-" + layerId + "/" + x + "/" + y + "/" + zoom;
}
return {
create: function(layerId){
return L.TileLayer.extend({
createTile: function(coords){
var tile = document.createElement('img');
tile.src = getTileSource(layerId, coords.x, coords.y, coords.z);
tile.id = getImageId(layerId, coords.x, coords.y, coords.z);
return tile;
}
});
},
update: function(data){
var id = getImageId(data.layerid, data.x, data.y, data.zoom);
var el = document.getElementById(id);
if (el){
//Update src attribute if img found
el.src = getTileSource(data.layerid, data.x, data.y, data.zoom, true);
}
}
};
}())