Has anyone else noticed a problem getting OpenLayers to work within jsFiddle?

I can't see what's wrong with http://jsfiddle.net/dPdhZ/

or the others I've mentioned here:


But it's frustrating when they work fine as a static HTML document but not in a social, sharable format like jsFiddle.

EDIT: Don't assume that works and be cautious with using 100% widths/height on CSS for the map in jsFiddle.


Two things are missing in your example: a call to init (it's defined but not called) and some styling to make the map height larger than zero. Here's a working example: http://jsfiddle.net/a8kK4/

  • Thanks @Alex - this helped considerably. Two jsFiddle quirks though. 1) I don't know why init() wasn't already being called from the <body> tag. 2) If the height/width are set in CSS to 100% it doesn't doesn't always display. I am still baffled by jsfiddle.net/MS6Bn & jsfiddle.net/kPQfw but have managed (with your help) to get others working alright. – Mike Gifford Apr 10 '12 at 13:47

This is the way i do it. http://jsfiddle.net/FsAwY/

  • I played with this a bit jsfiddle.net/qn7Ks essentially to split it up a bit more into html, css & javascript. It is working there, partly because the init() isn't called in your script. Thanks though. Useful to have this example too. – Mike Gifford Apr 10 '12 at 14:00

Your Answer

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

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