From 31cb2dd046c8c22fca1d44071083db379ee6bb60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Kl=C3=BCnder?= Date: Sun, 29 Oct 2017 12:00:59 +0100 Subject: [PATCH] add markers when a location is selected --- src/c3nav/site/static/site/js/c3nav.js | 69 ++++++++++++++++++++------ 1 file changed, 53 insertions(+), 16 deletions(-) diff --git a/src/c3nav/site/static/site/js/c3nav.js b/src/c3nav/site/static/site/js/c3nav.js index 4ddf0b7c..ff8dbdfd 100644 --- a/src/c3nav/site/static/site/js/c3nav.js +++ b/src/c3nav/site/static/site/js/c3nav.js @@ -48,22 +48,23 @@ c3nav = { _locationinput_set: function (elem, location) { // set a location input c3nav._locationinput_reset_autocomplete(); - var $search = $('#search'); - if (location === null || location === undefined) { - elem.removeClass('selected').addClass('empty').data('location', null).data('lastlocation', null); - elem.find('input').val('').data('origval', null); - elem.find('small').text(''); - if (elem.attr('id') === 'destination-input') { + var $search = $('#search'), + location = (location === undefined) ? null : location, + title = (location === null) ? '' : location.title, + subtitle = (location === null) ? '' : location.subtitle; + elem.toggleClass('selected', location !== null).toggleClass('empty', location === null) + .data('location', location).data('lastlocation', location); + elem.find('input').val(title).data('origval', null); + elem.find('small').text(subtitle); + + if (elem.attr('id') === 'destination-input') { + if (location === null) { $search.removeClass('location-view'); + } else if (!$search.is('.location-view, .route-view')) { + $search.addClass('location-view'); } - return; - } - elem.addClass('selected').removeClass('empty').data('location', location).data('lastlocation', location); - elem.find('input').val(location.title).data('origval', null); - elem.find('small').text(location.subtitle); - if (elem.attr('id') === 'destination-input' && !$search.is('.location-view, .route-view')) { - $search.addClass('location-view'); } + if (location !== null) c3nav.add_location_to_map(location); }, _locationinput_reset: function (elem) { // reset this locationinput to its last location @@ -270,9 +271,13 @@ c3nav = { // setup level control c3nav._levelControl = new LevelControl().addTo(c3nav.map); + c3nav._markerLayers = {}; + c3nav._routeLayers = {}; for (var i = c3nav.levels.length - 1; i >= 0; i--) { var level = c3nav.levels[i]; - c3nav._levelControl.addLevel(level[0], level[1]); + var layerGroup = c3nav._levelControl.addLevel(level[0], level[1]); + c3nav._markerLayers[level[0]] = L.layerGroup().addTo(layerGroup); + c3nav._routeLayers[level[0]] = L.layerGroup().addTo(layerGroup); } c3nav._levelControl.finalize(); c3nav._levelControl.setLevel(c3nav.levels[0][0]); @@ -280,6 +285,30 @@ c3nav = { c3nav.schedule_refresh_tile_access(); }, + clear_map: function() { + for (var level_id in c3nav._markerLayers) { + c3nav._markerLayers[level_id].clearLayers() + } + for (var level_id in c3nav._routeLayers) { + c3nav._routeLayers[level_id].clearLayers() + } + }, + add_location_to_map: function(location) { + if (location.locations !== undefined) { + var bounds = EmptyBounds; + for (var i=0; i