I am attempting to put a map on the page using a Jade template. The template looks like this:
html
head
script(src='http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js')
link(rel='stylesheet', href='http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css')
script.
var map = L.map("map").setView([51.505, -0.09], 13);
$(document).ready(function() {
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'}).addTo(map);
});
body
#map(style='height: 500px;')
When view the page the HTML generated looks like this:
<html>
<head>
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css"/>
<script>
var map = L.map("map").setView([51.505, -0.09], 13);
$(document).ready(function() {
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'}).addTo(map);
});
</script>
</head>
<body>
<div id="map" style="height: 500px;"></div>
</body>
</html>
Adding that code to JS fiddle (with the leaflet.js dependency) results in a working map - see JSfiddle Map
When debugging locally the error comes back as Error: Map container not found.
I've also tried wrapping it in a jquery document.ready to ensure the DOM is loaded.
EDIT: wrapping it in a document ready does work using the correct syntax, the code below works correctly:
html
head
h1= title
p Welcome to #{title}
script(src='http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js')
script(src='http://code.jquery.com/jquery-2.1.0.min.js')
link(rel='stylesheet', href='http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css')
script.
$(document).ready(function(){
var map = L.map("map").setView([51.505, -0.09], 13);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'}).addTo(map);
})
body
#map(style='height: 500px;')