Fix Cesium entity ID collision bug (issue #136) #161
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Fixes issue #136 where adding multiple landmarks/entities to a Cesium map results in the error:
An entity with id point_0 already exists in this collection.Root Cause
The existing code generates entity IDs using
len(self._layers)which causes ID collisions because:len(self._layers)can decrease and reuse previous IDsSolution
self._entity_counterthat only increments, never decreases_generate_entity_id(prefix)method that creates guaranteed unique IDsadd_point,add_billboard,add_polyline, andadd_polygonmethodsChanges
anymap/cesium.py:_entity_counter = 0in constructor_generate_entity_id(prefix)methodf"{type}_{len(self._layers)}"withself._generate_entity_id(type)in all entity creation methodsTesting
Verified the fix works correctly:
['point_0', 'point_1', 'billboard_2', 'polyline_3', 'polygon_4']Impact
Closes #136