0

I'm trying to create a polygon on selected country using lat and lng from geojson, as geojson stores data in lng and lat and leaflet expects data in lat and lng I'm trying to swap it using the coordstolatlng function but it does not works.

const latlng= L.geoJSON(polygonCountry.geometry, {
                    coordsToLatLng: function (coordinates) {
                        //                    latitude , longitude, altitude
                        //return new L.LatLng(coords[1], coords[0], coords[2]); //Normal behavior
                        console.log(coordinates);
                        return new L.LatLng(coordinates[0], coordinates[1]);
                    }
                });
                console.log(latlng);

I'm getting the array of coordinates in console.log(coordinates). But not getting those arrays in console.log(latlng) as it is not returning the corrected array.

  • What does L.LatLng() do? From the comment above the console.log, the entries for lat and long seem to be swapped. Maybe this is the issue. But without more knowledge what L.LatLng does, I Can't help you further – user13897241 Sep 29 '22 at 14:20

0 Answers0