Change units

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

Source code

HTML


<html>
    <head>
        <meta
            name="viewport"
            content="width=device-width, initial-scale=1.0, shrink-to-fit=no"
        />
        <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 src="script.js"></script>
    </body>
</html>

JavaScript


const options = {
    key: 'PsLAtXpsPTZexBwUkO7Mx5I', // REPLACE WITH YOUR KEY !!!
};

windyInit(options, windyAPI => {
    // All the params are stored in windyAPI.store
    const { overlays, broadcast } = windyAPI;

    const windMetric = overlays.wind.metric;
    console.log(windMetric);
    // '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
        console.log(overlay, newMetric);
    });
});