Support two colors of points rendered on the map.
This commit is contained in:
parent
e3eb7b30f0
commit
2bb92abf4b
6 changed files with 56 additions and 26 deletions
|
@ -42,7 +42,7 @@ function PrintRoutes($line){
|
|||
}
|
||||
echo '</tbody></table>';
|
||||
echo '</div><div id="map" class="tab-pane fade" role="tabpanel">';
|
||||
ShowMap(getPositionOfLine($line));
|
||||
ShowMap(getPositionOfLine($line,'go'),getPositionOfLine($line,'come'));
|
||||
echo '</div></div>';
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -30,7 +30,7 @@ if (isValidRoute($_GET['route'])){
|
|||
PrintStops($route,'go');
|
||||
PrintStops($route,'come');
|
||||
echo '</div><div id="map" class="tab-pane fade" role="tabpanel">';
|
||||
ShowMap(getPositionOfRoute($route['id']));
|
||||
ShowMap(getPositionOfRoute($route['id'],'go'),getPositionOfRoute($route['id'],'come'));
|
||||
echo '</div></div>';
|
||||
} else {
|
||||
echo '<span style="display:inline-block" class="alert alert-danger" role="alert">No such route. <a href="javascript:history.back()">Go back?</a></span>';
|
||||
|
|
|
@ -29,7 +29,7 @@ if (isValidStop($_GET["stop"])){
|
|||
echo '<div id="routes" class="tab-pane fade in active" role="tabpanel">';
|
||||
PrintRoutes($_GET["stop"]);
|
||||
echo '</div><div id="map" class="tab-pane fade" role="tabpanel">';
|
||||
ShowMap(array(array($stop['lat'],$stop['lon'])));
|
||||
ShowMap(array(array($stop['lat'],$stop['lon'])),[]);
|
||||
echo '</div></div>';
|
||||
} else {
|
||||
echo '<span style="display:inline-block" class="alert alert-danger" role="alert">No such stop. <a href="javascript:history.back()">Go back?</a></span>';
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
]
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,36 +2,64 @@
|
|||
<script src="openlayers/ol.js"></script>
|
||||
|
||||
<?php
|
||||
function ShowMap($coords){
|
||||
if(count($coords)>0){
|
||||
function ShowMap($coordsRed,$coordsGreen){
|
||||
if(count($coordsRed)>0 || count($coordsGreen)>0){
|
||||
?>
|
||||
<div id="mymap" style="width:300px;height:300px;overflow:hidden;"></div>
|
||||
<script>
|
||||
var style = new ol.style.Style({
|
||||
var pos = new ol.proj.fromLonLat([25.1329,35.3342]);
|
||||
var features = [];
|
||||
<?php
|
||||
if(count($coordsRed)>0){
|
||||
echo "var coordinatesRed = [";
|
||||
for ($i=0; $i<count($coordsRed)-1;$i++){
|
||||
$loc = $coordsRed[$i];
|
||||
echo '['. $loc[1] . ',' . $loc[0] . '],';
|
||||
}
|
||||
echo '['. $coordsRed[$i][1] . ',' . $coordsRed[$i][0] . ']];';
|
||||
?>
|
||||
var styleRed = new ol.style.Style({
|
||||
image: new ol.style.Circle({
|
||||
fill: new ol.style.Fill({color: '#FF0000'}),
|
||||
stroke: new ol.style.Stroke({color: '#000000'}),
|
||||
radius: 5
|
||||
})
|
||||
});
|
||||
<?php
|
||||
echo "var coordinates = [";
|
||||
for ($i=0; $i<count($coords)-1;$i++){
|
||||
$loc = $coords[$i];
|
||||
echo '['. $loc[1] . ',' . $loc[0] . '],';
|
||||
}
|
||||
echo '['. $coords[$i][1] . ',' . $coords[$i][0] . ']];';
|
||||
?>
|
||||
var pos = new ol.proj.fromLonLat([coordinates[0][0],coordinates[0][1]]);
|
||||
var features = [];
|
||||
for(var i=0; i<coordinates.length; i++){
|
||||
for(var i=0; i<coordinatesRed.length; i++){
|
||||
var feat = new ol.Feature({
|
||||
geometry: new ol.geom.Point(new ol.proj.fromLonLat([coordinates[i][0],coordinates[i][1]]))
|
||||
geometry: new ol.geom.Point(new ol.proj.fromLonLat([coordinatesRed[i][0],coordinatesRed[i][1]]))
|
||||
});
|
||||
feat.setStyle(style);
|
||||
feat.setStyle(styleRed);
|
||||
features.push(feat);
|
||||
}
|
||||
|
||||
<?php
|
||||
}
|
||||
if(count($coordsGreen)>0){
|
||||
echo "var coordinatesGreen = [";
|
||||
for ($i=0; $i<count($coordsGreen)-1;$i++){
|
||||
$loc = $coordsGreen[$i];
|
||||
echo '['. $loc[1] . ',' . $loc[0] . '],';
|
||||
}
|
||||
echo '['. $coordsGreen[$i][1] . ',' . $coordsGreen[$i][0] . ']];';
|
||||
?>
|
||||
var styleGreen = new ol.style.Style({
|
||||
image: new ol.style.Circle({
|
||||
fill: new ol.style.Fill({color: '#00FF00'}),
|
||||
stroke: new ol.style.Stroke({color: '#000000'}),
|
||||
radius: 5
|
||||
})
|
||||
});
|
||||
for(var i=0; i<coordinatesGreen.length; i++){
|
||||
var feat = new ol.Feature({
|
||||
geometry: new ol.geom.Point(new ol.proj.fromLonLat([coordinatesGreen[i][0],coordinatesGreen[i][1]]))
|
||||
});
|
||||
feat.setStyle(styleGreen);
|
||||
features.push(feat);
|
||||
}
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
var vectorSource = new ol.source.Vector({features:features});
|
||||
var vectorLayer = new ol.layer.Vector({
|
||||
source: vectorSource,
|
||||
|
@ -54,7 +82,7 @@ echo '['. $coords[$i][1] . ',' . $coords[$i][0] . ']];';
|
|||
<?php
|
||||
}else{
|
||||
?>
|
||||
<span style="display:inline-block" class="alert alert-danger" role="alert">No bus on its way yet. <a href="javascript:history.back()">Go back?</a></span>
|
||||
<span style="display:inline-block" class="alert alert-danger" role="alert">No information to display on the map yet (probably no bus is on its way). <a href="javascript:history.back()">Go back?</a></span>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
|
Reference in a new issue