6

To get the undesired result below, I:

  1. Uploaded a zipped shapefile to MapBox Studio.
  2. Using the shape, created a layer of polygons to display area boundaries.
  3. Using the same shape, created a text layer to label areas with their names.

Labels appear on the lines:

enter image description here

How can I make labels appear in the centre of the polygons?

  • 1
    I was looking for the same feature, and I find this completely lacking in MB. How ridiculous to have to label shapefiles separately... – ecuated Jun 9 '16 at 19:35
5

The feature of calculating label points for polygons on the client is currently in progress and will appear in one of the next releases. See:

  • Mourner, has this been released as a Mapbox Studio feature? – David Sep 17 '17 at 21:51
4

Because of how vector-tiles work, you'll actually have to calculate the label locations yourself as a separate point layer. This should be pretty easy to do w/ any GIS program like qGIS/ArcGIS/PostGIS by calculating the centroid of each polygon, doing a spatial join to save the polygon label to the corresponding centroid point, and saving the result as a new point shp file.

Upload the result to MB, import it into your project and add labels via the new point layer, rather than the polygon layer.

The reason this is necessary is b/c vector-tiles actually split your polygons into tiles. Sufficiently large polygons will actually be cut into multiple polygons, so calculating polygon centroids on tiled polygons doesn't really make sense.

(by the way, I'm assuming you're using the new web-based MapBox Studio, not MapBox Studio Classic -- the answer is essentially the same either way, except that with the latter, you'd import the new label-point layer into your local download of MB Studio Classic, rather than uploading to your MB account).

  • With ArcGIS you simply turn on the 'display label' option and the system places labels in the centre of polygons (by default, but you can manipulate that). When you're suggesting me to do all the above, does this mean MB doesn't have a button (that I completely missed) that simply labels the polygon layer? You see what I mean? My initial approach was to create 2 layers, one to draw the polygons and another to display labels. Isn't there an option of a polygon layer in MB that I can simply turn on to display labels of that layer without having to create an extra layer just for the labels? – Rodrigo Mar 19 '16 at 17:59
  • 1
    No, there is not an option to turn on labels for polygons. This is b/c (as mentioned) MB Studio only has access to the tiled geometries, which prevents it from being able to calculate centroids for label placement. ArcGIS/typical GIS software, on the other hand, reads non-tiled geometries, which allows it to calculate centroids on the fly. (incidentally, reading tiled geometries is what enables MB Studio to consume high-precision global datasets like roads/boundaries/terrain/etc--so, some things are lost w/ tiling, some things gained...) – James Conkling Mar 19 '16 at 21:32
  • ...that being said, if (judging from you pic) you are adding labels to administrative polygons, MB has already generated many useful tile layers for stuff like this. Check out mapbox-streets-v7 #admin layer and #state_label. Should be easy to pull these into your project, and then you don't need to maintain your own versions of the data. – James Conkling Mar 19 '16 at 21:37
  • "incidentally, reading tiled geometries is what enables MB Studio to consume high-precision global datasets like roads/boundaries/terrain/etc" Don't over-read the hype on vector tiles. High precision global datasets are easily handled in a variety of systems without vector tiles. That said, vector tiles solve a lot of problems for distribution and device rendering. – Craig Williams Aug 3 '16 at 21:45
  • > "High precision global datasets are easily handled in a variety of systems" Yes, but not in the browser. – James Conkling Aug 3 '16 at 21:57

Your Answer

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

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