From: Tom Hughes Date: Fri, 31 Aug 2012 09:29:32 +0000 (+0100) Subject: Select which key entries to show on the client X-Git-Tag: live~5431 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/815c98c977831a9a7f84dca49186f5eea7b4a283 Select which key entries to show on the client Rather than requesting a new key every time the zoom or layer changes, serve up all the entries initially with appropriate annotations to allow the client to decide which ones to show. --- diff --git a/app/assets/javascripts/key.js b/app/assets/javascripts/key.js index d22738aaa..daff6eee6 100644 --- a/app/assets/javascripts/key.js +++ b/app/assets/javascripts/key.js @@ -4,13 +4,25 @@ $(document).ready(function () { title = $(this).text(); function updateMapKey() { - $("#sidebar_content").load(url, { - layer: map.baseLayer.keyid, - zoom: map.getZoom() + var mapLayer = map.baseLayer.keyid, + mapZoom = map.getZoom(); + + $(".mapkey-table-entry").each(function () { + var entryLayer = $(this).attr("data-layer"), + entryZoomMin = parseInt($(this).attr("data-zoom-min")), + entryZoomMax = parseInt($(this).attr("data-zoom-max")); + + if (mapLayer == entryLayer && + mapZoom >= entryZoomMin && mapZoom <= entryZoomMax) { + $(this).show(); + } else { + $(this).hide(); + } }); } - updateMapKey(); + $("#sidebar_content").load(url, updateMapKey); + openSidebar({ title: title }); $("#sidebar").one("closed", function () { diff --git a/app/views/site/key.html.erb b/app/views/site/key.html.erb index ed36c0186..d401b4c34 100644 --- a/app/views/site/key.html.erb +++ b/app/views/site/key.html.erb @@ -1,19 +1,15 @@
<% YAML.load_file("#{Rails.root}/config/key.yml").each do |name,data| %> - <% if params[:layer] == name %> - <% data.each do |entry| %> - <% if params[:zoom].to_i >= entry['min_zoom'] && params[:zoom].to_i <= entry['max_zoom'] %> - - - - - <% end %> - <% end %> + <% data.each do |entry| %> + + + + <% end %> <% end %>
- <%= image_tag "key/#{name}/#{entry['image']}" %> - - <%= [*t("site.key.table.entry.#{entry['name']}")].to_sentence %> -
+ <%= image_tag "key/#{name}/#{entry['image']}" %> + + <%= [*t("site.key.table.entry.#{entry['name']}")].to_sentence %> +
diff --git a/config/routes.rb b/config/routes.rb index 1ef0c31af..955c5706f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -106,7 +106,7 @@ OpenStreetMap::Application.routes.draw do match '/login' => 'user#login', :via => [:get, :post] match '/logout' => 'user#logout', :via => [:get, :post] match '/offline' => 'site#offline', :via => :get - match '/key' => 'site#key', :via => :post + match '/key' => 'site#key', :via => :get match '/user/new' => 'user#new', :via => :get match '/user/terms' => 'user#terms', :via => [:get, :post] match '/user/save' => 'user#save', :via => :post diff --git a/test/functional/site_controller_test.rb b/test/functional/site_controller_test.rb index 86445e551..55dff2d96 100644 --- a/test/functional/site_controller_test.rb +++ b/test/functional/site_controller_test.rb @@ -47,7 +47,7 @@ class SiteControllerTest < ActionController::TestCase { :controller => "site", :action => "offline" } ) assert_routing( - { :path => "/key", :method => :post }, + { :path => "/key", :method => :get }, { :controller => "site", :action => "key" } ) assert_routing(