2019-04-04 11:19:29 +03:00
|
|
|
/* exported RealtimeTileLayer */
|
2019-02-01 14:58:26 +03:00
|
|
|
|
2019-02-01 15:20:50 +03:00
|
|
|
var RealtimeTileLayer = L.TileLayer.extend({
|
|
|
|
|
2019-03-13 23:28:14 +03:00
|
|
|
initialize: function(wsChannel, layerId, map) {
|
2019-02-01 15:20:50 +03:00
|
|
|
var self = this;
|
|
|
|
this.layerId = layerId;
|
|
|
|
|
|
|
|
wsChannel.addListener("rendered-tile", function(tc){
|
|
|
|
if (tc.layerid != self.layerId){
|
|
|
|
//ignore other layers
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-13 23:28:14 +03:00
|
|
|
if (tc.zoom != map.getZoom()){
|
2019-02-07 21:22:57 +03:00
|
|
|
//ignore other zoom levels
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var id = self.getImageId(tc.x, tc.y, tc.zoom);
|
2019-02-01 15:20:50 +03:00
|
|
|
var el = document.getElementById(id);
|
|
|
|
|
|
|
|
if (el){
|
|
|
|
//Update src attribute if img found
|
2019-02-07 21:22:57 +03:00
|
|
|
el.src = self.getTileSource(tc.x, tc.y, tc.zoom, true);
|
2019-02-01 15:20:50 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
getTileSource: function(x,y,zoom,cacheBust){
|
2019-02-07 21:22:57 +03:00
|
|
|
return "api/tile/" + this.layerId + "/" + x + "/" + y + "/" + zoom + (cacheBust ? "?_=" + Date.now() : "");
|
2019-02-01 15:20:50 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
getImageId: function(x, y, zoom){
|
|
|
|
return "tile-" + this.layerId + "/" + x + "/" + y + "/" + zoom;
|
|
|
|
},
|
|
|
|
|
|
|
|
createTile: function(coords){
|
|
|
|
var tile = document.createElement('img');
|
2019-02-07 21:48:05 +03:00
|
|
|
tile.src = this.getTileSource(coords.x, coords.y, coords.z, true);
|
2019-02-01 15:20:50 +03:00
|
|
|
tile.id = this.getImageId(coords.x, coords.y, coords.z);
|
|
|
|
return tile;
|
|
|
|
}
|
|
|
|
});
|