Windy Community

    • Register
    • Login
    • Search
    • Unread
    • Categories
    • Groups
    • Go to windy.com

    Way to re-init the map: !!! Repeatedly calling "windyInit"...

    Developers
    4
    8
    325
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      Kostya Net last edited by

      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!

      Korina K 2 Replies Last reply Reply Quote 1
      • Korina
        Korina Administrator @Kostya Net last edited by

        @Kostya-Net Hello, please have a look at this thread about the same topic.

        Korina

        1 Reply Last reply Reply Quote 0
        • Referenced by  K Kostya Net 
        • K
          KimDotSe @Kostya Net last edited by

          @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

          K 1 Reply Last reply Reply Quote 0
          • K
            Kostya Net @KimDotSe last edited by

            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 , @marekd

            function 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());
            }
            
            K 1 Reply Last reply Reply Quote 1
            • K
              KimDotSe @Kostya Net last edited by

              @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 :/

              1 Reply Last reply Reply Quote 0
              • marekd
                marekd Administrator last edited by

                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. Calling windyInit 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".

                K 1 Reply Last reply Reply Quote 0
                • K
                  Kostya Net @marekd last edited by

                  Hello @marekd!
                  Totally agree with you that this is an ugly hack. And unfortunately we have no other options since you introduced the Repeatedly 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

                  marekd 1 Reply Last reply Reply Quote 0
                  • marekd
                    marekd Administrator @Kostya Net last edited by

                    @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.

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post
                    Windyty, S.E. - all rights reserved. Powered by excellent NodeBB
                    NodeBB & contributors, OSM & contributors, HERE maps
                    Terms and Conditions     Privacy Policy