Skip to content

Fix/encoding issue 162#163

Merged
giswqs merged 3 commits intomainfrom
fix/encoding-issue-162
Feb 10, 2026
Merged

Fix/encoding issue 162#163
giswqs merged 3 commits intomainfrom
fix/encoding-issue-162

Conversation

@giswqs
Copy link
Copy Markdown
Member

@giswqs giswqs commented Feb 10, 2026

Fix #162

- 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
Copilot AI review requested due to automatic review settings February 10, 2026 02:54
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 10, 2026

@github-actions github-actions Bot temporarily deployed to pull request February 10, 2026 02:56 Inactive
@giswqs giswqs merged commit 8875d82 into main Feb 10, 2026
8 checks passed
@giswqs giswqs deleted the fix/encoding-issue-162 branch February 10, 2026 02:57
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

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 CesiumMap default 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.

Comment thread anymap/cesium.py
Comment on lines 128 to +142
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')

Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment thread anymap/cesium.py
Comment on lines 232 to 238
) -> 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,
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

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.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

encoding issue when open reading js and css file(non-utf8 windows)

2 participants