From: John Firebaugh Date: Wed, 12 Jun 2013 19:09:16 +0000 (-0700) Subject: Port map key to new UI X-Git-Tag: live~4854^2~32 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/c8f8dbca19f9f1ed3539f93e1785d4de70f2b093 Port map key to new UI --- diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index 710095e2d..c96d18afd 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -7,7 +7,6 @@ //= require leaflet.share //= require index/browse //= require index/export -//= require index/key //= require index/notes $(document).ready(function () { diff --git a/app/assets/javascripts/index/key.js b/app/assets/javascripts/index/key.js deleted file mode 100644 index 5592a2960..000000000 --- a/app/assets/javascripts/index/key.js +++ /dev/null @@ -1,34 +0,0 @@ -$(document).ready(function () { - $("#open_map_key").click(function (e) { - e.preventDefault(); - - var url = $(this).attr('href'), - title = $(this).text(); - - function updateMapKey() { - var mapLayer = getMapBaseLayerId(), - mapZoom = map.getZoom(); - - $(".mapkey-table-entry").each(function () { - var data = $(this).data(); - - if (mapLayer == data.layer && - mapZoom >= data.zoomMin && mapZoom <= data.zoomMax) { - $(this).show(); - } else { - $(this).hide(); - } - }); - } - - $("#sidebar_content").load(url, updateMapKey); - - openSidebar({ title: title }); - - $("#sidebar").one("closed", function () { - map.off("zoomend baselayerchange", updateMapKey); - }); - - map.on("zoomend baselayerchange", updateMapKey); - }); -}); diff --git a/app/assets/javascripts/leaflet.key.js b/app/assets/javascripts/leaflet.key.js index 5756f0c41..4906cfcff 100644 --- a/app/assets/javascripts/leaflet.key.js +++ b/app/assets/javascripts/leaflet.key.js @@ -1,4 +1,4 @@ -L.OSM.key = function(options) { +L.OSM.key = function (options) { var control = L.control(options); control.onAdd = function (map) { @@ -8,10 +8,55 @@ L.OSM.key = function(options) { $('') .attr('class', 'control-button') .attr('href', '#') - .attr('title', 'Map Key') + .attr('title', I18n.t("javascripts.key.tooltip")) .html('') + .on('click', toggle) .appendTo($container); + var $ui = $('
') + .attr('class', 'layers-ui') + .appendTo(options.uiPane); + + $('

') + .text(I18n.t('javascripts.key.title')) + .appendTo($ui); + + var $section = $('
') + .appendTo($ui); + + function toggle(e) { + e.stopPropagation(); + e.preventDefault(); + + var controlContainer = $('.leaflet-control-container .leaflet-top.leaflet-right'); + + if ($ui.is(':visible')) { + $(options.uiPane).hide(); + controlContainer.css({paddingRight: '0'}); + map.off("zoomend baselayerchange", update); + } else { + $(options.uiPane).show(); + controlContainer.css({paddingRight: '200px'}); + map.on("zoomend baselayerchange", update); + $section.load('/key', update); + } + } + + function update() { + var mapLayer = getMapBaseLayerId(map), + mapZoom = map.getZoom(); + + $(".mapkey-table-entry").each(function () { + var data = $(this).data(); + + if (mapLayer == data.layer && mapZoom >= data.zoomMin && mapZoom <= data.zoomMax) { + $(this).show(); + } else { + $(this).hide(); + } + }); + } + return $container[0]; }; diff --git a/app/views/site/index.html.erb b/app/views/site/index.html.erb index 478669529..525811ce4 100644 --- a/app/views/site/index.html.erb +++ b/app/views/site/index.html.erb @@ -2,10 +2,6 @@ <%= javascript_include_tag "index" %> <% end %> -<% content_for :left_menu do %> -
  • <%= link_to t("site.key.map_key"), {:action => :key}, :id => "open_map_key", :title => t("site.key.map_key_tooltip") %>

  • -<% end %> - <%= render :partial => 'home_link' %> <%= render :partial => 'sidebar' %> <%= render :partial => 'search' %> diff --git a/config/locales/en.yml b/config/locales/en.yml index c621b40fe..15fadd9dd 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1338,8 +1338,6 @@ en: submit_text: "Go" search_help: "examples: 'Alkmaar', 'Regent Street, Cambridge', 'CB2 5AQ', or 'post offices near Lünen'
    more examples..." key: - map_key: "Map Key" - map_key_tooltip: "Key for the map" table: entry: motorway: "Motorway" @@ -2042,6 +2040,9 @@ en: share: title: "Share" cancel: "Cancel" + key: + title: "Map Key" + tooltip: "Key for the map" map: base: standard: Standard