Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

61
Views
Leaflet export geojson switch lat and long

Hello I'm currently using this code to draw Leaflet polygons etc. it works perfect but when I export to geoJson I end up getting lat and long in "reversed" positions How can I change them so that they like to switch places so that instead of -9.0230, 29.923 it will be 29.923, -9.0230.

var featureGroup = L.featureGroup().addTo(map);

var drawControl = new L.Control.Draw({
  edit: {
    featureGroup: featureGroup,
  },
}).addTo(map);

map.on("draw:created", function (e) {
  // Each time a feaute is created, it's added to the over arching feature group
  featureGroup.addLayer(e.layer);
});

// on click, clear all layers
document.getElementById("delete").onclick = function (e) {
  featureGroup.clearLayers();
};

document.getElementById("export").onclick = function (e) {
  // Extract GeoJson from featureGroup
  var data = featureGroup.toGeoJSON();

  // Stringify the GeoJson
  var convertedData =
    "text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(data));

  // Create export
  document
    .getElementById("export")
    .setAttribute("href", "data:" + convertedData);
  document.getElementById("export").setAttribute("download", "data.geojson");
};
7 months ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.