Conversation
There was a problem hiding this comment.
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.
| button.disabled = true; | ||
| button.title = 'Styling not available for Background layers'; | ||
| button.title = 'Styling not available for this layer'; |
There was a problem hiding this comment.
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').
|
🚀 Deployed on https://68fe33d3790dea66cfb46f5f--opengeos.netlify.app |
There was a problem hiding this comment.
💡 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".
| 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': { |
There was a problem hiding this comment.
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 👍 / 👎.
legend_control.mp4 |
Fix #29