Skip to content

Fix clear_geoman_data bug#109

Merged
giswqs merged 1 commit intomainfrom
draw
Nov 7, 2025
Merged

Fix clear_geoman_data bug#109
giswqs merged 1 commit intomainfrom
draw

Conversation

@giswqs
Copy link
Copy Markdown
Member

@giswqs giswqs commented Nov 7, 2025

No description provided.

Copilot AI review requested due to automatic review settings November 7, 2025 16:29
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Nov 7, 2025

@github-actions github-actions Bot temporarily deployed to pull request November 7, 2025 16:30 Inactive
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 pull request enhances the Geoman drawing control integration by improving feature synchronization between JavaScript and Python, and adding example usage documentation. The changes focus on preventing circular update loops and supporting multiple Geoman API versions.

Key changes:

  • Improved bidirectional sync between JavaScript and Python for Geoman features with change detection to prevent feedback loops
  • Added comprehensive notebook examples demonstrating how to get, set, and clear drawn features
  • Enhanced feature import logic with support for multiple Geoman API versions and fallback mechanisms

Reviewed Changes

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

File Description
docs/examples/maplibre_geoman.ipynb Added documentation and code examples for managing drawn features (get, set, clear operations)
anymap/static/maplibre_widget.js Enhanced Geoman data synchronization with change detection, multi-source support, and improved import/export logic to prevent circular updates

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

Comment on lines +4096 to +4099
} else {
// Data changed from Python even though we just exported - process it
el._geomanSyncFromJs = false;
}
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

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

The logic in the else block (lines 4096-4099) sets el._geomanSyncFromJs = false but then proceeds to import the data. However, this branch is only reached when data has changed from Python even though we just exported. The comment on line 4097 correctly describes this, but the implementation doesn't prevent potential race conditions or feedback loops if Python modifies the data immediately after receiving it. Consider adding additional safeguards or logging to track such scenarios.

Copilot uses AI. Check for mistakes.
Comment on lines +4089 to +4090
const newDataStr = JSON.stringify(newData);
const lastExportedStr = JSON.stringify(lastExported);
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

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

Using JSON.stringify() for deep comparison of potentially large GeoJSON objects can be inefficient and may cause performance issues with many features or complex geometries. The order of properties in the JSON string may also differ even when the data is functionally identical. Consider using a more efficient comparison method, such as comparing feature counts and IDs, or using a library designed for deep object comparison.

Copilot uses AI. Check for mistakes.
"id": "7",
"metadata": {},
"source": [
"Clear all drawn features from the map:"
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

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

The markdown cell describing "Clear all drawn features from the map:" appears after code cells that already demonstrate clearing features (lines 55 and 107). This documentation should be placed before the relevant code examples, specifically before line 55 where m.clear_geoman_data() is first called.

Copilot uses AI. Check for mistakes.
Comment on lines +101 to +109
"cell_type": "code",
"execution_count": null,
"id": "6",
"metadata": {},
"outputs": [],
"source": [
"m.set_geoman_data({\"type\": \"FeatureCollection\", \"features\": []})"
]
},
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

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

The code cell on line 107 duplicates the functionality already demonstrated on line 55. Both cells clear geoman data using similar approaches. Consider removing this duplicate example or documenting why both approaches are shown.

Suggested change
"cell_type": "code",
"execution_count": null,
"id": "6",
"metadata": {},
"outputs": [],
"source": [
"m.set_geoman_data({\"type\": \"FeatureCollection\", \"features\": []})"
]
},

Copilot uses AI. Check for mistakes.
@giswqs giswqs merged commit d13a939 into main Nov 7, 2025
14 checks passed
@giswqs giswqs deleted the draw branch November 7, 2025 16:32
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.

2 participants