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

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-02-01 14:58:26 +03:00
2019-06-11 15:16:41 +03:00
export default L.TileLayer.extend({
2019-02-01 15:20:50 +03:00
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;
}
});