2

I'm using leaflet to render a map with a popular visualization coordinate system, but the map tile is wrong ordering. How can I solve this problem?

enter image description here

var map = L.map('map', {
    // crs: crs,
    continuousWorld: true,
    worldCopyJump: false,
    zoomControl: true
});

new L.TileLayer('https://www.gtrack.co.id/TileMapService/TileMap.ashx?cachetype=0&tilex={x}&tiley={y}&level={z}', {
    maxZoom: 14,
    minZoom: 0,
    continuousWorld: true,
    tileSize:256,
    // tms: true
}).addTo(map);

map.setView([-0.497125, 117.108078], 5);
4
  • Are you sure that the problem isn't with the tileserver? I tried using the link but it doesn't seem to be working for me
    – Joost K
    Commented Dec 11, 2019 at 13:23
  • @JoostK, Yes Im sure, the link have used before with Google API, and the map shown normally
    – Rival
    Commented Dec 11, 2019 at 13:32
  • you could try switching z and y I could see some providers implementing this different Commented Dec 11, 2019 at 13:40
  • I added some property to tile layer, the map ordering correctly but the center of map isn't accurate, var map = L.map('map', { // crs: crs, continuousWorld: true, worldCopyJump: false, zoomControl: true, crs: L.CRS.Simple }); new L.TileLayer('gtrack.co.id/TileMapService/TileMap.ashx?cachetype=0&tilex={x}&tiley={y}&level={z}', { maxZoom: 14, minZoom: 0, continuousWorld: true, tileSize:256, // bounds: [[-5200, -5200], [5200, 5200]], // tms: true }).addTo(map); map.setView([-0.497125, 117.108078], 5);
    – Rival
    Commented Dec 11, 2019 at 13:46

2 Answers 2

3

The problem is that the Z index for the tile server is not zero-based like TileLayer([x,y], z) expects to receive. You have to pass an argument called zoomOffset with value 1 to fix this.

var map = L.map('map', {
    // crs: crs,
    continuousWorld: true,
    worldCopyJump: false,
    zoomControl: true
});

new L.TileLayer('https://www.gtrack.co.id/TileMapService/TileMap.ashx?cachetype=0&tilex={x}&tiley={y}&level={z}', {
    maxZoom: 14,
    minZoom: 0,
    continuousWorld: true,
    tileSize:256,
    crs: L.CRS.Simple,
    zoomOffset: 1 // <------------ the param to add
}).addTo(map);

map.setView([-0.497125, 117.108078], 5);

Then you get: enter image description here

0
0

I was having issues with invalid, empty and misplaced placed tiles as well.

As I do not know the service you are requesting the tiles from, this solution may not apply to you, but this might help any passerby using OpenStreetMaps:

In the URL, x, y and z must NOT be in alphabetical order like so:

const tileURL = "https://{s}.tile.osm.org/{x}/{y}/{z}.png";

but must instead be in this order:

const tileURL = "https://{s}.tile.osm.org/{z}/{x}/{y}.png";

Otherwise, invalid tiles will be requested, resulting in an unusable, faulty map.

Not the answer you're looking for? Browse other questions tagged or ask your own question.