0

I've followed several other posts but all the basic solutions have not worked. Basically, I can get it to show a GeoJSON correctly if I use a web link as the URL, but not a local file. For testing purposes, I will be using this GeoJSON file from OpenLayers, but the reason I need it to be a local file path is because I'm using a different GeoJSON file.

The following code works fine:

var vectorSource = new ol.source.Vector({
    format: new ol.format.GeoJSON(),
    url: 'https://openlayers.org/en/v4.6.4/examples/data/geojson/countries.geojson'
});

var vector = new ol.layer.Vector({
    source: vectorSource,
});

But, when I save that file to a local path and try linking it, I get nothing to show on the map. I do know for sure that the path exists and is correct because I have other things in the same resource directory that load fine using the same path directory:

var vectorSource = new ol.source.Vector({
    format: new ol.format.GeoJSON(),
    url: '../resources/countries.geojson'
});

var vector = new ol.layer.Vector({
    source: vectorSource,
});

What am I missing? I tried following the suggestion given here involving the IIS Manager but nothing has changed. I also tried changing the extension from .geojson to .js with no change also.

  • 1
    Can you open the file itself by navigating to its url in your browser? – Brynne Dec 14 '17 at 21:29
  • 1
    have you checked console.log? the only reason I can guess is about accessing .geojson file. – Chase Choi Dec 15 '17 at 9:04
  • 1
    @notkilroy No. I managed to get a log to show something late yesterday, though. It said something about how it can't be a local path, it has to be https:// or linked to a server. I tried running a local HTTP server with python and got other issues so I'm gonna try some other ways. It does appear that regular local will not work, though, unless you change some settings on the browser. – Hank Dec 15 '17 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.