Way to re-init the map: !!! Repeatedly calling "windyInit"...
-
Hi! We're using a paid plan at Fishfacts BV in our React driven web site. In our case we expose to the users an ability to switch between different map layers, where some of the layers belong to Windy but others are just plain Leaflet. So when switching between the layers we obviously need to reinitialize the maps. While it's safe for Leaflet map, the Windy map throws a warning, introduced last month.
!!! Repeatedly calling "windyInit" of an already initialized API is an unsupported functionality and will be removed in future versions!
So if there's any safe way to re-initialize Windy map? Or is it possible to completely destroy the current map instance so that the next time we can safely initialize the map again without any warnings being thrown?
Thank you!
-
@Kostya-Net Hello, please have a look at this thread about the same topic.
-
-
@Kostya-Net Hi! I got the same error as you and I fixed it by removing the global window.W when unmounting my component. So I still run init on mount but now I don't get the warning. Feels like a hack but I don't know any other way to fix this in a SPA. Hope this is some kind of help
-
Hello @KimDotSe !
Thank you for your reply!
We're hacking it like so, but still some windy related errors will be thrown in the console. Even though those errors do not affect the normal flow of things and allow the map re-initialization, I believe it could be much better and safer if the Windy team kindly fixes the following issue https://community.windy.com/topic/21973/error-by-gl-particles-js?_=1664174146851.
Guys, please take a look at that^^^ @Korina , @marekdfunction clearWindyOff() { window.W = void 0; window.wError = void 0; window.windyInit = void 0; window.windySentErrors = void 0; [...document.querySelectorAll('script[src*="windy"]')] .forEach((el) => el.remove()); }
-
@Kostya-Net Yeah I also got some more error from the lib-somthing file so I had to move the delete to right before running init again. Feels really hacky :/
-
Hey guys. The purpose of the
windyInit
method is to load all libraries and run their javascript, styles, etc... It is not mean to reset the map. Once the map is initialized, you should use just and only methods from the documentation (https://api.windy.com/map-forecast/docs).
So if you need to reset the map to your default settings, you should use documented methods to do this. CallingwindyInit
just and only load all libraries again and run their initialization. At this moment there is really ugly hack in our lib to keep it working as "reset map". -
Hello @marekd!
Totally agree with you that this is an ugly hack. And unfortunately we have no other options since you introduced theRepeatedly calling "windyInit"...
warning.Could you please provide a simple way to gracefully shut down the map by calling a standard LeafletJS method
map.remove()
because you use Leaflet under the hood (and expose this method). I really think it's not a big deal, but this will save us, your subscribers, gallons of our blood.Now if the method is called it is throwing a bunch of errors.
https://community.windy.com/topic/21973/error-by-gl-particles-js/2?_=1664174146851 -
@Kostya-Net I am sorry, but we will not change the logic. The API library is based on the code of our client, which does not assume that the map can be removed (the map is always visible on windy.com). It is not really an extension of the leaflet, leaflet is rather an extension of our API. Of course, the logic could be rewritten, but it is not a priority for us. Sorry about that.