From 41d831b5425a63ba1bca1dcb37c749d7682ab1f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20Schl=C3=BCter?= Date: Sat, 7 Feb 2015 19:42:13 +0100 Subject: [PATCH] Yay! --- static/js/main.js | 27 ++++++++++++++++++++++++--- views/index.tpl | 4 ++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/static/js/main.js b/static/js/main.js index 141312c..13bbe9c 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -1,13 +1,34 @@ (function () { + "use strict"; + // set up background map var map = L.map('map').setView([52.50, 13.40], 11); - var layer = new L.StamenTileLayer("toner-lite"); + var layer = new L.StamenTileLayer('toner-lite'); map.addLayer(layer); - $.get('/articles') + // get response from server and draw the map + var response; + $.getJSON('/articles/') .fail(console.error.bind(console)) .then(function (data) { console.log('Got data successfully!'); - console.log(data); + response = data; + + displayAll(); }); + + // logic for drawing follows + + var markers = []; + + /** + * Display all incidents at once + */ + function displayAll () { + for (var i = 0, l = response.length; i < l; i++) { + markers.push( + L.marker([response[i].lat, response[i].lng]).addTo(map).bindPopup(response[i].description) + ) + } + } })(); diff --git a/views/index.tpl b/views/index.tpl index e5089f2..2d5b9c8 100644 --- a/views/index.tpl +++ b/views/index.tpl @@ -21,8 +21,8 @@
- - + +