Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problematic polygon labeling density #5583

Closed
rouen-sk opened this issue Nov 2, 2017 · 8 comments
Closed

Problematic polygon labeling density #5583

rouen-sk opened this issue Nov 2, 2017 · 8 comments

Comments

@rouen-sk
Copy link

rouen-sk commented Nov 2, 2017

I am trying mapbox-gl-js (v0.40.1) with some proprietary data (not OSM) and there is one thing which seems quite problematic - no way to control labeling density of polygons, especially near tile edges it seems. Example (red lines are approx tile boundaries):
image
Basically, I dont see any way to control density of the water labels here. My layer style is

{
    "id": "water_label_small",
    "type": "symbol",
    "minzoom": 14,
    "source": "my-vectors",
    "source-layer": "water",
    "filter": [ "in", "display_class", 4, 5 ],
    "layout": {
      "text-font": [ "Open Sans Italic" ],
      "text-field": "{name}",
      "text-max-width": 8,
      "text-size": 12      
    },
    "paint": {
      "text-color": "#277ec1",
      "text-halo-width": 1,
      "text-halo-color": "rgba(255,255,255,0.5)"
    }
  },

symbol-spacing works only for symbol-placement = line (which place labels on boundaries of polygons) and I cant use some big text-padding, because collision detecion is "global" (between all layers) so in urban areas (with lots of street names, road shields, place names etc.) water labels are never shown.
It would be super usefull to have something similar to symbol-spacing for polygons, or maybe option to have separate collision detection per layer (for chosen layer)?

@tomass
Copy link

tomass commented Nov 3, 2017

To my knowledge polygons are cut into parts during vector tile creation and are not "recombined" during rendering. So you get a number of separate polygons all of which follow their own labelling. This is why you're getting so many labels.
The only solution I could find was to have a separate layer (in vector tiles) for labels. That layer would contain label points calculated in the database from original (not cut) objects say using a ST_PointOnSurface function. Downside is that for really large objects label placement cannot be adjusted according to viewport, waterbody geometry, orientation etc. (something which is not done in mapbox-gl-js yet anyway).
In your particular case you would also need to have a waterbody as one multipolygon rather than a number of polygons in the original database. Otherwise ST_PointOnSurface will still be generating more than one label point (one for each polygon).
(But I could be wrong because I could be missing something)

@rouen-sk
Copy link
Author

rouen-sk commented Nov 3, 2017

@tomass I think there is some "recombining" going on - if you use "buffer" while generating tile, mapbox-gl-js "knows" the geometry overlaps into next tile and joins them - at least that is what I can see in building layer - building style has "shadows" which are drawn correctly even for buildings cut in half on tile boundary (and if you disable buffer, shadow is in fact drawn in the middle of building because mapbox-gl-js doesnt know about overlap).
So maybe drawing polygons themselves use "recombining" but labeling do not?

@tomass
Copy link

tomass commented Nov 3, 2017

When you have buffer, client draws "full" tile (with buffer) and then cut's of the buffer part. This is how you get correct buildings, this is how you get correct polygon outlines, this is how you do not get gaps for roads on tile boundaries even if you use rounded corners. But those are still "separate" geometries. In other words you do not need to actually merge geometries to get the correct result for those particular cases.
For labelling large polygons you do need a merged polygon to do correct labelling.
But once again, this is according to my observations only.

@andrewharvey
Copy link
Collaborator

Just as an aside I use https://github.com/andrewharvey/geojson-polygon-labels to generate a new point label source from a polygon layer.

@mollymerp
Copy link
Contributor

mollymerp commented Nov 3, 2017

yes @tomass is correct:

To my knowledge polygons are cut into parts during vector tile creation and are not "recombined" during rendering. So you get a number of separate polygons all of which follow their own labelling. This is why you're getting so many labels.

labeling polygons that span tile boundaries is a challenge, and one that Mapbox solves by including a separate 'marine label' layer in our vector tiles which assigns point and linestring locations to label bodies of water instead of using the polygon (pole of inaccessibility) as the label anchor (which finds the optimal label placement point per tile not per polygon). We currently do not have a way of re-assembling polygons across tile boundaries in order to place labels, so I suggest using geojson like @andrewharvey suggests or adding a new layer to your vector tiles.

@mourner
Copy link
Member

mourner commented Mar 15, 2018

Closing as not actionable for now. But note that we're currently researching ways to recover full features across tiles, but that will require a major VT spec revision and is not feasible short term.

@mohomedanees
Copy link

@andrewharvey can you give me how to fix this using https://github.com/andrewharvey/geojson-polygon-labels ?

@ecarrillo01
Copy link

@andrewharvey can you give me too how to fix this with geojson polylabel, I have a tiles source

SourceBoy added a commit to SourceBoy/sourceboy.github.io that referenced this issue Nov 24, 2020
alukach added a commit to alukach/bc-covid-map that referenced this issue Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants