0

I am trying to add a GeoJSON file to my OpenLayers application and I am getting a cross origin request error.

My main question is can a GeoJSON be stored locally (within a folder on my C drive) and be used in OpenLayers?

I am just learning OL and I just want to be able to test some of the capabilities without setting up a web server.

Secondly, if its not possible to bring in a GeoJSON without having a web server or something like jetty running on my computer, is there a better format for bringing in features to OpenLayers?

Are KML files a better option for what I am trying to do?

1
  • How are you trying to add the file?
    – nmtoken
    May 18, 2016 at 7:24

1 Answer 1

1

Because of CORS-issues you cannot(?) load files directly from the harddrive.

But there is a simple solution: if you have python installed, you can use the builtin web server. Simply run

python -mhttp.server <portnumber> 

or

python -mSimpleHTTPServer <portnumber>

, depending on your python version (version 2 uses SimpleHTTPServer and Version 3 uses http.server). Use e.g. 8080 as portnumber, and then browse to localhost:8080. Run the command in the base directory of your webapp. URL paths are then relative to that directory.

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.