From: Tom Hughes Date: Tue, 14 Feb 2017 20:49:09 +0000 (+0000) Subject: Add layer switcher as soon as it is created X-Git-Url: https://git.openstreetmap.org/chef.git/commitdiff_plain/040284673ea136066015a89b9f93f888174f6cc8 Add layer switcher as soon as it is created Without this we get an error if we add a layer that is in the layer switcher to the map before the switcher is added. --- diff --git a/cookbooks/imagery/templates/default/imagery.js.erb b/cookbooks/imagery/templates/default/imagery.js.erb index 698c8926f..e1ed53515 100644 --- a/cookbooks/imagery/templates/default/imagery.js.erb +++ b/cookbooks/imagery/templates/default/imagery.js.erb @@ -3,15 +3,15 @@ function createMap(divName) { var map = L.map(divName).fitBounds(<%= @bbox.to_json %>); // Create a layer switcher - var layers = L.control.layers(null, null, {collapsed:false}); + var layers = L.control.layers(null, null, {collapsed:false}).addTo(map); // Add OpenStreetMap layer layers.addBaseLayer(L.tileLayer("//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", { attribution: "© OpenStreetMap and contributors, under an open license", maxZoom: 19 }), "OpenStreetMap"); - <% @layers.sort_by { |layer| layer[:name] }.each do |layer| -%> + // Create <%= layer[:name] %> layer var <%= layer[:name] %> = L.tileLayer(<%= layer[:url].to_json %>, { attribution: <%= layer[:attribution].to_json %>, @@ -31,8 +31,8 @@ function createMap(divName) { <% end -%> <% end -%> - // Add the layer switch to the mao - layers.addTo(map); + // Add the permalink control map.addControl(new L.Control.Permalink()); + return map; }