Skip to content

Add legend control#104

Merged
giswqs merged 4 commits intomainfrom
legend
Oct 26, 2025
Merged

Add legend control#104
giswqs merged 4 commits intomainfrom
legend

Conversation

@giswqs
Copy link
Copy Markdown
Member

@giswqs giswqs commented Oct 26, 2025

Fix #29

image

Copilot AI review requested due to automatic review settings October 26, 2025 14:17
Copy link
Copy Markdown
Contributor

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 a legend control feature to the map widget by integrating the @watergis/mapbox-gl-legend plugin. The implementation allows users to display and manage a map legend that automatically derives layer information from metadata, with support for custom labels, height constraints, and toggle icons.

Key Changes:

  • Added add_legend_control() Python API with auto-derivation of layer labels from metadata
  • Implemented JavaScript integration for the legend plugin with extensive customization options
  • Added layer control button to show/hide the legend with state tracking

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
anymap/maplibre.py Added add_legend_control() method with label derivation logic and control registration
anymap/static/maplibre_widget.js Implemented legend plugin loader, control initialization, styling patches, and layer control integration
anymap/static/maplibre_widget.css Added CSS styles for legend button states (active/inactive)
tests/test_anymap.py Added unit tests for legend control with auto-derived and custom targets

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 1116 to +1644
button.disabled = true;
button.title = 'Styling not available for Background layers';
button.title = 'Styling not available for this layer';
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

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

This code block is duplicated at lines 1689-1690. Consider extracting this into a helper function to reduce duplication, such as setButtonUnavailable(button, 'Styling not available for this layer').

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Oct 26, 2025

@github-actions github-actions Bot temporarily deployed to pull request October 26, 2025 14:18 Inactive
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 5669 to 5674
control = new maplibregl.GlobeControl(controlOptions || {});
break;
case 'layer_control':
control = new LayerControl(controlOptions || {}, map, model);
control = new LayerControl(controlOptions || {}, map, model, el);
break;
case 'geoman': {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Handle legend in addControl switch

The new Python API calls call_js_method("addControl", "legend", …) but the frontend’s case 'addControl' switch still only recognises the existing control types. When controlType is 'legend' it falls through to the default branch ("Unknown control type"), so the legend control is never created and the map state in _controls becomes out of sync with the UI. The restore logic that runs on initial load does schedule a legend, but any subsequent calls to MapLibreMap.add_legend_control won’t render anything. Please add a 'legend' branch here that invokes scheduleLegendInitialization similar to the other control cases.

Useful? React with 👍 / 👎.

@github-actions github-actions Bot temporarily deployed to pull request October 26, 2025 14:33 Inactive
@github-actions github-actions Bot temporarily deployed to pull request October 26, 2025 14:37 Inactive
@github-actions github-actions Bot temporarily deployed to pull request October 26, 2025 14:44 Inactive
@giswqs
Copy link
Copy Markdown
Member Author

giswqs commented Oct 26, 2025

legend_control.mp4

@giswqs giswqs merged commit ebf7e27 into main Oct 26, 2025
8 checks passed
@giswqs giswqs deleted the legend branch October 26, 2025 15:46
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.

Add mapbox-gl-legend

2 participants