diff options
author | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2020-07-03 00:56:09 +0200 |
---|---|---|
committer | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2020-07-03 00:56:09 +0200 |
commit | 6673ec6b02eaacda917978e56ca1498d7b1606d1 (patch) | |
tree | 53f14604fe0265e99a79e236619f5612b6953866 /htdocs | |
parent | 5a75bd30a6a230d0d5364faaa85ea3285e21dac9 (diff) | |
download | lifomapserver-signals.tar.gz lifomapserver-signals.tar.bz2 lifomapserver-signals.zip |
First working version of routingsignals
Diffstat (limited to 'htdocs')
-rw-r--r-- | htdocs/mapscript.js | 71 |
1 files changed, 63 insertions, 8 deletions
diff --git a/htdocs/mapscript.js b/htdocs/mapscript.js index 38b336c..bbd591e 100644 --- a/htdocs/mapscript.js +++ b/htdocs/mapscript.js @@ -209,12 +209,68 @@ var signalMarkerOptions = { -function go_to_signal(ps) { +function go_to_signal(ps, side) { if (signals[ps]) { signals[ps].layer.openPopup() } } +var RC = "" +var LN = "" + +function signal_routing(ps, side, rc, ln) { + if (signals[ps]) { + var routes = signals[ps].properties.sides[side].routes + for (let j=0;j<routes.length;j++) { + if (routes[j].auto) + return [routes[j].endpoint, routes[j].endpoint_side] + } + for (let j=0;j<routes.length;j++) { + let r = routes[j]; + if (r.ars.RC) { + for (let c of r.ars.RC) { + if (rc.some(o => o == c)) + return [r.endpoint, r.endpoint_side] + } + } + if (r.ars.LN) { + for (let c of r.ars.LN) { + if (ln.some(o => o == c)) + return [r.endpoint, r.endpoint_side] + } + } + } + for (let j=0;j<routes.length;j++) { + if (routes[j].ars["default"]) + return [routes[j].endpoint, routes[j].endpoint_side] + } + } + return [false,false] +} + +function form_handler(ps, side) { + RC= document.getElementById("route"+ps+"S"+side+"rc").value + LN = document.getElementById("route"+ps+"S"+side+"ln").value + E = signal_routing(ps, side, RC.split(" "), LN.split(" ")) + if (E[0]) + go_to_signal(E[0], E[1]) + return false; +} + +function station_popup_handler() { + var ps = this.feature.properties.pos; + var sidea = document.getElementById("route"+ps+"S"+0+"rc") + var sideb = document.getElementById("route"+ps+"S"+1+"rc") + if (sidea) { + sidea.value = RC + document.getElementById("route"+ps+"S"+0+"ln").value = LN + } + if (sideb) { + sideb.value = RC + document.getElementById("route"+ps+"S"+1+"ln").value = LN + } +} + function load_signals() { var active = 1 var xhttp_ps = new XMLHttpRequest(); @@ -245,8 +301,8 @@ function load_signals() { } s = s + "<h4>Side "+l[i]+": "+side.signal_name+"</h4>" s = s + '<table style="width: 100%"><thead><tr><td>Name<td>RC<td>LN</thead>'; - for (var i=0;i<routes.length;i++) { - var r = routes[i]; + for (var j=0;j<routes.length;j++) { + var r = routes[j]; var rstyle="route" var ln = "" var rc = "" @@ -266,15 +322,14 @@ function load_signals() { } var name = r.name if (r.endpoint) { - var e = r.endpoint.split(",") - name = '<a href="#" onclick="latLng2 = L.latLng(' + e[2] + ',' + e[0] + '); jump_to(latLng2); go_to_signal(\''+r.endpoint+'\','+r.endpoint_side+'); return false;">'+r.name+"</a>" - + name = '<a href="#" onclick="go_to_signal(\''+r.endpoint+'\','+r.endpoint_side+'); return false;">'+r.name+"</a>" } s = s+ '<tr class="'+rstyle+'"><td>'+name+"<td>"+rc+"<td>"+ln+"</tr>"; } - s = s + '</table><form><input type="text" name="route'+l[i]+'rc" placeholder="RC" style="width: 100%"></input><input type="text" name="route'+l[i]+'ln" placeholder="LN" style="width: 40%"></input><input type="submit" name="route'+l[i]+'submit" value="Next Signal"></input></form>' + var ps = feature.properties.pos + s = s + '</table><form onsubmit="form_handler(\''+ps+'\','+i+')" >RC: <input type="text" id="route'+ps+"S"+i+'rc" placeholder="RC" style="width: 80%"><br></input>LN: <input type="text" id="route'+ps+"S"+i+'ln" placeholder="LN" style="width: 35%"></input><input type="submit" id="route'+ps+"S"+i+'submit" value="Next Signal"></input></form>' } - layer.bindPopup('<h1>Routes here:</h1>' + s ); + layer.bindPopup('<h1>Routes here:</h1>' + s ).on("popupopen", station_popup_handler); }; pointToLayer = function (feature, latlng) { |