2019-02-01 14:58:26 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
function RealtimeTileLayer(wsChannel){
|
2019-02-01 14:46:38 +03:00
|
|
|
var self = this;
|
2019-01-29 10:36:46 +03:00
|
|
|
|
2019-02-01 14:46:38 +03:00
|
|
|
wsChannel.addListener("rendered-tile", function(tc){
|
|
|
|
var id = self.getImageId(tc.layerid, tc.x, tc.y, tc.zoom);
|
|
|
|
var el = document.getElementById(id);
|
|
|
|
|
|
|
|
if (el){
|
|
|
|
//Update src attribute if img found
|
|
|
|
el.src = self.getTileSource(tc.layerid, tc.x, tc.y, tc.zoom, true);
|
|
|
|
}
|
|
|
|
});
|
2019-02-01 14:58:26 +03:00
|
|
|
}
|
2019-02-01 14:46:38 +03:00
|
|
|
|
2019-02-01 14:58:26 +03:00
|
|
|
RealtimeTileLayer.prototype.getTileSource = function(layerId, x,y,zoom,cacheBust){
|
|
|
|
return "api/tile/" + layerId + "/" + x + "/" + y + "/" + zoom + "?_=" + Date.now();
|
|
|
|
};
|
2019-02-01 14:46:38 +03:00
|
|
|
|
2019-02-01 14:58:26 +03:00
|
|
|
RealtimeTileLayer.prototype.getImageId = function(layerId, x, y, zoom){
|
|
|
|
return "tile-" + layerId + "/" + x + "/" + y + "/" + zoom;
|
|
|
|
};
|
2019-01-29 10:36:46 +03:00
|
|
|
|
2019-02-01 14:58:26 +03:00
|
|
|
RealtimeTileLayer.prototype.createLayer = function(layerId){
|
|
|
|
var self = this;
|
2019-01-29 10:36:46 +03:00
|
|
|
|
2019-02-01 14:58:26 +03:00
|
|
|
return L.TileLayer.extend({
|
|
|
|
createTile: function(coords){
|
|
|
|
var tile = document.createElement('img');
|
|
|
|
tile.src = self.getTileSource(layerId, coords.x, coords.y, coords.z);
|
|
|
|
tile.id = self.getImageId(layerId, coords.x, coords.y, coords.z);
|
|
|
|
return tile;
|
|
|
|
}
|
|
|
|
});
|
2019-02-01 14:46:38 +03:00
|
|
|
};
|