Skip to content

Conversation

ibgreen-openai
Copy link
Collaborator

@ibgreen-openai ibgreen-openai commented Aug 21, 2025

Summary

  • add getMaxWidth accessor to TextLayer
  • allow individual labels to control their wrapping width
  • document getMaxWidth and expose through GeoJsonLayer

The layout is handled entirely on the CPU. TextLayer.transformParagraph resolves the effective maxWidth for each datum and runs the transformParagraph utility to wrap/truncate the text before any geometry is sent to the GPU, so the shader simply receives per-character offsets that already reflect the width limit. The sublayer that actually renders each glyph (MultiIconLayer) just reuses the existing IconLayer shaders and adds SDF uniforms; it does not read or use maxWidth, so no changes to shader code are necessary.

Questions

  • Ideally I would like to limit maxWidth based on world coordinates (OrthographicViews) because I am trying to make the text fit into containing boxes in world coordinates.
  • Do we still need maxWidth prop or should we deprecate it?

Testing

  • yarn test node test/modules/layers/text-layer/text-layer.spec.ts (fails: SyntaxError Unexpected identifier 'assert')

https://chatgpt.com/codex/tasks/task_i_68a736833ef0832c99608800972619f1

@coveralls
Copy link

Coverage Status

coverage: 91.226% (-0.004%) from 91.23%
when pulling 043bb11 on codex/add-getmaxwidth-prop-to-text-layer
into 55af702 on master.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for per-object text max width in TextLayer by introducing a getMaxWidth accessor function. This enhancement allows individual text labels to have their own wrapping width limits, providing more granular control over text layout.

Key changes:

  • Added getMaxWidth accessor to TextLayer for per-object width control
  • Updated text transformation logic to use object-specific max width values
  • Exposed the new accessor through GeoJsonLayer for broader usability

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
modules/layers/src/text-layer/text-layer.ts Implements the core getMaxWidth accessor functionality and updates text transformation logic
modules/layers/src/geojson-layer/sub-layer-map.ts Maps getTextMaxWidth prop to TextLayer's getMaxWidth accessor
docs/api-reference/layers/text-layer.md Documents the new getMaxWidth accessor with usage examples
docs/api-reference/layers/geojson-layer.md Documents the getTextMaxWidth prop forwarding to TextLayer

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

objectMaxWidth = value;
}
} else if (Number.isFinite(maxWidthAccessor) && maxWidthAccessor >= 0) {
objectMaxWidth = maxWidthAccessor;
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

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

[nitpick] The variable maxWidthAccessor is unnecessary since getMaxWidth is already descriptive. Consider using getMaxWidth directly in the conditional checks below to reduce code complexity.

Suggested change
objectMaxWidth = maxWidthAccessor;
if (typeof getMaxWidth === 'function') {
const value = getMaxWidth(object, objectInfo);
if (Number.isFinite(value) && value >= 0) {
objectMaxWidth = value;
}
} else if (Number.isFinite(getMaxWidth) && getMaxWidth >= 0) {
objectMaxWidth = getMaxWidth;

Copilot uses AI. Check for mistakes.

objectMaxWidth = value;
}
} else if (Number.isFinite(maxWidthAccessor) && maxWidthAccessor >= 0) {
objectMaxWidth = maxWidthAccessor;
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

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

[nitpick] This condition handles the case where getMaxWidth is a number rather than a function, but this seems inconsistent with the accessor pattern used elsewhere in the codebase. Consider if this number fallback is necessary or if it should always be treated as an accessor function.

Suggested change
objectMaxWidth = maxWidthAccessor;

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants