Skip to content

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

Merged
felixpalmer merged 12 commits intomasterfrom
felix/carto-line-poly-labels
Apr 17, 2025
Merged

CARTO: Automatically add labels to line & polygon layers#9449
felixpalmer merged 12 commits intomasterfrom
felix/carto-line-poly-labels

Conversation

@felixpalmer
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown
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.

Comment thread modules/carto/src/layers/label-utils.ts
Comment thread modules/carto/src/layers/label-utils.ts
Comment thread modules/carto/src/layers/label-utils.ts
Comment thread modules/carto/src/layers/label-utils.ts
Comment thread modules/carto/src/layers/label-utils.ts
Comment thread modules/carto/src/layers/vector-tile-layer.ts
Comment thread modules/carto/src/layers/vector-tile-layer.ts
@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