Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Street labels in Mapbox Tile Layer too small

Tags:

leaflet

mapbox

I have the following Leaflet map: JSFiddle link

<div id="mapid" style="height: 300px;"></div>

<script>
  var mapboxTiles = L.tileLayer(mapBoxUrl, {
    attribution: attributionText
  });

  var map = L.map('mapid')
    .addLayer(mapboxTiles)
    .setView([42.888284, -78.877222], 16);

</script>

The font size for the street labels is very small, to the point of being unreadable, and when you zoom in, the font size gets smaller. Is there a way to control the font size?

like image 903
Amit Avatar asked May 05 '16 00:05

Amit


People also ask

What is tile size leaflet?

By default,tile size is 256x256.

What is leaflet tile?

Leaflet is a lightweight open-source library for online maps. If you haven't worked with Leaflet before, take a look at its tutorials. There are three ways how to use OpenMapTiles as a map layer in Leaflet: raster tiles from server. vector tiles with mapbox-gl-leaflet plugin.

Is Mapbox based on leaflet?

Leaflet is an open-source JavaScript library used for web mapping. The Leaflet library forms the basis of Mapbox.

What is MAP tiler?

MapTiler Desktop Originally started in 2008, it allows anyone to convert images and geodata into fast zoomable maps and generate map tiles - and host on any web server or cloud hosting of your choice.


2 Answers

It looks like you have 512px sized tiles, but mapping the Earth as if they were 256px sized.

Therefore you need a combination of tileSize and zoomOffset options on your Tile Layer to compensate for these settings, and retrieve the correct view with readable sized text on the tiles:

var mapboxTiles = L.tileLayer(mapBoxUrl, {
  attribution: '© <a href="https://www.mapbox.com/map-feedback/">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
  tileSize: 512,
  zoomOffset: -1
});

Updated JSFiddle: https://jsfiddle.net/zq02pnpg/2/

like image 142
ghybs Avatar answered Sep 29 '22 14:09

ghybs


I had this problem too. On my case, the map was rendering just okay on desktop, but when it came to mobile devices, it)(The font size) gets really small and is not readable. I tried doubling the tile size as well as the zoom offset and it worked.

var mapboxTiles = L.tileLayer(mapBoxUrl, {
  attribution: '© <a href="https://www.mapbox.com/map-feedback/">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
  tileSize: 1024,
  zoomOffset: -2
});

I'm not sure if this is a violation of any kind but it worked for me!

like image 34
Gustone Alwanga Avatar answered Sep 29 '22 12:09

Gustone Alwanga