From 2bb92abf4b31f635c7f25728aba22cf6fd175569 Mon Sep 17 00:00:00 2001 From: George Kaklamanos Date: Sat, 20 Feb 2016 22:02:18 +0200 Subject: [PATCH] Support two colors of points rendered on the map. --- ShowLine.php | 2 +- ShowRoute.php | 2 +- ShowStop.php | 2 +- data/buspositions.json | 6 ++-- modules/libdata.php | 8 +++--- modules/map.php | 62 ++++++++++++++++++++++++++++++------------ 6 files changed, 56 insertions(+), 26 deletions(-) diff --git a/ShowLine.php b/ShowLine.php index 85bb0b9..e8e5b22 100644 --- a/ShowLine.php +++ b/ShowLine.php @@ -42,7 +42,7 @@ function PrintRoutes($line){ } echo ''; echo '
'; - ShowMap(getPositionOfLine($line)); + ShowMap(getPositionOfLine($line,'go'),getPositionOfLine($line,'come')); echo '
'; } ?> diff --git a/ShowRoute.php b/ShowRoute.php index ba3d87b..a8bc7c9 100644 --- a/ShowRoute.php +++ b/ShowRoute.php @@ -30,7 +30,7 @@ if (isValidRoute($_GET['route'])){ PrintStops($route,'go'); PrintStops($route,'come'); echo '
'; - ShowMap(getPositionOfRoute($route['id'])); + ShowMap(getPositionOfRoute($route['id'],'go'),getPositionOfRoute($route['id'],'come')); echo '
'; } else { echo 'No such route. Go back?'; diff --git a/ShowStop.php b/ShowStop.php index 7c81894..ef440e5 100644 --- a/ShowStop.php +++ b/ShowStop.php @@ -29,7 +29,7 @@ if (isValidStop($_GET["stop"])){ echo '
'; PrintRoutes($_GET["stop"]); echo '
'; - ShowMap(array(array($stop['lat'],$stop['lon']))); + ShowMap(array(array($stop['lat'],$stop['lon'])),[]); echo '
'; } else { echo 'No such stop. Go back?'; diff --git a/data/buspositions.json b/data/buspositions.json index 7aa3bba..d403bcb 100644 --- a/data/buspositions.json +++ b/data/buspositions.json @@ -3,12 +3,14 @@ "id":"100", "routeid":"10", "lat":"35.3387", - "lon":"25.1317" + "lon":"25.1317", + "direction":"go" }, { "id":"150", "routeid":"20", "lat":"35.4387", - "lon":"25.1217" + "lon":"25.1217", + "direction":"come" } ] diff --git a/modules/libdata.php b/modules/libdata.php index bea36db..399759e 100644 --- a/modules/libdata.php +++ b/modules/libdata.php @@ -112,21 +112,21 @@ function getLines(){ return $lines; } -function getPositionOfRoute($rt){ +function getPositionOfRoute($rt,$direction){ global $buspositions; $locations = array(); foreach ($buspositions as $bus){ - if($bus["routeid"] == $rt){ + if($bus["routeid"] == $rt && $bus["direction"] == $direction){ array_push($locations,array($bus["lat"],$bus["lon"])); } } return $locations; } -function getPositionOfLine($line){ +function getPositionOfLine($line,$direction){ $locations = array(); foreach(getRoutesOfLine($line) as $route){ - foreach(getPositionOfRoute($route["id"]) as $pos){ + foreach(getPositionOfRoute($route["id"],$direction) as $pos){ array_push($locations,$pos); } } diff --git a/modules/map.php b/modules/map.php index 932d401..867e9a7 100644 --- a/modules/map.php +++ b/modules/map.php @@ -2,36 +2,64 @@ 0){ +function ShowMap($coordsRed,$coordsGreen){ + if(count($coordsRed)>0 || count($coordsGreen)>0){ ?>