From 32ded0c2d4fe1519cbc94a6f4ae70452b6d3d6f3 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Mon, 30 May 2016 20:50:37 +0100 Subject: [PATCH 1/1] Generate HTML and javascript for imagery sites --- cookbooks/imagery/files/default/imagery.css | 7 +++ cookbooks/imagery/recipes/au_agri.rb | 2 +- .../imagery/recipes/gb_hampshire_aerial.rb | 2 +- cookbooks/imagery/recipes/gb_os_sv.rb | 29 +++++----- cookbooks/imagery/recipes/gb_surrey_aerial.rb | 2 +- cookbooks/imagery/resources/layer.rb | 12 ++++ cookbooks/imagery/resources/site.rb | 57 ++++++++++++++++--- .../imagery/templates/default/imagery.js.erb | 35 ++++++++++++ .../imagery/templates/default/index.html.erb | 17 ++++++ 9 files changed, 139 insertions(+), 24 deletions(-) create mode 100644 cookbooks/imagery/files/default/imagery.css create mode 100644 cookbooks/imagery/templates/default/imagery.js.erb create mode 100644 cookbooks/imagery/templates/default/index.html.erb diff --git a/cookbooks/imagery/files/default/imagery.css b/cookbooks/imagery/files/default/imagery.css new file mode 100644 index 000000000..0a22de636 --- /dev/null +++ b/cookbooks/imagery/files/default/imagery.css @@ -0,0 +1,7 @@ +#map { + position: absolute; + top: 0px; + bottom: 0px; + left: 0px; + right: 0px; +} diff --git a/cookbooks/imagery/recipes/au_agri.rb b/cookbooks/imagery/recipes/au_agri.rb index f2fe09bcc..99dcb972a 100644 --- a/cookbooks/imagery/recipes/au_agri.rb +++ b/cookbooks/imagery/recipes/au_agri.rb @@ -21,7 +21,7 @@ include_recipe "imagery" imagery_site "agri.openstreetmap.org" do # aliases [ "agri.openstreetmap.org.au" ] - git_repository "https://github.com/Firefishy/osm-imagery-agri-site.git" + bbox [[-44.74673, 111.5332], [-9.75237, 154.6875]] end imagery_layer "au_ga_agri" do diff --git a/cookbooks/imagery/recipes/gb_hampshire_aerial.rb b/cookbooks/imagery/recipes/gb_hampshire_aerial.rb index d6734a420..28dd8e94a 100644 --- a/cookbooks/imagery/recipes/gb_hampshire_aerial.rb +++ b/cookbooks/imagery/recipes/gb_hampshire_aerial.rb @@ -21,7 +21,7 @@ include_recipe "imagery" imagery_site "hampshire.aerial.openstreetmap.org.uk" do # aliases - git_repository "https://github.com/Firefishy/osm-imagery-hampshire-aerial-site.git" + bbox [[50.564, -1.9899], [51.3606, -0.712738]] end imagery_layer "gb_hampshire_aerial_rgb" do diff --git a/cookbooks/imagery/recipes/gb_os_sv.rb b/cookbooks/imagery/recipes/gb_os_sv.rb index 40234e163..1710a8909 100644 --- a/cookbooks/imagery/recipes/gb_os_sv.rb +++ b/cookbooks/imagery/recipes/gb_os_sv.rb @@ -1,3 +1,4 @@ +# coding: utf-8 # # Cookbook Name:: imagery # Recipe:: gb_os_sv @@ -42,14 +43,14 @@ end imagery_site "os.openstreetmap.org" do aliases ["os.openstreetmap.org.uk"] - git_repository "https://github.com/Firefishy/osm-imagery-os-site.git" + bbox [[49.85, -10.5], [58.75, 1.9]] end imagery_layer "gb_os_sv_2010_04" do site "os.openstreetmap.org" projection "EPSG:27700" source "/data/imagery/gb/os-sv/ossv-2010-04-combined.vrt" - copyright "Contains Ordnance Survey data © Crown copyright and database right 2010" # FIXME: Correct Copyright? + copyright "Contains Ordnance Survey data © Crown copyright and database right 2010" # FIXME: Correct Copyright? background_colour "230 246 255" # OSSV Water Blue extension "os_sv_png" url_aliases ["/sv-2010-04"] @@ -59,7 +60,7 @@ imagery_layer "gb_os_sv_2010_11" do site "os.openstreetmap.org" projection "EPSG:27700" source "/data/imagery/gb/os-sv/ossv-2010-11-combined.vrt" - copyright "Contains Ordnance Survey data © Crown copyright and database right 2010" # FIXME: Correct Copyright? + copyright "Contains Ordnance Survey data © Crown copyright and database right 2010" # FIXME: Correct Copyright? background_colour "230 246 255" # OSSV Water Blue extension "os_sv_png" url_aliases ["/sv-2010-11"] @@ -69,7 +70,7 @@ imagery_layer "gb_os_sv_2011_05" do site "os.openstreetmap.org" projection "EPSG:27700" source "/data/imagery/gb/os-sv/ossv-2011-05-combined.vrt" - copyright "Contains Ordnance Survey data © Crown copyright and database right 2011" # FIXME: Correct Copyright? + copyright "Contains Ordnance Survey data © Crown copyright and database right 2011" # FIXME: Correct Copyright? background_colour "230 246 255" # OSSV Water Blue extension "os_sv_png" url_aliases ["/sv-2011-05"] @@ -79,7 +80,7 @@ imagery_layer "gb_os_sv_2011_11" do site "os.openstreetmap.org" projection "EPSG:27700" source "/data/imagery/gb/os-sv/ossv-2011-11-combined.vrt" - copyright "Contains Ordnance Survey data © Crown copyright and database right 2011" # FIXME: Correct Copyright? + copyright "Contains Ordnance Survey data © Crown copyright and database right 2011" # FIXME: Correct Copyright? background_colour "230 246 255" # OSSV Water Blue extension "os_sv_png" url_aliases ["/sv-2011-11"] @@ -89,7 +90,7 @@ imagery_layer "gb_os_sv_2012_05" do site "os.openstreetmap.org" projection "EPSG:27700" source "/data/imagery/gb/os-sv/ossv-2012-05-combined.vrt" - copyright "Contains Ordnance Survey data © Crown copyright and database right 2012" + copyright "Contains Ordnance Survey data © Crown copyright and database right 2012" background_colour "230 246 255" # OSSV Water Blue extension "os_sv_png" url_aliases ["/sv-2012-05"] @@ -99,7 +100,7 @@ imagery_layer "gb_os_sv_2012_11" do site "os.openstreetmap.org" projection "EPSG:27700" source "/data/imagery/gb/os-sv/ossv-2012-11-combined.vrt" - copyright "Contains Ordnance Survey data © Crown copyright and database right 2012" + copyright "Contains Ordnance Survey data © Crown copyright and database right 2012" background_colour "230 246 255" # OSSV Water Blue extension "os_sv_png" url_aliases ["/sv-2012-11"] @@ -109,7 +110,7 @@ imagery_layer "gb_os_sv_2013_05" do site "os.openstreetmap.org" projection "EPSG:27700" source "/data/imagery/gb/os-sv/ossv-2013-05-combined.vrt" - copyright "Contains Ordnance Survey data © Crown copyright and database right 2013" + copyright "Contains Ordnance Survey data © Crown copyright and database right 2013" background_colour "230 246 255" # OSSV Water Blue extension "os_sv_png" url_aliases ["/sv-2013-05"] @@ -119,7 +120,7 @@ imagery_layer "gb_os_sv_2013_11" do site "os.openstreetmap.org" projection "EPSG:27700" source "/data/imagery/gb/os-sv/ossv-2013-11-combined.vrt" - copyright "Contains Ordnance Survey data © Crown copyright and database right 2013" + copyright "Contains Ordnance Survey data © Crown copyright and database right 2013" background_colour "230 246 255" # OSSV Water Blue extension "os_sv_png" url_aliases ["/sv-2013-11"] @@ -129,7 +130,7 @@ imagery_layer "gb_os_sv_2014_04" do site "os.openstreetmap.org" projection "EPSG:27700" source "/data/imagery/gb/os-sv/ossv-2014-04-combined.vrt" - copyright "Contains Ordnance Survey data © Crown copyright and database right 2014" + copyright "Contains Ordnance Survey data © Crown copyright and database right 2014" background_colour "230 246 255" # OSSV Water Blue extension "os_sv_png" url_aliases ["/sv-2014-04"] @@ -139,7 +140,7 @@ imagery_layer "gb_os_sv_2014_10" do site "os.openstreetmap.org" projection "EPSG:27700" source "/data/imagery/gb/os-sv/ossv-2014-10-combined.vrt" - copyright "Contains Ordnance Survey data © Crown copyright and database right 2014" + copyright "Contains Ordnance Survey data © Crown copyright and database right 2014" background_colour "230 246 255" # OSSV Water Blue extension "os_sv_png" url_aliases ["/sv-2014-10"] @@ -149,7 +150,7 @@ imagery_layer "gb_os_sv_2015_05" do site "os.openstreetmap.org" projection "EPSG:27700" source "/data/imagery/gb/os-sv/ossv-2015-05-combined.vrt" - copyright "Contains Ordnance Survey data © Crown copyright and database right 2015" + copyright "Contains Ordnance Survey data © Crown copyright and database right 2015" background_colour "230 246 255" # OSSV Water Blue extension "os_sv_png" url_aliases ["/sv-2015-05"] @@ -160,7 +161,7 @@ imagery_layer "gb_os_sv_2015_11" do root_layer true projection "EPSG:27700" source "/data/imagery/gb/os-sv/ossv-2015-11-combined.vrt" - copyright "Contains Ordnance Survey data © Crown copyright and database right 2015" + copyright "Contains Ordnance Survey data © Crown copyright and database right 2015" background_colour "230 246 255" # OSSV Water Blue extension "os_sv_png" url_aliases ["/sv-2015-11"] @@ -171,7 +172,7 @@ imagery_layer "gb_os_sv_2016_04" do root_layer true projection "EPSG:27700" source "/data/imagery/gb/os-sv/ossv-2016-04-combined.vrt" - copyright "Contains Ordnance Survey data © Crown copyright and database right 2016" + copyright "Contains Ordnance Survey data © Crown copyright and database right 2016" background_colour "230 246 255" # OSSV Water Blue extension "os_sv_png" url_aliases ["/sv-2016-04", "/sv"] # Add "/sv" to current edition for backward compatibility diff --git a/cookbooks/imagery/recipes/gb_surrey_aerial.rb b/cookbooks/imagery/recipes/gb_surrey_aerial.rb index ff82958d2..1495c2060 100644 --- a/cookbooks/imagery/recipes/gb_surrey_aerial.rb +++ b/cookbooks/imagery/recipes/gb_surrey_aerial.rb @@ -21,7 +21,7 @@ include_recipe "imagery" imagery_site "surrey.aerial.openstreetmap.org.uk" do # aliases - git_repository "https://github.com/Firefishy/osm-imagery-surrey-aerial-site.git" + bbox [[51.0595, -0.873413], [51.466, 0.0617981]] end imagery_layer "gb_surrey_aerial" do diff --git a/cookbooks/imagery/resources/layer.rb b/cookbooks/imagery/resources/layer.rb index f67f13852..13b9b794c 100644 --- a/cookbooks/imagery/resources/layer.rb +++ b/cookbooks/imagery/resources/layer.rb @@ -17,6 +17,8 @@ # limitations under the License. # +require "yaml" + default_action :create property :layer, String, :name_property => true @@ -37,6 +39,15 @@ property :url_aliases, [String, Array], :default => [] property :revision, Fixnum, :default => 1 action :create do + file "/srv/imagery/layers/#{site}/#{layer}.yml" do + owner "root" + group "root" + mode 0644 + content YAML.dump(:name => layer, + :url => "http://#{site}/layer/#{layer}/{z}/{x}/{y}.png", + :attribution => copyright) + end + template "/srv/imagery/mapserver/layer-#{layer}.map" do cookbook "imagery" source "mapserver.map.erb" @@ -102,5 +113,6 @@ action :delete do end def after_created + notifies :create, "imagery_site[#{site}]" notifies :restart, "service[nginx]" end diff --git a/cookbooks/imagery/resources/site.rb b/cookbooks/imagery/resources/site.rb index 1bbfe82cb..6478faa52 100644 --- a/cookbooks/imagery/resources/site.rb +++ b/cookbooks/imagery/resources/site.rb @@ -17,21 +17,64 @@ # limitations under the License. # +require "yaml" + default_action :create property :name, String property :aliases, [String, Array], :default => [] -property :git_repository, String, :default => "https://github.com/Firefishy/osm-imagery-default.git" +property :bbox, Array, :required => true action :create do - git "/srv/#{name}" do - action :sync - repository "#{git_repository}" - revision "master" - enable_submodules true - retries 3 + directory "/srv/#{name}" do + user "root" + group "root" + mode 0755 + end + + directory "/srv/imagery/layers/#{name}" do + user "root" + group "root" + mode 0755 + recursive true + end + + directory "/srv/imagery/overlays/#{name}" do + user "root" + group "root" + mode 0755 + recursive true + end + + template "/srv/#{name}/index.html" do + source "index.html.erb" + user "root" + group "root" + mode 0644 + variables :title => name + end + + cookbook_file "/srv/#{name}/imagery.css" do + source "imagery.css" + user "root" + group "root" + mode 0644 + end + + layers = Dir.glob("/srv/imagery/layers/#{name}/*.yml").collect do |path| + YAML.load(::File.read(path)) + end + + overlays = Dir.glob("/srv/imagery/overlays/#{name}/*.yml").collect do |path| + YAML.load(::File.read(path)) + end + + template "/srv/#{name}/imagery.js" do + source "imagery.js.erb" user "root" group "root" + mode 0644 + variables :bbox => bbox, :layers => layers, :overlays => overlays end nginx_site name do diff --git a/cookbooks/imagery/templates/default/imagery.js.erb b/cookbooks/imagery/templates/default/imagery.js.erb new file mode 100644 index 000000000..fc83f6a1f --- /dev/null +++ b/cookbooks/imagery/templates/default/imagery.js.erb @@ -0,0 +1,35 @@ +function createMap(divName) { + // Create a map + var map = L.map(divName); + + // Create a layer switcher + var layers = L.control.layers(); + + // Add OpenStreetMap layer + layers.addBaseLayer(L.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", { + attribution: "© OpenStreetMap and contributors, under an open license", + maxZoom: 19 + }), "OpenStreetMap"); + + <% @layers.each do |layer| -%> + // Add <%= layer[:name].to_json %> layer + layers.addBaseLayer(L.tileLayer(<%= layer[:url].to_json %>, { + attribution: <%= layer[:attribution].to_json %> + }), <%= layer[:name].to_json %>); + + <% end -%> + <% @overlays.each do |layer| -%> + // Add <%= layer[:name].to_json %> layer + layers.addOverlay(L.tileLayer(<%= layer[:url].to_json %>, { + attribution: <%= layer[:attribution].to_json %> + }), <%= layer[:name].to_json %>); + + <% end -%> + // Add the layer switch to the mao + layers.addTo(map); + + // Zoom to specified bounds + map.fitBounds(<%= @bbox.to_json %>); + + return map; +} diff --git a/cookbooks/imagery/templates/default/index.html.erb b/cookbooks/imagery/templates/default/index.html.erb new file mode 100644 index 000000000..cf2c9a26e --- /dev/null +++ b/cookbooks/imagery/templates/default/index.html.erb @@ -0,0 +1,17 @@ + + + + + <%= @title %> + + + + + + + +
+ + -- 2.39.5