From c8f8dbca19f9f1ed3539f93e1785d4de70f2b093 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 12 Jun 2013 12:09:16 -0700 Subject: [PATCH] Port map key to new UI --- app/assets/javascripts/index.js | 1 - app/assets/javascripts/index/key.js | 34 ------------------- app/assets/javascripts/leaflet.key.js | 49 +++++++++++++++++++++++++-- app/views/site/index.html.erb | 4 --- config/locales/en.yml | 5 +-- 5 files changed, 50 insertions(+), 43 deletions(-) delete mode 100644 app/assets/javascripts/index/key.js 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 -- 2.39.5