.broadcast: Observe what is happening

Major broadcasts are emmited by windApi.broadcast. Recieving and emmiting messages in Windy API has usuall syntax and methods: on, off, once, fire.

Tip: Use verbose: true as a parameter in start up options to see nice colorfull output in browser's console.

Main broadcasts

mapChanged

After Leaflet map has been panned or zoomed.

paramsChanged

When user changes some paramters (overlay, level, date etc...). Do not not use this event to start any intensive action since Windy now must load and render all the data. Use redrawFinished instead.

redrawFinished

Triggered when Windy has succesfully loaded and rendered requested data. Use this for triggering your own tasks.

metricChanged

After some of the units (wind, temp, ...) has been changed.

rqstOpen, rqstClose, closeAll

Requests to load and open or close lazy loaded plug-ins (see later)

pluginOpend, pluginClosed

Lazy loaded plugin was sucessully loaded and opend/closed

redrawLayers

Forces various renderers to render layers, for example after reconfiguring color gradient, or changing particle animation settings.

uiChanged

Whenever User Interface has been changed. Information for other UI components to recalculate their respective sizes and adapt themselfs to new layout.

Source code

        
<html>
  <head>
    <script src="https://unpkg.com/leaflet@1.4.0/dist/leaflet.js"></script>
    <script src="https://api4.windy.com/assets/libBoot.js"></script>
  	<style>
  		#windy {
  			width: 100%;
  			height: 300px;
  		}
  	</style>
  </head>
  <body>
    <div id="windy"></div>

    <script>

    const options = {
        key: 'PsLAtXpsPTZexBwUkO7Mx5I'

        // Tip: Use verbose true for nice console output
        // verbose: true

    }

    windyInit( options, windyAPI => {

        const { store, broadcast } = windyAPI
        // broadcast is main Windy's event emmiter that
        // let you know what is happening inside

        // Change overlays programatically
        var overlays = ['rain','wind','temp','clouds']
        , i = 0

        setInterval( ()=> {
            i = ( i === 3 ? 0 : i + 1 )
            store.set('overlay', overlays[ i ] )
        }, 800)

        // Observe the most important broadcasts
        broadcast.on('paramsChanged', params => {

            console.log('Params changed:', params )

        })

        broadcast.on('redrawFinished', params => {

            console.log('Map was rendered:', params )

        })
    })

    </script>

  </body>
</html>


        
Fork me on GitHub