Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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:

http://stackoverflow.com/questions/10075862/trouble-getting-openlayers-examples-with-jquery-working-in-jsfiddle

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.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

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/

share|improve this answer
    
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
add comment

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

share|improve this answer
    
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
add comment

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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