From: Tom Hughes Date: Mon, 9 Sep 2013 14:17:09 +0000 (+0100) Subject: Notice, and act on, changes to the layer parameter in the URL bar X-Git-Tag: live~4800 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/9bcd049c98eb09e0b822710448e64dd5c266c498 Notice, and act on, changes to the layer parameter in the URL bar --- diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index d577e0cf7..a19a6a61e 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -51,13 +51,24 @@ $(document).ready(function () { }) ]; - for (var i = layers.length - 1; i >= 0; i--) { - if (i === 0 || params.layers.indexOf(layers[i].options.code) >= 0) { - map.addLayer(layers[i]); - break; + function updateLayers(params) { + var layerParam = params.layers || "M"; + + for (var i = layers.length - 1; i >= 0; i--) { + if (layerParam.indexOf(layers[i].options.code) >= 0) { + map.addLayer(layers[i]); + } else { + map.removeLayer(layers[i]); + } } } + updateLayers(params); + + $(window).on("hashchange", function () { + updateLayers(OSM.mapParams()); + }); + map.noteLayer = new L.LayerGroup(); map.noteLayer.options = {code: 'N'};