+function createMap(divName) {
+ // Create a map
+ var map = L.map(divName);
+
+ // Create a layer switcher
+ var layers = L.control.layers();
+
+ // Add OpenStreetMap layer
+ layers.addBaseLayer(L.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
+ attribution: "© <a target=\"_parent\" href=\"http://www.openstreetmap.org\">OpenStreetMap</a> and contributors, under an <a target=\"_parent\" href=\"http://www.openstreetmap.org/copyright\">open license</a>",
+ maxZoom: 19
+ }), "OpenStreetMap");
+
+ <% @layers.each do |layer| -%>
+ // Add <%= layer[:name].to_json %> layer
+ layers.addBaseLayer(L.tileLayer(<%= layer[:url].to_json %>, {
+ attribution: <%= layer[:attribution].to_json %>
+ }), <%= layer[:name].to_json %>);
+
+ <% end -%>
+ <% @overlays.each do |layer| -%>
+ // Add <%= layer[:name].to_json %> layer
+ layers.addOverlay(L.tileLayer(<%= layer[:url].to_json %>, {
+ attribution: <%= layer[:attribution].to_json %>
+ }), <%= layer[:name].to_json %>);
+
+ <% end -%>
+ // Add the layer switch to the mao
+ layers.addTo(map);
+
+ // Zoom to specified bounds
+ map.fitBounds(<%= @bbox.to_json %>);
+
+ return map;
+}