Hello All,

Currently I am using leaflet map. And if I zoom out or zoom in or moved here and there on map then I go on another screen and if came back to screen on which my map is loaded. I am able to see the original state of ma which we have defined with latitude,longitude. 

But I want to persist the state of map which I was looking before moving to another screen.

For example : Step 1. Initially I am able to see city A as soon as map loaded.

Step 2.Then I moved on map and looking city B

Step 3. I navigate to another screen

Step 4: I come back to screen where map is loaded

Step 5. I am able to see city A, but I want to see city B.

How to achieve this kind of scenario

Any pointer would help

Thanks in advance.

- Prajakta

Solution

Hi Prajakta,


You must have a logic to initialize the leaflet map which your might being called under `onLoad`, with a Lat-Long pair and zoom level; which is the reason on navigating to the page it always starts at City-A.


If you want to override this default behaviour. Write the logic to persist the new map location (Lat-Long of City-B and the modified zoom level) to a session variable say LastVisited. Change the logic of map to the first check if the session variable LastVisited is not empty. If the session variable LastVisited has value then supply these values (of City-B) to the existing onLoad logic instead of the database values (of City-A).


Regards,

Swatantra

Solution

Swatantra Kumar wrote:

Hi Prajakta,


You must have a logic to initialize the leaflet map which your might being called under `onLoad`, with a Lat-Long pair and zoom level; which is the reason on navigating to the page it always starts at City-A.


If you want to override this default behaviour. Write the logic to persist the new map location (Lat-Long of City-B and the modified zoom level) to a session variable say LastVisited. Change the logic of map to the first check if the session variable LastVisited is not empty. If the session variable LastVisited has value then supply these values (of City-B) to the existing onLoad logic instead of the database values (of City-A).


Regards,

Swatantra


Sorry for very late reply... This solution worked for me. 

Thank you so much!

Thanks Prajakta for the update. Glad it worked.