Using and extending the Stored Map Information in the Frontend

This document gives guidelines on how the store persists certain information for each map, which allows the user, when returning to a previously loaded map, to resume from the last state they left. This is done by tracking certain information in a special part of our store, which we then persist in the Browser's Local Storage using the 'Persist' middleware functionality of the Zustand store.

Store Structure

  • The storedMapInfo property lives under the UntrackedMapStore slice of the MapStore, as it tracks information not being persisted in the Backend.
  • This property contains an array, with an entry for each map, containing information about the state of the layers in the map (visibility, opacity), the currently selected layer, as well as other map-specific data, like the selected timeline date, the view state of the map (center coordinates and scale) and the visibility of the plant labels.

Adding a new Layer

  • As long as on map initialisation, the new layer is also added to the stored map info (See guide about implementing a new layer in the frontend), then this part of the store will track the visibility and opacity properties for you.
  • Any temporarily tracked information in the layer (e.g., the currently selected object, or current brush settings) that should not be persisted in local storage, should be added to the rest of the UntrackedMapStore like for the other layers.
  • The Stored Map Info could be extended to track other new relevant information. For that, simply extend the structure of the type and make sure you read/change the property in the correct map entry of the storedMapInfo object.

Versioning

  • As future changes in the persisted object structure might lead to property conflicts, we are using the 'Versioning' feature of the persist middleware.
  • Whenever there is a breaking change in the structure (e.g., property renamed, or removed), you can update the current version property in the MapStore.ts file, and provide a migrate method that can be called to migrate an existing stored entry to the new version. (See the documentation of the persist middleware for more information)