From 1b7c528d8491bc362eabe2ff49f7cff60d76a2e4 Mon Sep 17 00:00:00 2001 From: Jacek Kowalski <Jacek@jacekk.info> Date: Wed, 13 Mar 2019 00:03:41 +0000 Subject: [PATCH] Allow switching between tram and bus stop --- map.js | 34 +++++++++++++++++++++++++++------- lang_en.js | 2 ++ map.html | 4 ++-- lang_pl.js | 2 ++ 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/lang_en.js b/lang_en.js index 22d74bf..0b767ca 100644 --- a/lang_en.js +++ b/lang_en.js @@ -58,6 +58,8 @@ select_feature: 'There is more than one feature here. Select the proper one:', departures_for_stop: 'Click for stop departures (and not only this stop point).', + departures_for_trams: 'Switch to tram departures.', + departures_for_buses: 'Switch to bus departures.', tram_type_pattern: '$num $type ($floor)', high_floor: 'high floor', diff --git a/lang_pl.js b/lang_pl.js index 64f30ad..0212619 100644 --- a/lang_pl.js +++ b/lang_pl.js @@ -60,6 +60,8 @@ select_feature: 'W tym miejscu znajduje się więcej niż jeden element. Wybierz właściwy z listy:', departures_for_stop: 'Kliknij, by zobaczyć odjazdy dla całego przystanku (a nie tylko peronu).', + departures_for_trams: 'Przełącz na odjazdy tramwajów.', + departures_for_buses: 'Przełącz na odjazdy autobusów.', tram_type_pattern: '$num $type ($floor)', high_floor: 'wysokopodłogowy', diff --git a/map.html b/map.html index 3122d8d..5992df6 100644 --- a/map.html +++ b/map.html @@ -24,8 +24,8 @@ <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT" crossorigin="anonymous"></script> <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList"></script> <script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v5.3.0/build/ol.js" integrity="sha384-iQkGyyH4ioz3m+maM3s9MX1Oq67mACa4B9Z3ovUv3Sv37LJ96fx3WnZfLoiC3Wfl" crossorigin="anonymous"></script> -<script tyle="text/javascript" src="lang_pl.js?v5" id="lang_script"></script> +<script tyle="text/javascript" src="lang_pl.js?v6" id="lang_script"></script> <script tyle="text/javascript" src="common.js?v6"></script> -<script tyle="text/javascript" src="map.js?v13"></script> +<script tyle="text/javascript" src="map.js?v14"></script> </body> </html> diff --git a/map.js b/map.js index 4640626..089a952 100644 --- a/map.js +++ b/map.js @@ -58,6 +58,7 @@ }), }; var stops_type = ['st', 'sb', 'pt', 'pb']; +var stops_mapping = {}; var stops_source = {}; var stops_layer = {}; @@ -369,6 +370,7 @@ function updateStopSource(stops, prefix) { var source = stops_source[prefix]; + var mapping = stops_mapping[prefix]; for(var i = 0; i < stops.length; i++) { var stop = stops[i]; @@ -377,6 +379,12 @@ stop.geometry = getGeometry(stop); var stop_feature = new ol.Feature(stop); + + if(prefix.startsWith('p')) { + mapping[stop.stopPoint] = stop_feature; + } else { + mapping[stop.shortName] = stop_feature; + } stop_feature.setId(prefix + stop.id); @@ -599,8 +607,23 @@ break; case 's': type = lang.type_stop_tram; + var second_type = lang.departures_for_buses; + var mapping = stops_mapping['sb']; if(feature.getId().startsWith('sb')) { type = lang.type_stop_bus; + second_type = lang.departures_for_trams; + mapping = stops_mapping['st']; + } + + if(mapping[feature.get('shortName')]) { + additional = document.createElement('p'); + additional.className = 'small'; + addElementWithText(additional, 'a', second_type).addEventListener( + 'click', + function() { + featureClicked(mapping[feature.get('shortName')]); + } + ); } addElementWithText(thead, 'th', lang.header_line); @@ -622,12 +645,8 @@ addElementWithText(additional, 'a', lang.departures_for_stop).addEventListener( 'click', function() { - var source = stops_source['s' + feature.getId().substr(1,1)]; - featureClicked(source.forEachFeature(function(stop_feature) { - if(stop_feature.get('shortName') == feature.get('shortName')) { - return stop_feature; - } - })); + var mapping = stops_mapping['s' + feature.getId().substr(1,1)]; + featureClicked(mapping[feature.get('shortName')]); } ); @@ -851,7 +870,7 @@ if(!f1) return f2; if(!f2) return f1; - return (getDistance(point, f1) < getDistance(point, f2)) ? f1 : f2; + return (getDistance(point, f1) <= getDistance(point, f2)) ? f1 : f2; } function init() { @@ -876,6 +895,7 @@ renderMode: 'image', style: stops_style[type], }); + stops_mapping[type] = {}; }); stop_selected_source = new ol.source.Vector({ -- Gitblit v1.9.1