Leaflet map disappears when switching back to map scene

(kerguelen) #1

I’m still digging the map work using Leaflet. Very happy to see how it turns out.
I’ve got a problem here : map displays as it should on it’s scene. I’d like to be able to switch to another scene displaying info/tuto/etc and then switch back to the map scene. Unfortunately, when I switch back to map, nothing is displayed. What do I do wrong ? Also, when this will be resolved, I’d need when I come back to map scene to find the map (zoom, position) how I left it.
Any ideas ?

Directions :

  • Plan 1 / Plan 2 : displays given plan on map and passes special variable to map (zoom, map position for focus button)
  • Next scene : as mentioned
  • Target : focuses on Plan 1/Plan 2 to their specific coordinates

TestScene.hype.zip (386.3 KB)

(Jonathan Deutsch) #2

There’s a log that might indicate the issue:

Error in undefined: Error: Map container is already initialized.

Probably the Leaflet code doesn’t like being re-initialized and Hype is likely blanking out a lot of things needed.

The easiest solution would be to put the map element in a persistent symbol and then run the initMap() function On Symbol Load. This will preserve the element’s state and make sure it doesn’t get re-initialized. In my rough test it seemed to work.

(kerguelen) #3

Thank you @jonathan !
This makes the job very well. And even keeps track of map position before scene change.