I've been trying to load a load a local geoJSON and i keep recieving the following error:
leaflet/geojson/3_mittel.geojson' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.
I have tried a number of examples from this thread: https://gis.stackexchange.com/questions/68489/loading-external-geojson-file-into-leaflet-map
but i always get the same Error (CORS policy)
I can get it to work when using the raw.github link of the geoJSON but i dont want to use that method.
I also found another Post which is about this problem, but for OpenLayer and not for leaflet :
Maybe someone knows how to adjust the Code so that it works for leaflet.
let xhr = new XMLHttpRequest();
xhr.open('GET', 'geojson/3_mittel.geojson');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.responseType = 'json';
xhr.onload = function() {
if (xhr.status !== 200) return
L.geoJSON(xhr.response).addTo(map);
};
xhr.send();
This is my current code ( one example from the first link)