0

I’m currently working on creating a map using an Esri feature layer, along with the Windy API for weather data visualization. I’m facing an issue where the Esri feature layer does not scale down as I zoom out on the map, while the Windy map adjusts properly. Or, the opposite will happen if I hover over a point on the feature layer and zoom, the feature layer will change size, but not the Windy map.

Here’s my current code:

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
    <title>Map Tiler, Esri, Windy</title>
    
    <!-- Load Leaflet from CDN -->
    <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" crossorigin="" />
    <script src="https://unpkg.com/[email protected]/dist/leaflet.js" crossorigin=""></script>

    <!-- Load Esri Leaflet from CDN -->
    <script src="https://unpkg.com/[email protected]/dist/esri-leaflet.js"></script>
    <script src="https://unpkg.com/[email protected]/dist/esri-leaflet-vector.js"></script>
    <script src="https://js.arcgis.com/4.24/"></script>

    <!-- Load Windy API -->
    <script src="https://api.windy.com/assets/map-forecast/libBoot.js"></script>

    <style>
        body {
            margin: 0;
            padding: 0;
        }

        #map {
            position: absolute;
            top: 0;
            bottom: 0;
            width: 100%;
        }

        #windy {
            position: absolute;
            top: 0;
            bottom: 0;
            width: 100%;
            z-index: 1; // To ensure the Windy map is seen above basemap and below feature layer
        }
    </style>
</head>

<body>
    <div id="map"></div>
    <div id="windy"></div>

    <script>
        // Initialize Leaflet map
        const map = L.map("map").setView([47.22231670231114, -122.44999808745531], 10);
        

        // Initialize Windy API
        let windyMap; // Variable to hold the Windy map instance
        function initWindy() {
            windyInit({
                key: 'xxxxxxxx', 
                lat: 47.22231670231114,    // Default latitude
                lon: -122.44999808745531,  // Default longitude
                zoom: 10                   // Default zoom level
            }).then(function (windy) {
                windyMap = windy; // Save the Windy map instance
                console.log('Windy map initialized');
                
                // Sync Windy zoom and center with Leaflet
                map.on('zoomend moveend', function () {
                    const center = map.getCenter();
                    const zoomLevel = map.getZoom();
                    windyMap.map.setCenter([center.lat, center.lng]);
                    windyMap.map.setZoom(zoomLevel);
                });

            }).catch(function (error) {
                console.error('Error initializing Windy API', error);
            });
        }

        // Add ESRI Feature Layer to Leaflet map
        L.esri.featureLayer({
            url: "xxxxxxxx",
        }).addTo(map);
        

        // Wait until the Windy library is fully loaded
        window.onload = function() {
            initWindy();
        };

    </script>

</body>

</html>

Even though the Windy map zooms in and out correctly, the Esri feature layer remains the same size and does not seem to respond to the zoom changes.

How do I fix it?

I am very new to coding / development.

1
  • You write "Esri feature layer remains the same size and does not seem to respond to the zoom changes". What kind of zoom changes? Mouse scroll or zoom button click? You also write in code comment "To ensure the Windy map is seen above basemap and below feature layer". That won't work, feature DOM element is child of map DOM element, so Windy map will always be above any Leaflet map layer ans so probably catch mouse event and not let them go to Leaflet map.
    – TomazicM
    Commented Sep 30 at 20:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.