X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/394dcd73161a244e9a110aaffd7b2a6dfc168002..c30f20122d1f2f0f49240aae17d1233dd745e1e5:/app/assets/javascripts/index/browse.js diff --git a/app/assets/javascripts/index/browse.js b/app/assets/javascripts/index/browse.js index 5ca29e568..e04a864f4 100644 --- a/app/assets/javascripts/index/browse.js +++ b/app/assets/javascripts/index/browse.js @@ -2,7 +2,7 @@ //= require templates/browse/feature_list //= require templates/browse/feature_history -$(document).ready(function () { +function initializeBrowse(map) { var browseBounds; var layersById; var selectedLayer; @@ -10,20 +10,20 @@ $(document).ready(function () { var areasHidden = false; var locationFilter; - var dataLayer = new L.OSM.DataLayer(null, { - styles: { - way: { - weight: 3, - color: "#000000", - opacity: 0.4 - }, - area: { - weight: 3, - color: "#ff0000" - }, - node: { - color: "#00ff00" - } + var dataLayer = map.dataLayer; + + dataLayer.setStyle({ + way: { + weight: 3, + color: "#000000", + opacity: 0.4 + }, + area: { + weight: 3, + color: "#ff0000" + }, + node: { + color: "#00ff00" } }); @@ -35,10 +35,6 @@ $(document).ready(function () { onSelect(e.layer); }); - if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') { - map.layersControl.addOverlay(dataLayer, I18n.t("browse.start_rjs.data_layer_name")); - } - map.on('layeradd', function (e) { if (e.layer === dataLayer) { $.ajax({ url: "/browse/start", success: function (sidebarHtml) { @@ -69,10 +65,10 @@ $(document).ready(function () { map.on("moveend", updateData); updateData(); - $("#browse_filter_toggle").toggle(enableFilter, disableFilter); + $("#browse_filter_toggle").click(toggleFilter); $("#browse_hide_areas_box").html(I18n.t('browse.start_rjs.hide_areas')); - $("#browse_hide_areas_box").toggle(hideAreas, showAreas); + $("#browse_hide_areas_box").click(toggleAreas); $("#sidebar").one("closed", function () { map.removeLayer(dataLayer); @@ -96,28 +92,28 @@ $(document).ready(function () { } } - function enableFilter() { - $("#browse_filter_toggle").html(I18n.t('browse.start_rjs.view_data')); - locationFilter.setBounds(map.getBounds().pad(-0.2)); - locationFilter.enable(); - getData(); - } + function toggleFilter() { + if (locationFilter.isEnabled()) { + $("#browse_filter_toggle").html(I18n.t('browse.start_rjs.manually_select')); + locationFilter.disable(); + } else { + $("#browse_filter_toggle").html(I18n.t('browse.start_rjs.view_data')); + locationFilter.setBounds(map.getBounds().pad(-0.2)); + locationFilter.enable(); + } - function disableFilter() { - $("#browse_filter_toggle").html(I18n.t('browse.start_rjs.manually_select')); - locationFilter.disable(); getData(); } - function hideAreas() { - $("#browse_hide_areas_box").html(I18n.t('browse.start_rjs.show_areas')); - areasHidden = true; - getData(); - } + function toggleAreas() { + if (areasHidden) { + $("#browse_hide_areas_box").html(I18n.t('browse.start_rjs.hide_areas')); + areasHidden = false; + } else { + $("#browse_hide_areas_box").html(I18n.t('browse.start_rjs.show_areas')); + areasHidden = true; + } - function showAreas() { - $("#browse_hide_areas_box").html(I18n.t('browse.start_rjs.hide_areas')); - areasHidden = false; getData(); } @@ -151,7 +147,7 @@ $(document).ready(function () { setStatus(I18n.t('browse.start_rjs.loading')); - var url = "/api/" + OSM.API_VERSION + "/map?bbox=" + bounds.toBBOX(); + var url = "/api/" + OSM.API_VERSION + "/map?bbox=" + bounds.toBBoxString(); /* * Modern browsers are quite happy showing far more than 100 features in @@ -327,4 +323,4 @@ $(document).ready(function () { $("#browse_status").html(""); $("#browse_status").hide(); } -}); +}