7

I am using Leaflet JS for displaying my map.

Following is my code. The map gets displayed. But the size of the city names are not large. Each time I zoom in, the font size is very less. It is not readable.

var mymap = L.map('maps1').setView([19.8762, 75.3433], 7);
    L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={access_token}', {
    attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
        id: 'mapbox/streets-v11',
        accessToken: 'your.mapbox.access.token'
}).addTo(mymap);
L.marker([19.8762, 75.3433]).addTo(mymap).bindPopup('Aurangabad');

enter image description here

3
  • You are using the styles API - is that what you want? It looks wrong to me, but I have never used mapbox...
    – til_b
    Commented Jan 2, 2020 at 14:24
  • Yes for styles API
    – Questions
    Commented Jan 2, 2020 at 14:36
  • To me, the size of the labels looks more or less the same as in the example: leafletjs.com/examples/quick-start/example-basic.html
    – toms
    Commented Jan 2, 2020 at 18:23

1 Answer 1

11

If you look at a single tile, the native resolution is 512x512, whereas the default tileSize in the tileLayer API is 256

Try setting the tileSize and zoomOffset:

L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={access_token}', {
    attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
    id: 'mapbox/streets-v11',
    accessToken: 'your.mapbox.access.token',
    tileSize: 512,
    zoomOffset: -1,
}).addTo(mymap);

zoomOffset needs to be -1 to account for the larger tiles, so they cover the expected pixel coordinates. See this issue for some discussion about zoomOffset and why this needs to be set in addition to tileSize

4
  • Can you explain also zoomOffset: -1 setting?
    – TomazicM
    Commented Jan 2, 2020 at 19:17
  • added some additional explanation and links
    – toms
    Commented Jan 2, 2020 at 19:39
  • Hm, this is getting interesting, specially if you throw in also detectRetina option. Requires some logical thinking about the way tiles are fetched from server.
    – TomazicM
    Commented Jan 2, 2020 at 19:51
  • @TomazicM Does having a non-Retina screen cause any problems after you set tileSize and zoomOffset like in the solution? No non-Retina machine right now for me to check this out.
    – Nyxynyx
    Commented Feb 7, 2021 at 22:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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