Skip to content

CARTO: Automatically add labels to line & polygon layers #9449

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

Merged
merged 12 commits into from
Apr 17, 2025

Conversation

felixpalmer
Copy link
Collaborator

@felixpalmer felixpalmer commented Feb 19, 2025

Background

It is often desirable to add labels to line or polygon layers, but calculating the positioning is not trivial - especially if the data is being loaded tile by tile.

This PR add functionality to the VectorTileLayer to automatically add labels when the autoLabels prop is set.

Usage:

const vectorTileLayer = new VectorTileLayer({
  // Configure as normal
  data: <LINE or POLYGON data>,
  ...,
  // Add props for text rendering
  getText: f => f.properties.name
});
Screenshot 2025-02-19 at 15 17 29

Doc PR to follow

Change List

  • Added new utils file label-utils that calculates label positions
  • Tests for label-utils
  • Tidy types and rework common code

@coveralls
Copy link

coveralls commented Feb 19, 2025

Coverage Status

coverage: 91.488% (-0.04%) from 91.523%
when pulling c410f09 on felix/carto-line-poly-labels
into dfa6d41 on master.

@felixpalmer felixpalmer changed the title WIP: CARTO: Automatically add labels to line & polygon layers CARTO: Automatically add labels to line & polygon layers Feb 19, 2025
Copy link
Collaborator

@donmccurdy donmccurdy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! A few comments, questions, and ideas - all optional.

@felixpalmer felixpalmer merged commit fa59506 into master Apr 17, 2025
4 checks passed
@felixpalmer felixpalmer deleted the felix/carto-line-poly-labels branch April 17, 2025 15:17
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

Successfully merging this pull request may close these issues.

4 participants