Hello World not working
-
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
-
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?
-
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
-
@rittels It worked now, thank you 🙏