From 2d06bfe7796148f6f1c6ec3fa5c78f7d7fa76a97 Mon Sep 17 00:00:00 2001 From: Tom Russell Date: Fri, 3 Aug 2018 11:04:53 +0100 Subject: [PATCH] Sketch switching data layers --- frontend/main.js | 37 ++++++++++++++++++++++++++++++++----- frontend/maps.html | 3 ++- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/frontend/main.js b/frontend/main.js index ab34a262..37ace6f5 100755 --- a/frontend/main.js +++ b/frontend/main.js @@ -31,7 +31,7 @@ function map(){ zoom: 16, doubleClickZoom: false, }); - + // Controls var attr = L.control.attribution({prefix: ""}); attr.addAttribution("Contains OS data © Crown copyright: OS Maps baselayers and building outlines. Building attribute data is © Colouring London contributors"); @@ -43,12 +43,39 @@ function map(){ }).addTo(map); // Rendered layer - var outline_layer = L.tileLayer('/tiles/date_year/{z}/{x}/{y}.png', { + var data_layers = {} + data_layers.size_storeys = L.tileLayer('/tiles/size_storeys/{z}/{x}/{y}.png', { maxZoom: 20, minZoom: 14 }) - outline_layer.setZIndex(10); - outline_layer.addTo(map); + data_layers.size_storeys.setZIndex(10); + + data_layers.date_year = L.tileLayer('/tiles/date_year/{z}/{x}/{y}.png', { + maxZoom: 20, + minZoom: 14 + }) + data_layers.date_year.setZIndex(10); + + data_layers.date_year.addTo(map); + var active_data_layer = "date_year" + + var year_el = document.querySelector('li[data-map="date_year"]') + year_el.addEventListener("click", function(e){ + if (active_data_layer !== "date_year"){ + map.removeLayer(data_layers.size_storeys) + data_layers.date_year.addTo(map) + active_data_layer = "date_year" + } + }) + var storey_el = document.querySelector('li[data-map="size_storeys"]') + storey_el.addEventListener("click", function(e){ + if (active_data_layer !== "size_storeys"){ + map.removeLayer(data_layers.date_year) + data_layers.size_storeys.addTo(map) + active_data_layer = "size_storeys" + } + }) + var highlight_layer = L.tileLayer('/tiles/highlight/{z}/{x}/{y}.png', { maxZoom: 20, @@ -79,7 +106,7 @@ function map(){ if (data.error){ preview_el.textContent = 'Click a building to see data'; } else { - preview_el.textContent = JSON.stringify(data, ["id", "date_year", "date_source", "uprns"], 2); + preview_el.textContent = JSON.stringify(data, ["id", "date_year", "date_source", "size_storeys", "uprns"], 2); } }) }) diff --git a/frontend/maps.html b/frontend/maps.html index 62905690..f31175a8 100755 --- a/frontend/maps.html +++ b/frontend/maps.html @@ -59,7 +59,8 @@

View Maps

Building