From 9bcd049c98eb09e0b822710448e64dd5c266c498 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Mon, 9 Sep 2013 15:17:09 +0100 Subject: [PATCH] Notice, and act on, changes to the layer parameter in the URL bar --- app/assets/javascripts/index.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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'}; -- 2.39.5