ต้องการทำเส้นหลายเส้นในหน้าเดียวจากข้อมูลจากดาต้าเบสเป็นพิกัดต้นทางและปลายทาง
นำมาทำเป็นฟังชั่นเพื่อวนเรียกตอนดึงข้อมูลและพล้อตเส้น แต่ผลคือขึ้นมาแค่เส้นเดียวครับ
<script>
var road;
var map;
function plotred(road) {
var polyline = new longdo.Polyline(road, {
title: 'name',
detail: '-',
label: 'name',
lineWidth: 4,
lineColor: 'rgba(255, 0, 0, 0.8)'
});
map = new longdo.Map({
placeholder: document.getElementById('map')
});
map.Overlays.add(polyline); // add geometry object
}
function plotorange(road) {
var polyline = new longdo.Polyline(road, {
title: 'name',
detail: '-',
label: 'name',
lineWidth: 4,
lineColor: 'rgba(255, 102, 0, 0.8)'
});
map = new longdo.Map({
placeholder: document.getElementById('map')
});
map.Overlays.add(polyline); // add geometry object
}
function plotyellow(road) {
var polyline = new longdo.Polyline(road, {
title: 'okok',
detail: '-',
label: 'okok',
lineWidth: 4,
lineColor: 'rgba(255, 255, 0, 1)'
});
map = new longdo.Map({
placeholder: document.getElementById('map')
});
map.Overlays.add(polyline); // add geometry object
}
</script>
<body>
<div id="map"></div>
<div id="demo"></div>
<?php
$sql_road = mysqli_query($conn, "SELECT DISTINCT road_test.name as roadname FROM road_test");
$numroad = 0;
while ($row_road = mysqli_fetch_array($sql_road)) {
$numroad++;
$road = $row_road['roadname'];
$numpoint = 0;
$myJSON = null;
$road_point = array();
//$numroad = $row_road['numroad'];
$sql_point = mysqli_query($conn, "SELECT lon,lat,road_test.name FROM road_test where road_test.name = '$road'");
while ($row_point = mysqli_fetch_array($sql_point)) {
array_push($road_point,array('lon' => $row_point['lon'], 'lat' => $row_point['lat']));
$numpoint++;
}
$myJSON = json_encode($road_point);
unset($road_point);
//echo $myJSON . '<br>';
//echo 'numpoint = ' . $numpoint . $road . '<br>';
/*
echo '<script type="text/javascript">' .
'plotyellow(' . $myJSON . ');' .
'</script>';*/
if ($numroad % 3 == 0) {
echo '<script type="text/javascript">' .
'plotred(' . $myJSON . ');' .
'</script>';
$myJSON = null;
} elseif ($numroad % 3 == 1) {
echo '<script type="text/javascript">' .
'plotorange(' . $myJSON . ');' .
'</script>';
$myJSON = null;
} else {
echo '<script type="text/javascript">' .
'plotyellow(' . $myJSON . ');' .
'</script>';
$myJSON = null;
}
}
//echo $myJSON . '<br>';
//echo $numroad . '<br>';
?>
*-*