Is there a way to call an AWS GeoJSON file from leaflet and not get CORS errors? I took the advice of putting "var Flight =" at the beginning of a GeoJSON file and saving it as JavaScript. I have a map that works when I call the GeoJSON (as .sj) like this

<script src="https://myflights.s3.us-east-2.amazonaws.com/2023_0322/images/2023_0322.js" type="text/javascript"></script>

and then later using it with the variable "Flight"

var leftPoints = L.geoJSON(Flight, {
      pointToLayer: function (feature, latlng) { 
         label = String(feature.properties.Name)
         return L.circleMarker(latlng, geojsonGreen).bindTooltip(label, {permanent: false, opacity: 0.75}).openTooltip();
      onEachFeature: popUpLFeature}).addTo(map1);

my issue is when I try to change this using a variable to define the url: inside JavaScript and then trying to load the GeoJSON.

I have tried JQuery.getScript and $getJson but always end up with a CORS error.

Access to XMLHttpRequest at "https://myflights.s3.us-east-2.amazonaws.com/2023_0322/images/2023_0322.js" from origin 'https://my-test-2.azurewebsites.net' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I have tried methods mentioned here - How to get Leaflet layer control to work with GeoJSON files hosted online but this seems to give the same result.



Your Answer

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

Browse other questions tagged or ask your own question.