Leaflet: tms option ignored in 1.0?

Created on 28 Sep 2016  ·  3Comments  ·  Source: Leaflet/Leaflet

I'm using custom tiles generated by gdal. In 1.0, the tiles are being reversed in the y-axis after zoom-in. I tried toggling tms from true to false, but it had no effect. I also tried the new {-y} feature (with the tms option removed), but it throws a "No value provided for variable {-y}" error.

After fiddling around for awhile I referenced 0.6.4 instead of 1.0 and everything works.

Btw, the cdn link to 0.7.7 seems down: http://cdn.leafletjs.com/leaflet-0.7.7/leaflet.js

Linking against https://unpkg.com/[email protected]/dist/leaflet.js for 1.0

var map = L.map('map', {
            crs: L.CRS.Simple,
            center: L.latLng(-128, 128),
            zoom: -2
        });
        L.tileLayer('/map/{z}/{x}/{y}.png', {
            noWrap: true,
            attribution: 'WW',
            detectRetina: false,
            bounds: L.latLngBounds(
                L.latLng(-256, 0),
                L.latLng(0, 256)
            ),
            tms: true,
            minZoom: 0,
            maxZoom: 4
        }).addTo(map);

All 3 comments

Works for me, see http://playground-leaflet.rhcloud.com/bahu/edit?html,output

Next time, check the WMS/TMS tutorial, which contains working examples of TMS, and formulate a bug report like an actual bug report.

Right, I had already read that (and all the tutorials), but that doesn't really apply to custom tiles in conjunction with TMS. The closest tutorial is http://leafletjs.com/examples/crs-simple/crs-simple.html. Being somewhat of an esoteric topic, I was hoping for guidance. I will ask on Stackoverflow next time, my bad.

For anyone else trying to get CRS.Simple working with tiling generated by GDAL, the issue seems to be caused by this block of code

if (this._map && !this._map.options.crs.infinite) {
            var invertedY = this._globalTileRange.max.y - coords.y;
            if (this.options.tms) {
                data['y'] = invertedY;
            }
            data['-y'] = invertedY;
        }

The y will never invert because infinite is set to true in CRS.Simple. Creating a custom copy of CRS.Simple with infinite = false did the trick for my situation.

Was this page helpful?
0 / 5 - 0 ratings