More fixes
This commit is contained in:
@@ -36,12 +36,26 @@ class LocationLayerManager:
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
def create_layer(self) -> None:
|
||||
"""Create the memory layer, add it to the project and load initial features.
|
||||
"""Create or reuse the layer and load initial features.
|
||||
|
||||
Raises:
|
||||
Exception: if the initial API fetch fails (layer is still added to the
|
||||
project but will be empty until reload_layer() succeeds).
|
||||
If a layer with the stored ID already exists in the project (e.g. loaded
|
||||
from a saved project file) it is reused rather than duplicated.
|
||||
"""
|
||||
# Check if a previously created layer is still alive in the project.
|
||||
stored_id, _ = QgsProject.instance().readEntry("BAPEBridge", "layer_id", "")
|
||||
if stored_id:
|
||||
existing = QgsProject.instance().mapLayer(stored_id)
|
||||
if existing is not None and not sip.isdeleted(existing):
|
||||
self.layer = existing
|
||||
return # layer already present — nothing more to do
|
||||
|
||||
# Guard against duplicate layers by name (e.g. toggled on twice).
|
||||
for lyr in QgsProject.instance().mapLayers().values():
|
||||
if lyr.name() in (self._NAME_OK, self._NAME_ERR):
|
||||
self.layer = lyr
|
||||
QgsProject.instance().writeEntry("BAPEBridge", "layer_id", lyr.id())
|
||||
return
|
||||
|
||||
self.layer = QgsVectorLayer("Point?crs=EPSG:4326", self._NAME_OK, "memory")
|
||||
if not self.layer.isValid():
|
||||
raise RuntimeError("Failed to create memory layer.")
|
||||
@@ -54,6 +68,7 @@ class LocationLayerManager:
|
||||
self.layer.updateFields()
|
||||
|
||||
QgsProject.instance().addMapLayer(self.layer)
|
||||
QgsProject.instance().writeEntry("BAPEBridge", "layer_id", self.layer.id())
|
||||
self._configure_marker()
|
||||
self._configure_labels()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user