0

I got a fictional map set up following this tutorial: https://leafletjs.com/examples/crs-simple/crs-simple.html

But when I try to switch the imageOverlay for map tiles (generated with gdal2tiles-leaflet via docker run --rm -v pwd:/data niene/gdal2tiles-leaflet -l -p raster -z 0-5 -w none /data/<image> /data/<tilesdir>), I only see grey emptiness. What do I need to change to make that work? Or should I better use the rastercoords plugin?

My code currently looks like this:

    var w = 4636;
    var h = 6000;

    //the stuff to be able to work with xy instead of latlon
    var yx = L.latLng;
    var xy = function(x, y) {
        if (L.Util.isArray(x)) {    // When doing xy([x, y]);
            return yx(x[1], x[0]);
        }
        return yx(y, x);  // When doing xy(x, y);
    };

    var bounds = [xy(0, 0), xy(w, h)];

    var background = L.tileLayer('tiles/{z}/{x}/{y}.png', {
        attribution: 'your Map',
        bounds: [[0, 0], [-6000, 4636]],    //the minus is apparently needed to avoid leaflet trying to fetch tiles like -3.png
        tileSize: 256,
        noWrap: true
    });

    var map = L.map('map', {
        layer: [background],
        crs: L.CRS.Simple,
        minZoom: -3
    });

    map.fitBounds(bounds).setMaxBounds(bounds); 
  • And how do you run gdal2tiles? Are you specifying a custom CRS to that? – IvanSanchez Apr 28 at 23:06
  • honestly, I just ran it like this 'docker run --rm -v pwd:/data niene/gdal2tiles-leaflet -l -p raster -z 0-5 -w none /data/<image> /data/<tilesdir>'. I probably don't fully understand this yet, but the output are just some folders with png files. I thought the folder names define how they are supposed to be stitched together at certain some levels - were does the CRS come in play here? Shouldn't that be irrelevant for gdal2tiles and only relevan to the map application? – Merion Apr 29 at 8:17
  • gdal2tiles does reproject raster images depending on the values passed to its -s/--srs and -p/--profile options. That impacts the zoom levels of the created tiles (i.e. the extents of the tile pyramid) and so on. Do you have tiles for zoom levels 0, -3, 8...? How do the tile X/Y coordinates look like for a given zoom level? Unfortunately I'm not knowledgeable enough on gdal2tiles profiles to know more with the information you provide. – IvanSanchez Apr 29 at 13:30
  • Looks like I have to read deeper into the gdal2tiles doc. I thought the -p raster would be enough. – Merion Apr 29 at 19:19
  • I found the answer over at stackoverflow: stackoverflow.com/questions/44054833/… – Merion Apr 30 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.