1
0
forked from MTSR/mapserver
mapserver/server/static/js/RealtimeTileLayer.js

40 lines
1.0 KiB
JavaScript
Raw Normal View History

2019-01-29 08:57:35 +01:00
var RealtimeTileLayer = (function(){
'use strict';
2019-01-29 08:36:46 +01:00
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;
}
2019-01-29 18:08:54 +01:00
2019-01-29 08:57:35 +01:00
return {
2019-01-29 18:08:54 +01:00
init: function(){
WebSocketChannel.addListener("rendered-tile", function(tc){
var id = getImageId(tc.layerid, tc.x, tc.y, tc.zoom);
var el = document.getElementById(id);
if (el){
//Update src attribute if img found
el.src = getTileSource(tc.layerid, tc.x, tc.y, tc.zoom, true);
}
});
},
2019-01-29 08:36:46 +01:00
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;
}
});
}
};
2019-01-29 08:57:35 +01:00
}())