Windy Community
    • Unread
    • Categories
    • Groups
    • Go to windy.com
    • Register
    • Login

    Hello World not working

    Scheduled Pinned Locked Moved Windy Plugins
    4 Posts 3 Posters 1.4k Views 2 Watching
    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.
    • luigitrevisiL Offline
      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
      • luigitrevisiL Offline
        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

        rittelsR 1 Reply Last reply Reply Quote 0
        • rittelsR Offline
          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
          
          luigitrevisiL 1 Reply Last reply Reply Quote 0
          • luigitrevisiL Offline
            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
            Windy Community  |  Powered by excellent NodeBB
            Terms of Use     Privacy Policy     Windy.com