2 function createMap(divName) {
4 var map = L.map(divName, {
6 }).fitBounds(<%= @bbox.to_json %>);
8 // Create a layer switcher
9 var layers = L.control.layers(null, null, {collapsed:false}).addTo(map);
11 // Add OpenStreetMap layer
12 layers.addBaseLayer(L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", {
13 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>",
16 <% @layers.sort_by { |layer| layer[:name] }.each do |layer| -%>
18 // Create <%= layer[:name] %> layer
19 var <%= layer[:name].gsub("-", "_") %> = L.tileLayer(<%= layer[:url].to_json %>, {
20 attribution: <%= layer[:attribution].to_json %>,
21 maxZoom: <%= layer[:maxZoom].to_json %>
24 // Add <%= layer[:name] %> to layer switcher
25 <% if layer[:overlay] -%>
26 layers.addOverlay(<%= layer[:name].gsub("-", "_") %>, <%= layer[:title].to_json %>);
28 layers.addBaseLayer(<%= layer[:name].gsub("-", "_") %>, <%= layer[:title].to_json %>);
31 <% if layer[:default] -%>
32 // Add <%= layer[:name] %> to map
33 <%= layer[:name].gsub("-", "_") %>.addTo(map);
37 // Add the permalink control
38 map.addControl(new L.Control.Permalink());
40 var lc = L.control.locate({