Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width,user-scalable=no"/>
    <title>JS SDK - Tropical Systems</title>

    <script defer src="https://cdn.jsdelivr.net/npm/luxon@2.0.2/build/global/luxon.min.js"></script>
    <script defer src="https://cdn.aerisapi.com/sdk/js/1.4.2/aerisweather.min.js"></script>
    <link rel="stylesheet" href="https://cdn.aerisapi.com/sdk/js/1.4.2/aerisweather.css">

    <style>
        body, html {
            height: 100%;
            margin: 0;
            padding: 0;
            width: 100%;
        }

        #app {
            height: 100%;
        }
    </style>
</head>
<body>

<div id="app"></div>

<script>
    window.onload = () => {

        let systems = {};
        let activeSystem = null;

        const aeris = new AerisWeather('q2ZG1wIYyW5jz2qMVs4XV', 'T15iEonob1d2H8kUPkbqlfk4gE2MvYQwiFbNfCVA'); 
        const utils = aeris.utils;

        // function to load the active systems form the AerisWeather API
        const loadSystems = () => {
            return aeris.api()
                .endpoint('tropicalcyclones')
                .limit(50)
                .sort('id:1')
                .get()
                .then((result) => {
                    const data = result.data;
                    if (data && Array.isArray(data)) {
                        data.forEach((item) => systems[item.id] = item);
                        return data;
                    }
                    return [];
                });
        };

        // defines the basin order to display in the Layer Panel and the
        // associated names
        const basinOrder = ['all', 'AL', 'EP', 'CP', 'WP', 'SH', 'IO'];
        const getBasinName = (code) => {
            const mapping = {
                AL: 'Atlantic',
                EP: 'East Pacific',
                CP: 'Central Pacific',
                WP: 'West Pacific',
                SH: 'Southern Hemisphere',
                IO: 'Indian Ocean'
            };
            return mapping[code] || code;
        };

        aeris.apps().then(apps => {

            // create the interactive map app
            const app = new apps.InteractiveMapApp('#app', {
                map: {
                    zoom  : 4,
                    layers: 'tropical-systems'
                }
            });

            // event to capture selecting an individual storm from the
            // map.
            app.on('layer:change:option', (e) => {
                const data = e.data || {};
                if (data.id === 'tropical-systems') {
                    const {value: {filters}, source} = data;
                    let systemId = null;
                    Object.keys(filters).forEach((key) => {
                        const val = filters[key];
                        if (!aeris.utils.isEmpty(val) && !aeris.utils.isset(systemId)) {
                            systemId = val;
                        }
                    });

                    if (source) {
                        if (systems[systemId]) {
                            activeSystem = systems[systemId];
                            source.reload({p: systemId});
                        } else if (systemId === 'all') {
                            activeSystem = 'all';
                            source.reload({p: ''});
                        }
                    }
                }
            });

            // event to zoom to the selected tropical system
            app.map.on('source:load:done', (e) => {
                const data = e.data || {};
                if (data.layer === 'tropical-systems') {
                    if (activeSystem) {
                        if (activeSystem === 'all') {
                            app.map.setView({lat: 40.0, lon: -93.5}, 4);
                        } else {
                            const [south, west, north, east] = activeSystem.profile.boundingBox;
                            app.map.setBounds({north, west, south, east});
                        }
                        app.closeInfoPanel();
                    }
                }
            });


            // after the interactive maps and modules are loaded
            // lets fetch the active storms, add to the layer panel
            // and enable the tropical module
            app.on('ready', () => {
                aeris.modules().then((modules) => {

                    // fetch the active systems
                    loadSystems().then((systems) => {
                        const groups = {
                            all: {
                                id      : 'tropical-systems-all',
                                segments: [{
                                    value: 'all',
                                    title: 'All Systems'
                                }]
                            }
                        };

                        // step through the active systems and add each storm
                        // to the proper basin group.
                        systems.forEach((system) => {
                            const basin = system.profile.basinCurrent;
                            let name = system.profile.name.replace(/-([ew])$/, (r) => `${r.toUpperCase()}`);

                            if (!groups[basin]) {
                                groups[basin] = {
                                    id      : `tropical-systems-basin-${basin}`,
                                    title   : `${getBasinName(basin)}`,
                                    segments: []
                                };
                            }

                            groups[basin].segments.push({
                                value: `${system.id}`,
                                title: `${name}`
                            });
                        });

                        modules.tropical.utils().then((tropUtils) => {

                            // utility functions for styling
                            const getMarkerDate = (data) => {
                                let tzName = utils.get(data, 'profile.tz', 'UTC');
                                let dt = luxon.DateTime.fromISO(utils.get(data, 'dateTimeISO')).setZone(tzName);
                                return dt.toFormat('h a ccc ZZZZ');
                            };

                            const getStormMarkerConfig = (data) => {
                                const {lat} = utils.get(data, 'loc');
                                const type = utils.get(data, 'details.stormCat');
                                const isCurrent = data.isCurrent;
                                const isForecast = data.isForecast;
                                const flipped = lat < 0 && tropUtils.flipForSouthernLat(type);

                                if (isCurrent || isForecast) {
                                    const catTextStyle = {
                                        value    : (type === 'STY') ? 'S' : type.replace(/[^\d]/g, ''),
                                        anchor   : 'start',
                                        position : 'center',
                                        translate: {
                                            y: -2
                                        },
                                        size     : 14,
                                        color    : '#ffffff',
                                        autosize : false
                                    };
                                    const nameTextStyle = {
                                        value    : getMarkerDate(data),
                                        anchor   : 'start',
                                        translate: {
                                            y: 22
                                        },
                                        size     : 11,
                                        color    : '#222222',
                                        stroke   : {
                                            color: '#ffffff',
                                            width: 2
                                        },
                                        autosize : false
                                    }

                                    let styles = {
                                        className: 'marker-tropicalcyclone',
                                        svg      : {
                                            image: {
                                                url      : (flipped && type === 'TD') ? tropUtils.icon(`${type}-flipped`) : tropUtils.icon(type),
                                                size     : [25, 25],
                                                transform: (flipped && type !== 'TD') ? 'scale(-1, 1) translate(-80, 0)' : ''
                                            },
                                            text : [catTextStyle, nameTextStyle]
                                        },
                                        size     : [80, 60],
                                        zIndex   : 50
                                    };

                                    if (isCurrent) {
                                        styles = utils.extend({}, styles, {
                                            svg : {
                                                image: {
                                                    size: [34, 34]
                                                },
                                                text : [
                                                    utils.extend({}, catTextStyle, {
                                                        translate: {
                                                            y: -3
                                                        },
                                                        size     : 20
                                                    }),
                                                    utils.extend({}, catTextStyle, {
                                                        value    : utils.get(data, 'details.stormShortName'),
                                                        size     : 16,
                                                        color    : '#222222',
                                                        translate: {
                                                            y: 22
                                                        },
                                                        stroke   : {
                                                            color: '#ffffff',
                                                            width: 3
                                                        }
                                                    })
                                                ]
                                            },
                                            size: [80, 80]
                                        });
                                    }

                                    return styles;
                                }

                                return {
                                    className: 'marker-tropicalcyclone',
                                    svg      : {
                                        shape: {
                                            type  : 'circle',
                                            fill  : {
                                                color: tropUtils.color(type)
                                            },
                                            stroke: {
                                                color: '#ffffff',
                                                width: 2
                                            },
                                            size  : [14, 14]
                                        },
                                        text : data.label ? {
                                            value    : utils.get(data, 'details.stormShortName'),
                                            anchor   : 'start',
                                            translate: {
                                                y: 12
                                            },
                                            autosize : false
                                        } : null
                                    },
                                    size     : data.label ? [60, 40] : [14, 14],
                                    zIndex   : data.label ? 50 : null
                                };
                            };


                            // add the tropical module, with the custom basin groups.
                            app.modules.add(modules.tropical.Systems, {
                                id      : 'tropical-systems-active',
                                source  : {
                                    data: {
                                        request: {
                                            endpoint: 'tropicalcyclones',
                                            action  : ':id',
                                            params  : {
                                                filter: 'active,geo'
                                            }
                                        }
                                    },
                                    style: {
                                        marker  : (data) => getStormMarkerConfig(data, aeris.utils),
                                        polyline: {
                                            stroke: {
                                                color    : '#4685D0',
                                                width    : 3,
                                                dashArray: '10 7 10 7'
                                            }
                                        }
                                    }
                                },
                                controls: {
                                    title           : 'Active Systems',
                                    filter          : true,
                                    multiselect     : false,
                                    groupMultiselect: false,
                                    reloadOnChange  : false,
                                    segments        : {
                                        groups: basinOrder
                                            .map((key) => groups[key])
                                            .filter((v) => aeris.utils.isset(v))
                                    }
                                }
                            });
                        });
                    });

                });
            });

        });
    };

</script>


</body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console