Conversation
- Replace len(self._layers) based ID generation with proper entity counter - Add _generate_entity_id() method that ensures unique IDs across all entity types - Fix applies to add_point, add_billboard, add_polyline, and add_polygon methods - Prevents 'An entity with id point_0 already exists in this collection' error - Entity counter increments globally ensuring no ID reuse even after entity removal Resolves #136
…stems) Add encoding="utf-8" to all open() calls that read widget JS/CSS files. Fixes encoding errors on Windows with Chinese locale (zh-CN) where default GBK encoding caused failures reading UTF-8 encoded static files. Fixes #162
for more information, see https://pre-commit.ci
|
🚀 Deployed on https://698a9e40f7b4d1dd81a275a0--opengeos.netlify.app |
There was a problem hiding this comment.
Pull request overview
Fixes Windows (non-UTF-8 locale) decoding errors when importing/loading widget JS/CSS assets by explicitly reading them as UTF-8, addressing #162.
Changes:
- Add
encoding="utf-8"to reads of bundled JS/CSS assets across multiple widget backends. - Update
CesiumMapdefault entity ID generation to use an internal counter for uniqueness.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| anymap/potree.py | Read Potree widget JS/CSS using UTF-8 encoding. |
| anymap/openlayers.py | Read OpenLayers widget JS/CSS using UTF-8 encoding. |
| anymap/mapbox.py | Read Mapbox widget JS/CSS using UTF-8 encoding. |
| anymap/leaflet.py | Read Leaflet widget JS/CSS using UTF-8 encoding. |
| anymap/cesium.py | Read Cesium widget JS/CSS using UTF-8 encoding; adjust Cesium entity ID generation to be unique. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| navigation_help_button=navigation_help_button, | ||
| animation=animation, | ||
| should_animate=should_animate, | ||
| **kwargs, | ||
| ) | ||
|
|
||
| # Initialize entity counter for unique ID generation | ||
| self._entity_counter = 0 | ||
|
|
||
| def _generate_entity_id(self, prefix: str) -> str: | ||
| """Generate a unique entity ID with the given prefix. | ||
|
|
||
| Args: | ||
| prefix: The prefix for the entity ID (e.g., 'point', 'billboard') | ||
|
|
There was a problem hiding this comment.
The PR description references only the Windows encoding fix (#162), but this hunk also changes Cesium entity ID generation by introducing an instance counter and a new helper method. If this behavior change is intentional, please update the PR description (or split this into a separate PR) so reviewers/users understand the additional functional change being shipped.
| ) -> str: | ||
| """Add a point to the globe.""" | ||
| if entity_id is None: | ||
| entity_id = f"point_{len(self._layers)}" | ||
| entity_id = self._generate_entity_id("point") | ||
|
|
||
| entity_config = { | ||
| "id": entity_id, |
There was a problem hiding this comment.
Cesium entity IDs are now generated via an internal counter rather than len(self._layers). There are existing CesiumMap tests, but none assert that auto-generated entity IDs are unique across multiple add_* calls; adding a small unit test would prevent regressions back to duplicate IDs.
Fix #162