1 function createMap(divName) {
3 var map = L.map(divName);
5 // Create a layer switcher
6 var layers = L.control.layers();
8 // Add OpenStreetMap layer
9 layers.addBaseLayer(L.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
10 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>",
14 <% @layers.sort_by { |layer| layer[:name] }.each do |layer| -%>
15 // Create <%= layer[:name] %> layer
16 var <%= layer[:name] %> = L.tileLayer(<%= layer[:url].to_json %>, {
17 attribution: <%= layer[:attribution].to_json %>,
18 maxZoom: <%= layer[:maxZoom].to_json %>
21 // Add <%= layer[:name] %> to layer switcher
22 layers.addBaseLayer(<%= layer[:name] %>, <%= layer[:title].to_json %>);
24 <% if layer[:default] -%>
25 // Add <%= layer[:name] %> to map
26 <%= layer[:name] %>.addTo(map);
29 <% @overlays.sort_by { |layer| layer[:name] }.each do |layer| -%>
30 // Add <%= layer[:name] %> to layer switcher
31 layers.addOverlay(L.tileLayer(<%= layer[:url].to_json %>, {
32 attribution: <%= layer[:attribution].to_json %>,
33 maxZoom: <%= layer[:maxZoom].to_json %>
34 }), <%= layer[:title].to_json %>);
37 // Add the layer switch to the mao
40 // Zoom to specified bounds
41 map.fitBounds(<%= @bbox.to_json %>);