I am interested in user-specific tiling schemes and serverless display with Leaflet. I have come across problems that I cannot solve on my own.
There are older requests in the forum for the display of user-specific tile schemes with Leaflet. I took up the example from the thread SAS Planet cached tiles for use in Leaflet map and tried to reproduce the example. I encountered the problem that tiles deeper than zoom level 19 cannot be displayed.
I used the following JS code to display the tile bundle from the cache:
L.TileLayer.customTiles = L.TileLayer.extend({
getTileUrl: function (tile_bundle) {
x = tile_bundle.x + 0,
y = tile_bundle.y + 0,
z0 = tile_bundle.z + 1,
x0 = Math.floor(tile_bundle.x / 1024) + 0,
x1 = Math.floor(tile_bundle.x % 1024) + 0,
y0 = Math.floor(tile_bundle.y / 1024),
y1 = Math.floor(tile_bundle.y % 1024);
const tile_view = `./gMapCache/z${z0}/${x0}/x${x}/${y0}/y${y}.jpg`;
console.log('tile_bundle', z0,x0,x,y0,y,x1,y1, tile_view);
return tile_view;
},
});
L.tileLayer.customTiles = function (tile_bundle) { return new L.TileLayer.customTiles({maxZoom: 22}).addTo(map) }; var Ausgabekarte = L.tileLayer.customTiles({}).addTo(map);
The algorithm for calculating the path to the tiles should be correct. However, the tiles from the directory from gMapCache/z19 and below are not displayed. Does anyone know a solution for this?
Whether the tile is actually present should be displayed in a new browser window with a click of the mouse:
map.on('click', function(click)
{
clickzoom = map.getZoom();
var latlng = map.mouseEventToLatLng(click.originalEvent);
var layerPoint = map.latLngToContainerPoint(latlng);
x = layerPoint.x + 0,
y = layerPoint.y + 0,
z0 = clickzoom + 0,
x0 = Math.floor(x / 1024) + 0,
x1 = Math.floor(x % 1024) + 0,
y0 = Math.floor(y / 1024),
y1 = Math.floor(y % 1024);
var tile_on_click = `./gMapCache/z${z0}/${x0}/x${x}/${y0}/y${y}.jpg`;
var clickurl = ["<br><a href=\"" + tile_grid_dir + "\"></a>"];
console.log( layerPoint, x,y,'on click: ', tile_on_click);
alert(
"\rCLICK.TELEMETRIC URL to Tile:\r\r" +
"URL: " + clickurl + "\n" +
"\n\n" )
});
The attached ZIP Conatiner contains an example dataset. ZIP with dataset example. The same example online: LiveView