Navigation

    Windy Community

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

    Hello World not working

    Windy Plugins
    3
    4
    182
    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.
    • luigitrevisi
      luigitrevisi Photographer | Premium last edited by luigitrevisi

      Hello,
      I'm new to JavaScript and trying to learn how to develop a plug-in. I followed the tutorial in the wiki page, granted permissions and checked the https://localhost:9999/plugin.js is up and accessible. It's also confirmed by the message on top of the webpage: Your plugin is loaded & parsed OK.

      Unfortunately, when I open the Hello World plugin, nothing happens, while I expect the prompt message is shown, like in the video.

      Opening the log console, I found this:

      Uncaught (in promise) TypeError: map.getCenter is not a function
      

      I tried from Chrome 98.0.4758.80 and Safari 15.1. macOS 12.0.1

      Luigi

      1 Reply Last reply Reply Quote 0
      • luigitrevisi
        luigitrevisi Photographer | Premium last edited by luigitrevisi

        This is the content of the script.

                import map from '@windy/map';
                let popup = null;
        
                this.onopen = () => {
                    console.log('I am being opened');
                    const center = map.getCenter();
        
                    if (popup) {
                        popup.setLatLng(center);
                    } else {
                        popup = L.popup()
                            .setLatLng(center)
                            .setContent('Hello World')
                            .openOn(map);
                    }
                };
        
                this.onclose = () => {
                    console.log('I am being closed');
                    if (popup) {
                        map.removeLayer(popup);
                        popup = null;
                    }
                };
        

        From a quick look on Google, I read that the import statement cannot be used in the embedded scripts unless the script has a type=’ module.’ Could it be this the reason?

        Luigi

        rittels 1 Reply Last reply Reply Quote 0
        • rittels
          rittels Code contributor @luigitrevisi | Premium last edited by rittels

          @luigitrevisi

          I see the plugin examples have not been updated. Will try this week.

          In the meantime use :

          import {map} from '@windy/map'
          

          Also

          import utils from  '@windy/utils'
          const {$} = utils
          
          luigitrevisi 1 Reply Last reply Reply Quote 0
          • luigitrevisi
            luigitrevisi Photographer @rittels | Premium last edited by

            @rittels It worked now, thank you 🙏

            Luigi

            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