1 function createMap(divName) {
3 var map = L.map(divName).fitBounds(<%= @bbox.to_json %>);
5 // Create a layer switcher
6 var layers = L.control.layers(null, null, {collapsed:false}).addTo(map);
8 // Add OpenStreetMap layer
9 layers.addBaseLayer(L.tileLayer("//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
10 attribution: "© <a target=\"_parent\" href=\"https://www.openstreetmap.org\">OpenStreetMap</a> and contributors, under an <a target=\"_parent\" href=\"https://www.openstreetmap.org/copyright\">open license</a>",
13 <% @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 <% if layer[:overlay] -%>
23 layers.addOverlay(<%= layer[:name] %>, <%= layer[:title].to_json %>);
25 layers.addBaseLayer(<%= layer[:name] %>, <%= layer[:title].to_json %>);
28 <% if layer[:default] -%>
29 // Add <%= layer[:name] %> to map
30 <%= layer[:name] %>.addTo(map);
34 // Add the permalink control
35 map.addControl(new L.Control.Permalink());