0

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?

ahocevar
  • 5,448
  • 15
  • 29
Kate2707
  • 3
  • 3

1 Answers1

0

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.

Community
  • 1
  • 1
kryger
  • 12,906
  • 8
  • 44
  • 65
  • Hi, thanks for u answer... I can´t. in the folder examples i found file "simple_http_server.py" need i run this file?... i paste the folder examples in local web server but i can´t see correctly the example.. I don´t speak english and is difficult understeand, sorry. and thanks – Kate2707 May 10 '16 at 17:49
  • The commands only need Python installed, you don't need to add any new files. Can't comment on the *"can't see"* - this sounds less and less related to OpenLayers. Also, you may try to use Google Translate if in doubt. – kryger May 11 '16 at 08:45
  • The problem was relationed about my IIS... I configured & worked... Really thanks... – Kate2707 May 11 '16 at 15:31