1 function createMap(divName) {
3 var map = L.map(divName, {
5 }).fitBounds(<%= @bbox.to_json %>);
7 // Create a layer switcher
8 var layers = L.control.layers(null, null, {collapsed:false}).addTo(map);
10 // Add OpenStreetMap layer
11 layers.addBaseLayer(L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", {
12 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>",
15 <% @layers.sort_by { |layer| layer[:name] }.each do |layer| -%>
17 // Create <%= layer[:name] %> layer
18 var <%= layer[:name] %> = L.tileLayer(<%= layer[:url].to_json %>, {
19 attribution: <%= layer[:attribution].to_json %>,
20 maxZoom: <%= layer[:maxZoom].to_json %>
23 // Add <%= layer[:name] %> to layer switcher
24 <% if layer[:overlay] -%>
25 layers.addOverlay(<%= layer[:name] %>, <%= layer[:title].to_json %>);
27 layers.addBaseLayer(<%= layer[:name] %>, <%= layer[:title].to_json %>);
30 <% if layer[:default] -%>
31 // Add <%= layer[:name] %> to map
32 <%= layer[:name] %>.addTo(map);
36 // Add the permalink control
37 map.addControl(new L.Control.Permalink());
39 var lc = L.control.locate({
41 icon: '/location-arrow-solid.svg',
42 iconLoading: '/spinner-solid.svg'