Automatic Labels in Leaflet
Keywords: automatic labels, Leaflet, webcartography, open source
Abstract. Automatic labelling is a lacking feature in the popular client-side web mapping library, Leaflet. Although there exist various workarounds and substitutes, most of these do not fulfil the basic cartographic rules, e.g. avoiding text overlaps.
This paper discusses the various workarounds addressing this problem, and introduces the author’s solution, which extends Leaflet’s GeoJSON class with automatic labelling functionality. The new class displays labels for point, line or polygon features. Labels can be placed either on right or left side of points or automatically for better fitting. Markers for points are only displayed if their labels can be drawn without overlaps. Label text is specified either by property field name or a user-specified function. It is also possible to specify priority order of features (higher priority labels are drawn first) and to customize label styles.