1 function createMap(divName) {
3 var map = L.map(divName).fitBounds(<%= @bbox.to_json %>);
5 // Create layer and overlays variables
6 var leaflet_layers = {}
7 var leaflet_overlays = {}
9 // Add OpenStreetMap layer
10 leaflet_layers["OpenStreetMap"] = L.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
11 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>",
15 <% @layers.sort_by { |layer| layer[:name] }.each do |layer| -%>
17 <% if layer[:overlay] -%>
18 // Create <%= layer[:name] %> overlay
19 leaflet_overlays["<%= layer[:name] %>"] = L.tileLayer(<%= layer[:url].to_json %>, {
20 attribution: <%= layer[:attribution].to_json %>,
21 maxZoom: <%= layer[:maxZoom].to_json %>
24 <% if layer[:default] -%>
25 // Add <%= layer[:name] %> to map
26 leaflet_overlays["<%= layer[:name] %>"].addTo(map);
30 // Create <%= layer[:name] %> layer
31 leaflet_layers["<%= layer[:name] %>"] = L.tileLayer(<%= layer[:url].to_json %>, {
32 attribution: <%= layer[:attribution].to_json %>,
33 maxZoom: <%= layer[:maxZoom].to_json %>
36 <% if layer[:default] -%>
37 // Add <%= layer[:name] %> to map
38 leaflet_layers["<%= layer[:name] %>"].addTo(map);
44 // Create a layer switcher
45 var layers = L.control.layers(leaflet_layers, leaflet_overlays, {collapsed:false});
47 // Add the layer switch to the mao
49 map.addControl(new L.Control.Permalink({text: 'Permalink', layers: leaflet_layers, overlays: leaflet_overlays}));