Auto-generalized labels on multi-layer Leaflet maps
Keywords: automatic labels, Leaflet, web cartography, open source
Abstract. Leaflet is one of the most popular client-side web mapping libraries. It is lightweight, easy-to-use, especially for ones without strong programming background. The library, however, lacks a very important feature: map labels.
The author developed a plugin for Leaflet that makes it easy to show map labels for any vector layer. Labels are automatically generalized to avoid overlapping texts. Point symbols or markers can be linked to their labels i.e. if the label cannot be displayed, its marker is also removed. Labels are drawn in priority order. Priorities, as well as label texts and styles can be highly customized with respect to feature/layer properties.
Labels are displayed as HTML <span>
elements, allowing developers to create complex labels with various borders or backgrounds as well, by CSS styling rules.
The plugin extends the Map class, while label properties can be set for each layer separately. Collision conflicts are checked between layers as well. Dynamic addition/removal of map objects is also supported. Performance of the plugin was tested with 3700 map objects (mixed data of points, polygons, and lines). Updating map labels after zoom/pan required only fragments of seconds.
The source code, user guide and examples are available at https://github.com/samanbey/leaflet-mapwithlabels