Reference
You can use all features provided by the Leaflet
library. Only features provided by the JavaScript windyAPI
object are described
below.
Do not use features not listed here as we cannot guarantee that they will be available in other
versions of Map Forecast API.
store
The most important class of the API - it holds the state of the map and visualizations. It also allows
you to change the state. All values are stored in a key-value structure.
Check out this tutorial also to find out which keys are useful.
Methods
Method |
Returns |
Description |
get (key) |
any |
Returns the value, which has been set for the key . |
getAllowed (key) |
any[] | string |
Returns the array of all allowed values, which can be set for the key . String is
returned when the array cannot be returned. |
set (key, value, opts) |
- |
Set or change the value for the key . To skip all validations, use
{ forceChange: true } as opts . |
on (key, callback) |
- |
Bind a function callback to run it every time the value for the key is
changed. |
once (key, callback) |
- |
Bind a function callback to run it only once when the value for the
key is changed. |
off (key, callback) |
- |
Unbind the callback function. |
map
This is an instance of the Leaflet L.Map class. Check the Leaflet documentation for more info.
picker
Weather picker to get the value of the current layer at specific coordinates. The picker works only on
desktop, but you can make it work even for mobile devices on your own.
Check out this tutorial for better understanding.
Methods
Method |
Returns |
Description |
open ({ lat, lon }) |
- |
Open the picker at lat ,lon coordinates. |
close () |
- |
Close the picker. |
getParams () |
{ lat, lon, values, overlay } |
Get values from the open picker. |
on (event, callback) |
- |
Bind a function callback to run it every time the event was emitted.
|
once (event, callback) |
- |
Bind a function callback to run it only once when the event was
emitted. |
off (event, callback) |
- |
Unbind the callback function from the event . |
Events
Event |
Data |
Description |
pickerOpened |
{ lat, lon } |
Fired immediately after the picker is opened. |
pickerMoved |
{ lat, lon, values, overlay } |
Fired every time the picker is moved. |
pickerClosed |
- |
Fired immediately after the picker is closed. |
utils
Collection of some useful methods.
Methods
Method |
Returns |
Description |
deg2rad (deg) |
number |
Converts degree to radian. |
isNear ({ lat, lon }, { lat, lon }) |
boolean |
Check if two latLon objects are 0.01deg close to each other. |
isValidLatLonObj ({ lat, lon }) |
boolean |
Check if object contains lat and lon properties. Values are not
checked. |
lonDegToXUnit (deg) |
number |
Converts longitude degree <-180.0; 180.0> to mercator
<0.0, 1.0> . |
latDegToYUnit (deg) |
number |
Converts latitude degree <-85.05; 85.05> to mercator
<0.0, 1.0> . |
unitXToLonDeg (x) |
number |
Converts mercator <0.0, 1.0> to longitude degree
<-180.0; 180.0> . |
unitYToLatDeg (y) |
number |
Converts mercator <0.0, 1.0> to latitude degree
<-85.05; 85.05> . |
latLon2str ({ lat, lon }) |
string |
Encodes latLon object into string. |
str2latLon (hash) |
{ lat, lon } |
Decodes latLon from string hash. |
wave2obj (number[]) |
{ period, dir, size } |
Converts wave vectors to user friendly object. |
wind2obj (number[]) |
{ wind, dir } |
Converts wind vectors to user friendly object. |
broadcast
Main events broadcaster and emitter. Check out this tutorial to discover
some
useful events.
Methods
Method |
Returns |
Description |
fire (event, ...args) |
- |
Emits the event with args for callbacks.
|
on (event, callback) |
- |
Bind a function callback to run it every time the event was
emitted.
|
once (event, callback) |
- |
Bind a function callback to run it only once when the event was
emitted. |
off (event, callback) |
- |
Unbind the callback function from the event . |
overlays
This object contains all instances of all layers. It comes in handy when you need to change the layer
metric (check this tutorial for better understanding). Note that
layers that are not part of the API are also part of the object, but they are totally useless.
The list below are methods of one particular layer from the whole collection (e.g. wind
or temp
).
Methods
Method |
Returns |
Description |
convertNumber (value) |
number |
Converts default metric value to the value of currently selected metric. |
convertValue (value) |
string |
Converts default metric value to the value of currently selected metric, label
with units is included. |
cycleMetric () |
- |
Switches to the next available metric. |
listMetrics () |
string[] |
Returns the list of all available metrics. |
setMetric (metric) |
- |
Set specific metric . |
Attributes
Attribute |
Description |
metric |
Label of the currently selected metric. |
colors
This object contains all color definitions of all layers. It comes in handy when you need to change
the color definition of any layer. Note that
layers that are not part of the API are also part of the object, but they are totally useless.
The list below are methods of one particular color definition from the whole collection (e.g.
wind
or temp
).
Methods
Method |
Returns |
Description |
changeColor (colors) |
- |
Changes default colors. The method accepts the same format as the Customize color
scale
tool at Windy.com
exports. |
checkValidity (colors) |
boolean |
A basic check if the color scale is valid. It does not check values, just object structure. |
color (value) |
string |
Returns color for the value in rgb(r,g,b) string format. |
RGBA (value) |
number[] |
Returns color for the value in [R,G,B,A] array format. |
toDefault () |
- |
Resets colors to the default. |