Reputation: 3
This is an example for OpenLayers 3: http://openlayers.org/en/v3.15.1/examples/kml-earthquakes.html
I copy the code and paste in my project of Visual Studio 2012, but it doesn't work. After I download the examples directly from this page: http://openlayers.org/download/
I open any of the HTML examples but it doesn't work. Why would it work online and not locally from my PC. Do I need to import any additional library?
Upvotes: 0
Views: 275
Reputation: 13181
If you had opened your browser's JS console you'd see something like this:
ol.js:278 XMLHttpRequest cannot load file:///Users/(...snip...)/v3.15.1/examples/data/kml/2012_Earthquakes_Mag5.kml. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
The explanation can be easily found on Stack Overflow, the simplest solution would be to run a local web server that would expose your local the examples folder over HTTP. Arguably the easiest solution is to use python's in-built HTTP server. From inside of your OpenLayers/v3.15.1/
folder execute:
python -m SimpleHTTPServer 8000
or, if you're using Python 3:
python -m http.server 8000
Then, once you navigate to http://localhost:8000/examples/kml-earthquakes.html you'll see the example correctly loading exactly like the version deployed on openlayers.org.
Upvotes: 0