.overlays: change of overlay's metrics

Each Windy's overlay has its own object in windyApi.overlays modules. Use these objects to change overlay's metric. For example for wind overlay, use read only value overlays.wind.metric to get actual value, .listMetrics() to get allowed ones, and .setMetric(metric) to set metric to the new value.

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'
      }

      windyInit( options, windyAPI => {

        // All the params are stored in windyAPI.store
        const { overlays, broadcast } = windyAPI

        var windMetric = overlays.wind.metric
        // 'kt' .. actually selected metric for wind overlay
        // Read only value! Do not modify.

        overlays.wind.listMetrics()
        // ['kt', 'bft', 'm/s', 'km/h', 'mph'] .. available metrics

        overlays.wind.setMetric('bft')
        // Metric for wind was changed to bft

        broadcast.on('metricChanged', (overlay,newMetric) => {

          // Any changes of any metric can be observed here

        })
      })
    </script>

  </body>
</html>


        
Fork me on GitHub