mapbox/mapbox-gl-js — pull request #683 by mourner (2014-08-11 12:43:07+00:00)
Title: Merge adjacent roads with the same text for labeling

Closes #56. Improves road labeling in many situations, especially on lower zoom levels:

Before:
![image](https://cloud.githubusercontent.com/assets/25395/3875520/83f41118-2152-11e4-9c28-4fa82075c814.png)

After:
![image](https://cloud.githubusercontent.com/assets/25395/3875524/8e07409e-2152-11e4-865b-56ad01c522bd.png)

It can descrease label density in some situations too — e.g. if a road was split into many short chunks shorter than the symbol-min-distance, before a label would be placed in each chunk, but with one big road, interpolated placement points collide with crossing road labels more often. But I think overall the improvement is worth it. I'd still appreciate playing with it a bit to make sure. @ansis @kkaefer

Performance overhead is not significant (e.g. < 5ms per tile in DC). This is because merging is o(n). I keep two indexes, one stores features by text-startPoint, other by text-endPoint. Then for each feature, I simply check whether it should be added as a new item or merged with existing one that's adjacent from either side.

![image](https://cloud.githubusercontent.com/assets/25395/3875647/f38d1492-2153-11e4-975f-63f40bd43ec1.png)